/** * Determine if we should try to make a default value widget. * * @param \Drupal\Core\Field\FieldDefinitionInterface $definition * * @return bool */ private function isDefaultCompatible(FieldDefinitionInterface $definition) { $class = $definition->getClass(); $type = $definition->getType(); $compatible_types = [ 'boolean', 'list_float', 'list_integer', 'list_string', ]; if (in_array($type, $compatible_types)) { return TRUE; } if ('entity_reference' == $type) { // We should only store a default value in the special case // where the target is a config entity. // Otherwise we would have config that pointed to content. // The site-builder could still do this in manage fields for the Update type // but should not en-courage this practice. $target_type = $definition->getFieldStorageDefinition()->getSetting('target_type'); $definition = $this->entityTypeManager->getDefinition($target_type); if ($this->definitionClassImplementsInterface($definition, ['Drupal\Core\Config\Entity\ConfigEntityInterface'])) { return TRUE; } } return FALSE; }