Hi. I am getting the following error when trying to edit a field. Any ideas how to fix this?

Structure -> Content Types -> Manage Fields -> Edit

Recently upgraded to Drupal 8.2.7 and Domain alpha8 (see attached for all installed modules and versions).

Warning: call_user_func() expects parameter 1 to be a valid callback, class 'Drupal\domain_access\DomainAccessManager' does not have a method 'getDefaultAllValue' in Drupal\Core\Field\FieldConfigBase->getDefaultValue() (line 388 of core\lib\Drupal\Core\Field\FieldConfigBase.php).
Drupal\Core\Field\FieldConfigBase->getDefaultValue(Object) (Line: 180)
Drupal\Core\Field\FieldItemList->applyDefaultValue() (Line: 112)
Drupal\Core\Entity\ContentEntityStorageBase->initFieldValues(Object, Array) (Line: 88)
Drupal\Core\Entity\ContentEntityStorageBase->doCreate(Array) (Line: 184)
Drupal\Core\Entity\EntityStorageBase->create(Array) (Line: 299)
_field_create_entity_from_ids(Object) (Line: 80)
Drupal\field_ui\Form\FieldConfigEditForm->form(Array, Object) (Line: 115)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('field_config_edit_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
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}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
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: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 652)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jtkunley created an issue. See original summary.

Znak’s picture

Status: Active » Needs review
FileSize
778 bytes

Maybe, this patch will fix your problems. Please, check up.

agentrickard’s picture

Category: Bug report » Support request
Status: Needs review » Active

We deliberately removed the default value callback for the "All" field. The field handler definitions have to be changed and the getDefaultAllValue() method has been removed.

Make sure you run domain_alpha_update_8004(), which you might have to manually force if that module was not enabled before you updated.

This change was made to allow the field value to be configurable on a per-node type basis.

See https://github.com/agentrickard/domain/pull/335.

jtkunley’s picture

see #5

jtkunley’s picture

Applied #2 patch and changed method name to 8005 to force the update. Update went through. Now the problem appears when adding a new node. Any ideas?

Issue

Warning: call_user_func() expects parameter 1 to be a valid callback, class 'Drupal\domain_access\DomainAccessManager' does not have a method 'getDefaultAllValue' in Drupal\Core\Field\FieldConfigBase->getDefaultValue() (line 388 of core\lib\Drupal\Core\Field\FieldConfigBase.php).

Update DB

> drush updb
The following updates are pending:
domain_alpha module :
  8005 -   Make all affiliates default value configurable.
Do you wish to run all pending updates? (y/n): y
Performing domain_alpha_update_8005                                                                                                                                [ok]
Cache rebuild complete.                                                                                                                                            [ok]
Finished performing updates.

---------------------------

New Code

/**
 * Make all affiliates default value configurable.
 */
function domain_alpha_update_8005() {
  $config = \Drupal::configFactory();
  $field_name = '.' . DOMAIN_ACCESS_ALL_FIELD;
  // Iterate over all node & user fields.
  foreach (['node', 'user'] as $type) {
    foreach ($config->listAll('field.field.' . $type . '.') as $field_id) {
      if (substr($field_id, -strlen($field_name)) === $field_name) {
        $field = $config->getEditable($field_id);
        if ($field->get('default_value_callback') === 'Drupal\domain_access\DomainAccessManager::getDefaultValue') {
          $field
            ->clear('default_value_callback')
            ->save(TRUE);
        }
      }
    }
  }
}
agentrickard’s picture

Well, that error would mean that the update didn't work, though I can't really replicate that in DEV.

You could remove the IF condition if ($field->get('default_value_callback') === 'Drupal\domain_access\DomainAccessManager::getDefaultValue') { and run it again.

Or use Config Synchronization to export the field, manually edit the YML and reload it.

The final YML should look like so. There will be one for each node type and for users:

uuid: eaab4f38-0a83-47bd-a1b7-26b046e4fd5f
langcode: en
status: true
dependencies:
  config:
    - field.storage.node.field_domain_all_affiliates
    - node.type.article
id: node.article.field_domain_all_affiliates
field_name: field_domain_all_affiliates
entity_type: node
bundle: article
label: 'Send to all affiliates'
description: 'Make this content available on all domains.'
required: false
translatable: true
default_value: {  }
default_value_callback: ''
settings:
  on_label: 'On'
  off_label: 'Off'
field_type: boolean
jtkunley’s picture

Okay, I got it now.

My config for all content types looked like this before update, so 'if' statement never executed (as you've rightly guessed!)

uuid: f6b83cb2-0a9f-4101-a9db-557fc4d33610
langcode: en
status: true
dependencies:
  config:
    - field.storage.node.field_domain_all_affiliates
    - node.type.fact
id: node.fact.field_domain_all_affiliates
field_name: field_domain_all_affiliates
entity_type: node
bundle: fact
label: 'Send to all affiliates'
description: 'Make this content available on all domains.'
required: false
translatable: true
default_value: {  }
default_value_callback: 'Drupal\domain_access\DomainAccessManager::getDefaultAllValue'
settings:
  on_label: 'On'
  off_label: 'Off'
field_type: boolean

So I kept the if statement and just reverted to original version (check for getDefaultAllValue). After drush updb everything looks good now. Thanks Ken!

function domain_alpha_update_8006() {
  $config = \Drupal::configFactory();
  $field_name = '.' . DOMAIN_ACCESS_ALL_FIELD;
  // Iterate over all node & user fields.
  foreach (['node', 'user'] as $type) {
    foreach ($config->listAll('field.field.' . $type . '.') as $field_id) {
      if (substr($field_id, -strlen($field_name)) === $field_name) {
        $field = $config->getEditable($field_id);
        if ($field->get('default_value_callback') === 'Drupal\domain_access\DomainAccessManager::getDefaultAllValue') {
          $field
            ->clear('default_value_callback')
            ->save(TRUE);
        }
      }
    }
  }
}
jtkunley’s picture

Status: Active » Fixed
jtkunley’s picture

Issue summary: View changes

Status: Fixed » Closed (fixed)

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

agentrickard’s picture

Londova’s picture

It seems this error still exists after updating to "alpha10" version.

tanc’s picture

An old issue but I just wanted to note I came across this problem while doing a Drupal 9 upgrade on someone's site. All hook updates had been run, but looking at the exported config I could see that default_value_callback: 'Drupal\domain_access\DomainAccessManager::getDefaultAllValue' still existed.

I did a find and replace on the config/sync dir with the following:

From:
default_value_callback: 'Drupal\domain_access\DomainAccessManager::getDefaultAllValue'
To:
default_value_callback: ''

Then imported the config and confirmed that it fixed the error.