When I install "Domain Content" module through administration UI, before I confirm to install "Domain, Domain Access", the warning occurs:

Warning: Use of undefined constant DOMAIN_ACCESS_FIELD - assumed 'DOMAIN_ACCESS_FIELD' (this will throw an Error in a future version of PHP) in domain_content_requirements() (line 22 of modules/contrib/domain/domain_content/domain_content.install).
domain_content_requirements('install')
call_user_func_array('domain_content_requirements', Array) (Line: 392)
Drupal\Core\Extension\ModuleHandler->invoke('domain_content', 'requirements', Array) (Line: 1035)
drupal_check_module('domain_content') (Line: 419)
Drupal\system\Form\ModulesListForm->buildModuleList(Object) (Line: 437)
Drupal\system\Form\ModulesListForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('system_modules', Array, Object) (Line: 318)
Drupal\Core\Form\FormBuilder->buildForm('system_modules', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Domain content cannot be enabled until Domain access has installed its required fields.
Notice: Undefined index: domain_content in Drupal\system\Form\ModulesListConfirmForm->buildMessageList() (line 148 of core/modules/system/src/Form/ModulesListConfirmForm.php).
Drupal\system\Form\ModulesListConfirmForm->buildMessageList() (Line: 124)
Drupal\system\Form\ModulesListConfirmForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 518)
Drupal\Core\Form\FormBuilder->retrieveForm('system_modules_confirm_form', Object) (Line: 275)
Drupal\Core\Form\FormBuilder->buildForm('system_modules_confirm_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

And after them install complete, another notice occur:

Notice: Undefined index: domain_content in Drupal\system\Form\ModulesListConfirmForm->buildMessageList() (line 148 of core/modules/system/src/Form/ModulesListConfirmForm.php).
Drupal\system\Form\ModulesListConfirmForm->buildMessageList() (Line: 124)
Drupal\system\Form\ModulesListConfirmForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 518)
Drupal\Core\Form\FormBuilder->retrieveForm('system_modules_confirm_form', Object) (Line: 275)
Drupal\Core\Form\FormBuilder->buildForm('system_modules_confirm_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
The content access permissions need to be rebuilt. Rebuild permissions.

And then, I found "Domain, Domain Access" had install success, but "Domain Content" Fail.
So, I reinstall "Domain Content", it works!!! install success.

but, it must be something went wrong here.

Evns:
Database type and version : MySQL 5.7
PHP version : 7.2.8

I install this base on a pure "droopler" distribution instance which version is v8.1.4

Drupal Version
8.6.17

Last Cron Run
Last run 1 day 5 hours ago
(more information)
Run cron

Web Server
Apache/2.4.33 (Unix)

PHP
Version
7.2.8 (more information)
Memory limit
512M

Database
Version
5.7.24
System
MySQL

Comments

canvaskent created an issue. See original summary.

司南’s picture

Issue summary: View changes
司南’s picture

Issue summary: View changes
司南’s picture

Title: Warning: Use of undefined constant DOMAIN_ACCESS_FIELD » Domain Content module install Fail. Warning: Use of undefined constant DOMAIN_ACCESS_FIELD
司南’s picture

Issue summary: View changes
司南’s picture

I found why "Warning: Use of undefined constant DOMAIN_ACCESS_FIELD" occurs.

These two const should not be defined in "domain_access.module", cause "domain_content_requirements()" can not find it when "domain_access" module has not been install.

/**
 * The name of the node access control field.
 */
const DOMAIN_ACCESS_FIELD = 'field_domain_access';

/**
 * The name of the all affiliates field.
 */
const DOMAIN_ACCESS_ALL_FIELD = 'field_domain_all_affiliates';
agentrickard’s picture

Except that Domain Access is declared as a dependency for the installation of Domain Content, which makes this a core installation error.

Any ideas as for where to put those constants instead?

We could also force-load the Domain Access module file...

agentrickard’s picture

We could move these constants to the DomainAccessManagerInterface.

davps’s picture

Version: 8.x-1.0-alpha16 » 8.x-1.x-dev
Assigned: 司南 » Unassigned
Status: Active » Needs review
StatusFileSize
new1.43 KB

We could move these constants to the DomainAccessManagerInterface.

@agentrickard, it seems that need to check requirements when the dependency is already installed, otherwise there is no sense in checking requirements that will never be met when the dependent module is disabled.

Status: Needs review » Needs work

The last submitted patch, 9: installation_fail-3078503-9.patch, failed testing. View results

andypost’s picture

@agentrickard I bet it because no .module file loaded in install stage

But you point about this constant is interesting! There's some mess with this constant in other domain contrib.
I used to introduce other variable in domain_entity module for 2 reasons:
- get rid of "field_" prefix because this names supposed to be used for fields added with Field UI
- to prevent dependency on domain_access (node) module when I need to "domainize" other entities but not nodes

Probably better to move this discussion to separate issue because domain module supposed to be applicable to nodes only

agentrickard’s picture

Bumping. We should move these to an interface so they can be loaded with a use statement.

andypost’s picture

Interesting idea with interface, module installer probably adds installable's namespace to classloader before calling hook_install()

agentrickard’s picture

I would think so. That's why most core constants have moved to interfaces.

agentrickard’s picture

Status: Needs work » Needs review
StatusFileSize
new63.52 KB
andypost’s picture

It looks great except removal of constants (I bet you made it intentionally to make sure nothing will fail)

The example https://git.drupalcode.org/project/drupal/-/blob/8.9.x/core/modules/comm...
Here we are keeping old constant value instead of assigning interface constant to prevent autoloader useless run when loading module file

+++ b/domain_access/domain_access.module
@@ -12,16 +12,7 @@ use Drupal\Core\Access\AccessResult;
-const DOMAIN_ACCESS_FIELD = 'field_domain_access';
...
-const DOMAIN_ACCESS_ALL_FIELD = 'field_domain_all_affiliates';

I bet this constants should stay but marked as deprecated

agentrickard’s picture

I had forgotten about @deprecated. Thanks.

agentrickard’s picture

StatusFileSize
new101.61 KB

New patch, which fixes a Domain Source error found during testing.

Status: Needs review » Needs work

The last submitted patch, 18: 3078503-domain-constants_18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

agentrickard’s picture

Status: Needs work » Needs review
StatusFileSize
new102.52 KB

And a new patch.

agentrickard’s picture

Issue tags: -DOMAIN_ACCESS_FIELD, -domain_content
agentrickard’s picture

StatusFileSize
new109.64 KB

And a patch which makes two changes:

- Restores the old constants and marks them as @deprecated.
- Moves the DOMAIN_MATCH_* constants to DomainNegotiatorInterface.

Status: Needs review » Needs work

The last submitted patch, 22: 3078503-domain-constants_22.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

agentrickard’s picture

Status: Needs work » Needs review
StatusFileSize
new110.4 KB

For compatibility, the DomainNegotiatorInterface constants must be renamed.

agentrickard’s picture

@andypost -- I think this is ready for final review.

andypost’s picture

This looks mostly ready, just not sure the field name could be a part of domain interface as it used only for access controller

+++ b/domain/src/DomainAccessControlHandler.php
@@ -118,7 +119,7 @@ class DomainAccessControlHandler extends EntityAccessControlHandler implements E
   public function isDomainAdmin(EntityInterface $entity, AccountInterface $account) {
     $user = $this->userStorage->load($account->id());
-    $user_domains = $this->domainElementManager->getFieldValues($user, DOMAIN_ADMIN_FIELD);
+    $user_domains = $this->domainElementManager->getFieldValues($user, DomainInterface::DOMAIN_ADMIN_FIELD);

+++ b/domain/src/DomainInterface.php
@@ -3,12 +3,18 @@
+   * The name of the admin access control field.
...
+  const DOMAIN_ADMIN_FIELD = 'field_domain_admin';

That's what I find it strage - this field is added via config in main (domain) module, but also defined in dependent module - "domain_access" which is hard to override or replace

agentrickard’s picture

These are different fields, DOMAIN_ADMIN_FIELD and DOMAIN_ACCESS_FIELD.

The ADMIN field, defined by Domain module, is for users and the ACCESS field, defined by Domain Access, is for nodes.

There are non-node access reasons when the ADMIN field on the user is in the main module. This is largely present for people who want to divide up admin tasks or logins.

Drupal\domain_config_ui\Form\SwitchForm::getDomainOptions() looks at the Domain admin field and uses Drupal\domain\DomainAccessControlHandler::checkAccess() to determine which domains can be used by the current user.

Something similar happens in domain_alias.routing.yml, which refers to the same method

domain_alias.admin:
  path: '/admin/config/domain/alias/{domain}'
  defaults:
    _controller: '\Drupal\domain_alias\Controller\DomainAliasController::listing'
    _title: 'Domain aliases'
    _title_context: 'With modules'
  requirements:
    _entity_access: domain.update
    _permission: 'view domain aliases'

This was a deliberate change from earlier versions, since we had people who wanted to extend or separate admin actions based on domain.

  • agentrickard committed 5754a6d on 8.x-1.x
    Issue #3078503 by agentrickard, davps, canvaskent, andypost: Domain...
agentrickard’s picture

Status: Needs review » Fixed
andypost’s picture

Thank you! It works great for me.

@agentrickard please add PHP 8 test run on commit

agentrickard’s picture

EDIT: Looks like you can do that, just not for issues.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

musa.thomas’s picture

Still got this issue with the last dev version (Drupal 9.3)

breezeweb’s picture

I'm just confirming that this is still occurring on a D9 fresh install (Drupal 9.3) as @Musa.thomas said.

brad.bulger’s picture

in 1.0-beta6 I get

Error: Class 'Drupal\\domain_access\\DomainAccessManagerInterface' not found in /home/www/domainsite/web/modules/contrib/domain/domain_content/domain_content.install on line 24 #0 [internal function]: domain_content_requirements()

is that this same issue?

UPDATE: sorry I missed that this was closed, opened #3272765: domain_content install fatal error using DomainAccessManagerInterface

flyke’s picture

I just updated to the latste dev (from dev-1.x 818fd0f to dev-1.x 8818fae) and now I have this error too on my project.
For example when editing a node.
The error was not there before updating the Domain module to the latest dev.

I do not use the domain_content module.
My exact message:
Warning: Use of undefined constant DOMAIN_ACCESS_FIELD - assumed 'DOMAIN_ACCESS_FIELD' (this will throw an Error in a future version of PHP) in /app/web/modules/contrib/domain/domain_access/domain_access.module on line 760

Nevermind my comment, in my case this came from applying patch from here:
https://www.drupal.org/project/domain/issues/2909853

I updated that patch in #33 there and now this error went away.