diff --git a/core/lib/Drupal/Core/Entity/Annotation/FieldType.php b/core/lib/Drupal/Core/Entity/Annotation/FieldType.php index 1de71b5..e73ae01 100644 --- a/core/lib/Drupal/Core/Entity/Annotation/FieldType.php +++ b/core/lib/Drupal/Core/Entity/Annotation/FieldType.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Entity\Annotation; use Drupal\Component\Annotation\Plugin; +use Drupal\Core\TypedData\Annotation\DataType; /** * Defines a FieldType annotation object. @@ -17,7 +18,7 @@ * * @Annotation */ -class FieldType extends Plugin { +class FieldType extends DataType { /** * The plugin ID. @@ -103,8 +104,6 @@ class FieldType extends Plugin { /** * A boolean stating that fields of this type are configurable. * - * @todo: Make field module respect this. - * * @var boolean */ public $configurable = TRUE; @@ -112,10 +111,16 @@ class FieldType extends Plugin { /** * A boolean stating that fields of this type cannot be created through the UI. * - * If TRUE, fields of this type can only be created programmatically. + * If TRUE or the field type is not configurable, fields of this type can only + * be created programmatically. * * @var boolean */ public $no_ui = FALSE; + /** + * {@inheritdoc} + */ + public $list_class = '\Drupal\field\Plugin\Type\FieldType\ConfigField'; + } diff --git a/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php index 5269769..d738b60 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php @@ -25,7 +25,6 @@ class FieldTypePluginManager extends DefaultPluginManager { protected $defaults = array( 'settings' => array(), 'instance_settings' => array(), - 'list_class' => '\Drupal\field\Plugin\Type\FieldType\ConfigField', ); /** @@ -52,6 +51,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac } /** +<<<<<<< HEAD * Returns the default field-level settings for a field type. * * @param string $type @@ -81,4 +81,27 @@ public function getDefaultInstanceSettings($type) { return isset($info['instance_settings']) ? $info['instance_settings'] : array(); } + /** + * Gets the definition of all field types. + * + * @param Boolean $configurable + * Configurable flag to indicate whether return configurable field types. + * + * @return array + * An array of field type definitions. + */ + public function getDefinitions($configurable = NULL) { + $definitions = $this->getCachedDefinitions(); + if (!isset($definitions)) { + $definitions = $this->findDefinitions(); + $this->setCachedDefinitions($definitions); + } + if ($configurable) { + return array_filter($this->definitions, function ($defintion) { + return $defintion['configurable']; + }); + } + return $definitions; + } + } diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/LanguageItem.php b/core/lib/Drupal/Core/Entity/Plugin/field/field_type/LanguageItem.php similarity index 90% rename from core/lib/Drupal/Core/Entity/Plugin/DataType/LanguageItem.php rename to core/lib/Drupal/Core/Entity/Plugin/field/field_type/LanguageItem.php index 68526f5..283f41d 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/LanguageItem.php +++ b/core/lib/Drupal/Core/Entity/Plugin/field/field_type/LanguageItem.php @@ -2,23 +2,24 @@ /** * @file - * Contains \Drupal\Core\Entity\Plugin\DataType\LanguageItem. + * Contains \Drupal\Core\Entity\Plugin\field\field_type\LanguageItem. */ -namespace Drupal\Core\Entity\Plugin\DataType; +namespace Drupal\Core\Entity\Plugin\field\field_type; -use Drupal\Core\TypedData\Annotation\DataType; +use Drupal\Core\Entity\Annotation\FieldType; use Drupal\Core\Annotation\Translation; use Drupal\Core\Entity\Field\FieldItemBase; use Drupal\Core\Language\Language; /** - * Defines the 'language_field' entity field item. + * Defines the 'field_item:language' entity field item. * - * @DataType( - * id = "language_field", - * label = @Translation("Language field item"), + * @FieldType( + * id = "language", + * label = @Translation("Language"), * description = @Translation("An entity field referencing a language."), + * configurable = false, * list_class = "\Drupal\Core\Entity\Field\Field", * constraints = { * "ComplexData" = { diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php index 46b3894..a01429a 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php @@ -265,7 +265,7 @@ public static function baseFieldDefinitions($entity_type) { $fields['langcode'] = array( 'label' => t('Language code'), 'description' => t('The feed language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $fields['url'] = array( 'label' => t('URL'), diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php index f0b6694..10717ce 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php @@ -184,7 +184,7 @@ public static function baseFieldDefinitions($entity_type) { $fields['langcode'] = array( 'label' => t('Language code'), 'description' => t('The feed item language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $fields['link'] = array( 'label' => t('Link'), diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php index 2044050..9c806d7 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php @@ -273,7 +273,7 @@ public static function baseFieldDefinitions($entity_type) { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The custom block language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['info'] = array( 'label' => t('Subject'), diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index c30d380..86be646 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -387,7 +387,7 @@ public static function baseFieldDefinitions($entity_type) { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The comment language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['subject'] = array( 'label' => t('Subject'), diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index 79345a8..bade4d5 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -68,6 +68,140 @@ function field_behaviors_widget($op, $instance) { } /** +<<<<<<< HEAD +======= + * Returns a lightweight map of fields across bundles. + * + * The function only returns active, non deleted fields. + * + * @return + * An array keyed by field name. Each value is an array with two entries: + * - type: The field type. + * - bundles: The bundles in which the field appears, as an array with entity + * types as keys and the array of bundle names as values. + * Example: + * @code + * array( + * 'body' => array( + * 'bundles' => array( + * 'node' => array('page', 'article'), + * ), + * 'type' => 'text_with_summary', + * ), + * ); + * @endcode + * + * @deprecated as of Drupal 8.0. Use + * Field::fieldInfo()->getFieldMap(). + */ +function field_info_field_map() { + return Field::fieldInfo()->getFieldMap(); +} + +/** + * Returns information about configurable field types. + * + * @param $field_type + * (optional) A field type name. If omitted, all field types will be returned. + * + * @return + * Either a field type definition, or an array of all existing field types, + * keyed by field type name. + * + * @deprecated as of Drupal 8.0. Use + * Drupal::service('plugin.manager.entity.field.field_type')->getDefinition() + * or + * Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions() + */ +function field_info_field_types($field_type = NULL) { + if ($field_type) { + return Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_type); + } + else { + return array_filter(Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions(), function ($definition) { + return $definition['configurable']; + }); + } +} + +/** + * Returns information about field widgets from AnnotatedClassDiscovery. + * + * @param string $widget_type + * (optional) A widget type name. If omitted, all widget types will be + * returned. + * + * @return array + * Either a single widget type description, as provided by class annotations, + * or an array of all existing widget types, keyed by widget type name. + * + * @deprecated as of Drupal 8.0. Use + * Drupal::service('plugin.manager.field.widget')->getDefinition() + * or + * Drupal::service('plugin.manager.field.widget')->getDefinitions() + */ +function field_info_widget_types($widget_type = NULL) { + if ($widget_type) { + return drupal_container()->get('plugin.manager.field.widget')->getDefinition($widget_type); + } + else { + return drupal_container()->get('plugin.manager.field.widget')->getDefinitions(); + } +} + +/** + * Returns information about field formatters from hook_field_formatter_info(). + * + * @param string $formatter_type + * (optional) A formatter type name. If omitted, all formatter types will be + * returned. + * + * @return array + * Either a single formatter type description, as provided by class + * annotations, or an array of all existing formatter types, keyed by + * formatter type name. + * + * @deprecated as of Drupal 8.0. Use + * Drupal::service('plugin.manager.field.formatter')->getDefinition() + * or + * Drupal::service('plugin.manager.field.formatter')->getDefinitions() + */ +function field_info_formatter_types($formatter_type = NULL) { + if ($formatter_type) { + return drupal_container()->get('plugin.manager.field.formatter')->getDefinition($formatter_type); + } + else { + return drupal_container()->get('plugin.manager.field.formatter')->getDefinitions(); + } +} + +/** + * Returns information about field storage from hook_field_storage_info(). + * + * @param $storage_type + * (optional) A storage type name. If omitted, all storage types will be + * returned. + * + * @return + * Either a storage type description, as provided by + * hook_field_storage_info(), or an array of all existing storage types, keyed + * by storage type name. + */ +function field_info_storage_types($storage_type = NULL) { + $info = _field_info_collate_types(); + $storage_types = $info['storage types']; + if ($storage_type) { + if (isset($storage_types[$storage_type])) { + return $storage_types[$storage_type]; + } + } + else { + return $storage_types; + } +} + +/** +>>>>>>> applied patch * Returns all field definitions. * * Use of this function should be avoided when possible, since it loads and diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/LegacyFieldTypeDiscoveryDecorator.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/LegacyFieldTypeDiscoveryDecorator.php index 2fc45a4..2c8b362 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/LegacyFieldTypeDiscoveryDecorator.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/LegacyFieldTypeDiscoveryDecorator.php @@ -63,11 +63,10 @@ public function getDefinitions() { $function = $module . '_field_info'; if (function_exists($function)) { foreach ($function() as $plugin_id => $definition) { - $definition += array( - 'id' => $plugin_id, - 'provider' => $module, - 'list_class' => '\Drupal\field\Plugin\field\field_type\LegacyConfigField', - ); + $definition['id'] = $plugin_id; + $definition['provider'] = $module; + $definition['configurable'] = TRUE; + $definition['list_class'] = '\Drupal\field\Plugin\field\field_type\LegacyConfigField'; $definitions[$plugin_id] = $definition; } } diff --git a/core/modules/file/lib/Drupal/file/Entity/File.php b/core/modules/file/lib/Drupal/file/Entity/File.php index b891253..2f13e99 100644 --- a/core/modules/file/lib/Drupal/file/Entity/File.php +++ b/core/modules/file/lib/Drupal/file/Entity/File.php @@ -231,7 +231,7 @@ public static function baseFieldDefinitions($entity_type) { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The file language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['uid'] = array( 'label' => t('User ID'), diff --git a/core/modules/node/lib/Drupal/node/Entity/Node.php b/core/modules/node/lib/Drupal/node/Entity/Node.php index 8367e16..7faee83 100644 --- a/core/modules/node/lib/Drupal/node/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Entity/Node.php @@ -347,7 +347,7 @@ public static function baseFieldDefinitions($entity_type) { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The node language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['title'] = array( 'label' => t('Title'), diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php index 95d74ce..5cc1bdb 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php @@ -120,7 +120,7 @@ public static function baseFieldDefinitions($entity_type) { $fields['langcode'] = array( 'label' => t('Language code'), 'description' => t('The language code of the test entity.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $fields['name'] = array( 'label' => t('Name'), diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php index 03ddfe2..b38f164 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php @@ -223,7 +223,7 @@ public static function baseFieldDefinitions($entity_type) { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The term language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['name'] = array( 'label' => t('Name'), diff --git a/core/modules/user/lib/Drupal/user/Entity/User.php b/core/modules/user/lib/Drupal/user/Entity/User.php index 748c8f1..005e20e 100644 --- a/core/modules/user/lib/Drupal/user/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Entity/User.php @@ -438,17 +438,17 @@ public static function baseFieldDefinitions($entity_type) { $properties['langcode'] = array( 'label' => t('Language code'), 'description' => t('The user language code.'), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['preferred_langcode'] = array( 'label' => t('Language code'), 'description' => t("The user's preferred langcode for receiving emails and viewing the site."), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['preferred_admin_langcode'] = array( 'label' => t('Language code'), 'description' => t("The user's preferred langcode for viewing administration pages."), - 'type' => 'language_field', + 'type' => 'field_item:language', ); $properties['name'] = array( 'label' => t('Name'),