summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-11-06 12:28:18 +0000
committerNathaniel Catchpole2017-11-06 12:28:18 +0000
commit3cadcd5df43d7bd88c7c99e19b960928b8d119a5 (patch)
treec0453feed74aa1a24e6c1db77b8bdf390f6767e1
parent2c2e85c348cc1d71cb82b37d35ae977705fac52c (diff)
Issue #2903161 by voleger, tacituseu, xjm, benjifisher, andypost, Berdir: Fix incorrect FieldFormatter id for weight field in base field definition in display options
-rw-r--r--core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php137
-rw-r--r--core/modules/menu_link_content/src/Entity/MenuLinkContent.php2
2 files changed, 118 insertions, 21 deletions
diff --git a/core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php b/core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php
index 85d6b0b..afd468a 100644
--- a/core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php
+++ b/core/modules/field/tests/src/Kernel/FieldDefinitionIntegrityTest.php
@@ -2,8 +2,13 @@
namespace Drupal\Tests\field\Kernel;
+use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
+use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Component\Utility\NestedArray;
+use Drupal\Core\Entity\ContentEntityTypeInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Extension\Extension;
+use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\KernelTests\KernelTestBase;
/**
@@ -24,26 +29,11 @@ class FieldDefinitionIntegrityTest extends KernelTestBase {
public function testFieldPluginDefinitionIntegrity() {
// Enable all core modules that provide field plugins, and their
// dependencies.
- $modules = system_rebuild_module_data();
- $modules = array_filter($modules, function (Extension $module) {
- // Filter contrib, hidden, already enabled modules and modules in the
- // Testing package.
- if ($module->origin === 'core'
- && empty($module->info['hidden'])
- && $module->status == FALSE
- && $module->info['package'] !== 'Testing'
- && is_readable($module->getPath() . '/src/Plugin/Field')) {
- return TRUE;
- }
- return FALSE;
- });
- // Gather the dependencies of the modules.
- $dependencies = NestedArray::mergeDeepArray(array_map(function (Extension $module) {
- return array_keys($module->requires);
- }, $modules));
- $modules = array_unique(NestedArray::mergeDeep(array_keys($modules), $dependencies));
-
- $this->enableModules($modules);
+ $this->enableModules(
+ $this->modulesWithSubdirectory(
+ 'src' . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . 'Field'
+ )
+ );
/** @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface $field_type_manager */
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
@@ -115,7 +105,114 @@ class FieldDefinitionIntegrityTest extends KernelTestBase {
else {
$this->pass(sprintf('Field formatter %s integrates with existing field types.', $definition['id']));
}
+
}
}
+ /**
+ * Tests to load field plugin definitions used in core's existing entities.
+ */
+ public function testFieldPluginDefinitionAvailability() {
+ $this->enableModules(
+ $this->modulesWithSubdirectory('src' . DIRECTORY_SEPARATOR . 'Entity')
+ );
+
+ /** @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface $field_type_manager */
+ $field_formatter_manager = $this->container->get('plugin.manager.field.formatter');
+
+ /** @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface $field_type_manager */
+ $field_widget_manager = $this->container->get('plugin.manager.field.widget');
+
+ /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
+ $entity_field_manager = $this->container->get('entity_field.manager');
+
+ /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
+ $entity_type_manager = $this->container->get('entity_type.manager');
+
+ /** @var \Drupal\Core\Field\BaseFieldDefinition[][] $field_definitions */
+ $field_definitions = [];
+
+ /** @var \Drupal\Core\Entity\EntityTypeInterface[] $content_entity_types */
+ $content_entity_types = array_filter($entity_type_manager->getDefinitions(), function (EntityTypeInterface $entity_type) {
+ return $entity_type instanceof ContentEntityTypeInterface;
+ });
+
+ foreach ($content_entity_types as $entity_type_id => $entity_type_definition) {
+ $field_definitions[$entity_type_id] = $entity_field_manager->getBaseFieldDefinitions($entity_type_id);
+ }
+
+ foreach ($field_definitions as $entity_type_id => $definitions) {
+ foreach ($definitions as $field_id => $field_definition) {
+ $this->checkDisplayOption($entity_type_id, $field_id, $field_definition, $field_formatter_manager, 'view');
+ $this->checkDisplayOption($entity_type_id, $field_id, $field_definition, $field_widget_manager, 'form');
+ }
+ }
+ }
+
+ /**
+ * Helper method that tries to load plugin definitions.
+ *
+ * @param string $entity_type_id
+ * Id of entity type. Required by message.
+ * @param string $field_id
+ * Id of field. Required by message.
+ * @param \Drupal\Core\Field\BaseFieldDefinition $field_definition
+ * Field definition that provide display options.
+ * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $plugin_manager
+ * Plugin manager that will try to provide plugin definition.
+ * @param string $display_context
+ * Defines which display options should be loaded.
+ */
+ protected function checkDisplayOption($entity_type_id, $field_id, BaseFieldDefinition $field_definition, DiscoveryInterface $plugin_manager, $display_context) {
+ $display_options = $field_definition->getDisplayOptions($display_context);
+ if (!empty($display_options['type'])) {
+ try {
+ $plugin_manager->getDefinition($display_options['type']);
+ }
+ catch (PluginNotFoundException $e) {
+ $this->fail(sprintf(
+ 'PluginNotFoundException here for "%s" field %s display options of "%s" entity type. Original message: %s',
+ $field_id,
+ $display_context,
+ $entity_type_id,
+ $e->getMessage()
+ ));
+ }
+ }
+ }
+
+ /**
+ * Find modules with a specified subdirectory.
+ *
+ * @param string $subdirectory
+ * The required path, relative to the module directory.
+ *
+ * @return string[]
+ * A list of module names satisfying these criteria:
+ * - provided by core
+ * - not hidden
+ * - not already enabled
+ * - not in the Testing package
+ * - containing the required $subdirectory
+ * and all modules required by any of these modules.
+ */
+ protected function modulesWithSubdirectory($subdirectory) {
+ $modules = system_rebuild_module_data();
+ $modules = array_filter($modules, function (Extension $module) use ($subdirectory) {
+ // Filter contrib, hidden, already enabled modules and modules in the
+ // Testing package.
+ return ($module->origin === 'core'
+ && empty($module->info['hidden'])
+ && $module->status == FALSE
+ && $module->info['package'] !== 'Testing'
+ && is_readable($module->getPath() . DIRECTORY_SEPARATOR . $subdirectory));
+ });
+ // Gather the dependencies of the modules.
+ $dependencies = NestedArray::mergeDeepArray(array_map(function (Extension $module) {
+ return array_keys($module->requires);
+ }, $modules));
+
+ return array_unique(NestedArray::mergeDeep(array_keys($modules), $dependencies));
+ }
+
}
diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
index d53ba49..460c0df 100644
--- a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
+++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
@@ -316,7 +316,7 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf
->setDefaultValue(0)
->setDisplayOptions('view', [
'label' => 'hidden',
- 'type' => 'integer',
+ 'type' => 'number_integer',
'weight' => 0,
])
->setDisplayOptions('form', [