diff --git a/core/lib/Drupal/Core/Field/FieldDefinition.php b/core/lib/Drupal/Core/Field/FieldDefinition.php index 8d36fba97b62..cfeccf850c7c 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinition.php +++ b/core/lib/Drupal/Core/Field/FieldDefinition.php @@ -477,8 +477,12 @@ class FieldDefinition extends ListDataDefinition implements FieldDefinitionInter $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->getType()); $class = $definition['class']; $schema = $class::schema($this); - // Fill in default values for optional entries. - $schema += array('indexes' => array(), 'foreign keys' => array()); + // Fill in default values. + $schema += array( + 'columns' => array(), + 'indexes' => array(), + 'foreign keys' => array(), + ); // Check that the schema does not include forbidden column names. if (array_intersect(array_keys($schema['columns']), static::getReservedColumns())) { diff --git a/core/lib/Drupal/Core/Field/FieldTypePluginManager.php b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php index 07aaceb41801..a4ccd78cefb0 100644 --- a/core/lib/Drupal/Core/Field/FieldTypePluginManager.php +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php @@ -10,7 +10,7 @@ namespace Drupal\Core\Field; use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Language\LanguageManager; +use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Plugin\DefaultPluginManager; /** @@ -26,12 +26,12 @@ class FieldTypePluginManager extends DefaultPluginManager implements FieldTypePl * keyed by the corresponding namespace to look for plugin implementations. * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * Cache backend instance to use. - * @param \Drupal\Core\Language\LanguageManager $language_manager + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. * @param \Drupal\Core\Extension\ModuleHandlerInterface * The module handler. */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler) { parent::__construct('Plugin/Field/FieldType', $namespaces, $module_handler, 'Drupal\Core\Field\Annotation\FieldType'); $this->alterInfo('field_info'); $this->setCacheBackend($cache_backend, $language_manager, 'field_types_plugins'); diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php index f9eb453220bb..130cb62600bb 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -75,7 +75,7 @@ class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery { $reader = parent::getAnnotationReader(); // Add the Core annotation classes like @Translation. - $reader->addNamespace('Drupal\Core\Annotation', array(DRUPAL_ROOT . '/core/lib/Drupal/Core/Annotation')); + $reader->addNamespace('Drupal\Core\Annotation', array(dirname(dirname(__DIR__)) . '/Annotation')); $this->annotationReader = $reader; } return $this->annotationReader; diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php index 545bc1bf2877..8466bf242dee 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php @@ -17,9 +17,12 @@ class EntityReferenceAdminTest extends WebTestBase { /** * Modules to enable. * + * Enable path module to ensure that the selection handler does not fail for + * entities with a path field. + * * @var array */ - public static $modules = array('node', 'field_ui', 'entity_reference'); + public static $modules = array('node', 'field_ui', 'entity_reference', 'path'); /** * {@inheritdoc} diff --git a/core/modules/path/tests/src/Field/PathFieldDefinitionTest.php b/core/modules/path/tests/src/Field/PathFieldDefinitionTest.php new file mode 100644 index 000000000000..fb99b8299790 --- /dev/null +++ b/core/modules/path/tests/src/Field/PathFieldDefinitionTest.php @@ -0,0 +1,58 @@ + 'Path field definitions', + 'description' => 'Tests that field definitions for path fields work correctly.', + 'group' => 'Path', + ); + } + + /** + * {@inheritdoc} + */ + protected function getPluginId() { + return 'path'; + } + + /** + * {@inheritdoc} + */ + protected function getNamespacePath() { + return dirname(dirname(dirname(__DIR__))) . '/lib/Drupal/path'; + } + + /** + * Tests FieldDefinition::getColumns(). + * + * @covers \Drupal\Core\Field\FieldDefinition::getColumns + * @covers \Drupal\path\Plugin\Field\FieldType\PathItem::getSchema + */ + public function testGetColumns() { + $this->assertSame(array(), $this->definition->getColumns()); + } + +} diff --git a/core/tests/Drupal/Tests/Core/Field/FieldDefinitionTestBase.php b/core/tests/Drupal/Tests/Core/Field/FieldDefinitionTestBase.php new file mode 100644 index 000000000000..49a39229ceb0 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Field/FieldDefinitionTestBase.php @@ -0,0 +1,86 @@ +getNamespacePath(); + // Suppport both PSR-0 and PSR-4 directory layouts. + $module_name = basename($namespace_path); + if ($module_name == 'src') { + $module_name = basename($module_name); + } + $namespaces = new \ArrayObject(array( + 'Drupal\\' . $module_name => $namespace_path, + )); + + $language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface'); + $language_manager->expects($this->once()) + ->method('getCurrentLanguage') + ->will($this->returnValue(new Language(array('id' => 'en')))); + $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); + $module_handler->expects($this->once()) + ->method('moduleExists') + ->with($module_name) + ->will($this->returnValue(TRUE)); + $plugin_manager = new FieldTypePluginManager( + $namespaces, + $this->getMock('Drupal\Core\Cache\CacheBackendInterface'), + $language_manager, + $module_handler + ); + + $container = new ContainerBuilder(); + $container->set('plugin.manager.field.field_type', $plugin_manager); + // The 'string_translation' service is used by the @Translation annotation. + $container->set('string_translation', $this->getStringTranslationStub()); + \Drupal::setContainer($container); + + $this->definition = FieldDefinition::create($this->getPluginId()); + } + + /** + * Returns the plugin ID of the tested field type. + * + * @return string + * The plugin ID. + */ + abstract protected function getPluginId(); + + /** + * Returns the path to the module's classes. + * + * Depending on whether the module follows the PSR-0 or PSR-4 directory layout + * this should be either /path/to/module/lib/Drupal/mymodule or + * /path/to/module/src. + * + * @return string + * The path to the module's classes. + */ + abstract protected function getNamespacePath(); + +}