Issue #2023563 by Berdir, smiletrl, fago: Convert entity field types to the field_type plugin.
parent
5b026c3854
commit
0f8b4e794e
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Entity\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
use Drupal\Core\TypedData\Annotation\DataType;
|
||||
|
||||
/**
|
||||
* Defines a FieldType annotation object.
|
||||
|
@ -17,7 +17,7 @@ use Drupal\Component\Annotation\Plugin;
|
|||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class FieldType extends Plugin {
|
||||
class FieldType extends DataType {
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
|
@ -103,8 +103,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 +110,13 @@ 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.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $no_ui = FALSE;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $list_class;
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
|
|
|
@ -471,8 +471,16 @@ class EntityManager extends PluginManagerBase {
|
|||
}
|
||||
else {
|
||||
$class = $this->factory->getPluginClass($entity_type, $this->getDefinition($entity_type));
|
||||
|
||||
$base_definitions = $class::baseFieldDefinitions($entity_type);
|
||||
foreach ($base_definitions as &$base_definition) {
|
||||
// Support old-style field types to avoid that all base field
|
||||
// definitions need to be changed.
|
||||
// @todo: Remove after https://drupal.org/node/2047229.
|
||||
$base_definition['type'] = preg_replace('/(.+)_field/', 'field_item:$1', $base_definition['type']);
|
||||
}
|
||||
$this->entityFieldInfo[$entity_type] = array(
|
||||
'definitions' => $class::baseFieldDefinitions($entity_type),
|
||||
'definitions' => $base_definitions,
|
||||
// Contains definitions of optional (per-bundle) fields.
|
||||
'optional' => array(),
|
||||
// An array keyed by bundle name containing the optional fields added
|
||||
|
|
|
@ -25,7 +25,6 @@ class FieldTypePluginManager extends DefaultPluginManager {
|
|||
protected $defaults = array(
|
||||
'settings' => array(),
|
||||
'instance_settings' => array(),
|
||||
'list_class' => '\Drupal\field\Plugin\Type\FieldType\ConfigFieldItemList',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -51,6 +50,21 @@ class FieldTypePluginManager extends DefaultPluginManager {
|
|||
$this->discovery = new LegacyFieldTypeDiscoveryDecorator($this->discovery, $module_handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processDefinition(&$definition, $plugin_id) {
|
||||
parent::processDefinition($definition, $plugin_id);
|
||||
if (!isset($definition['list_class'])) {
|
||||
if ($definition['configurable']) {
|
||||
$definition['list_class'] = '\Drupal\field\Plugin\Type\FieldType\ConfigFieldItemList';
|
||||
}
|
||||
else {
|
||||
$definition['list_class'] = '\Drupal\Core\Entity\Field\FieldItemList';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default field-level settings for a field type.
|
||||
*
|
||||
|
@ -81,4 +95,17 @@ class FieldTypePluginManager extends DefaultPluginManager {
|
|||
return isset($info['instance_settings']) ? $info['instance_settings'] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the definition of all field types that are configurable.
|
||||
*
|
||||
* @return array
|
||||
* An array of field type definitions.
|
||||
*/
|
||||
public function getConfigurableDefinitions() {
|
||||
$definitions = $this->getDefinitions();
|
||||
return array_filter($definitions, function ($definition) {
|
||||
return $definition['configurable'];
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,23 +2,21 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Plugin\DataType\BooleanItem.
|
||||
* Contains \Drupal\Core\Entity\Plugin\field\field_type\BooleanItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Plugin\DataType;
|
||||
namespace Drupal\Core\Entity\Plugin\field\field_type;
|
||||
|
||||
use Drupal\Core\TypedData\Annotation\DataType;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
use Drupal\Core\Entity\Field\FieldItemBase;
|
||||
|
||||
/**
|
||||
* Defines the 'boolean_field' entity field item.
|
||||
* Defines the 'boolean' entity field type.
|
||||
*
|
||||
* @DataType(
|
||||
* id = "boolean_field",
|
||||
* label = @Translation("Boolean field item"),
|
||||
* @FieldType(
|
||||
* id = "boolean",
|
||||
* label = @Translation("Boolean"),
|
||||
* description = @Translation("An entity field containing a boolean value."),
|
||||
* list_class = "\Drupal\Core\Entity\Field\FieldItemList"
|
||||
* configurable = FALSE
|
||||
* )
|
||||
*/
|
||||
class BooleanItem extends FieldItemBase {
|
|
@ -2,23 +2,21 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Plugin\DataType\DateItem.
|
||||
* Contains \Drupal\Core\Entity\Plugin\field\field_type\DateItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Plugin\DataType;
|
||||
namespace Drupal\Core\Entity\Plugin\field\field_type;
|
||||
|
||||
use Drupal\Core\TypedData\Annotation\DataType;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
use Drupal\Core\Entity\Field\FieldItemBase;
|
||||
|
||||
/**
|
||||
* Defines the 'date_field' entity field item.
|
||||
* Defines the 'date' entity field type.
|
||||
*
|
||||
* @DataType(
|
||||
* id = "date_field",
|
||||
* label = @Translation("Date field item"),
|
||||
* @FieldType(
|
||||
* id = "date",
|
||||
* label = @Translation("Date"),
|
||||
* description = @Translation("An entity field containing a date value."),
|
||||
* list_class = "\Drupal\Core\Entity\Field\FieldItemList"
|
||||
* configurable = FALSE
|
||||
* )
|
||||
*/
|
||||
class DateItem extends FieldItemBase {
|
|
@ -2,27 +2,24 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Plugin\DataType\EmailItem.
|
||||
* Contains \Drupal\Core\Entity\Plugin\field\field_type\EmailItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Plugin\DataType;
|
||||
namespace Drupal\Core\Entity\Plugin\field\field_type;
|
||||
|
||||
use Drupal\Core\TypedData\Annotation\DataType;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
use Drupal\Core\Entity\Field\FieldItemBase;
|
||||
use Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem;
|
||||
|
||||
/**
|
||||
* Defines the 'email_field' entity field item.
|
||||
* Defines the 'email' entity field type.
|
||||
*
|
||||
* @DataType(
|
||||
* id = "email_field",
|
||||
* label = @Translation("E-mail field item"),
|
||||
* @FieldType(
|
||||
* id = "email",
|
||||
* label = @Translation("E-mail"),
|
||||
* description = @Translation("An entity field containing an e-mail value."),
|
||||
* list_class = "\Drupal\Core\Entity\Field\FieldItemList"
|
||||
* configurable = FALSE
|
||||
* )
|
||||
*/
|
||||
class EmailItem extends LegacyConfigFieldItem {
|
||||
class EmailItem extends FieldItemBase {
|
||||
|
||||
/**
|
||||
* Definitions of the contained properties.
|
||||
|
@ -54,4 +51,5 @@ class EmailItem extends LegacyConfigFieldItem {
|
|||
public function isEmpty() {
|
||||
return $this->value === NULL || $this->value === '';
|
||||
}
|
||||
|
||||
}
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem.
|
||||
* Contains \Drupal\Core\Entity\Plugin\field\field_type\EntityReferenceItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Plugin\DataType;
|
||||
namespace Drupal\Core\Entity\Plugin\field\field_type;
|
||||
|
||||
use Drupal\Core\TypedData\Annotation\DataType;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
|
@ -13,7 +13,7 @@ use Drupal\Core\Entity\Field\FieldItemBase;
|
|||
use Drupal\Core\TypedData\TypedDataInterface;
|
||||
|
||||
/**
|
||||
* Defines the 'entity_reference_item' entity field item.
|
||||
* Defines the 'entity_reference' entity field type.
|
||||
*
|
||||
* Supported settings (below the definition's 'settings' key) are:
|
||||
* - target_type: The entity type to reference. Required.
|
||||
|
@ -21,11 +21,11 @@ use Drupal\Core\TypedData\TypedDataInterface;
|
|||
* may be referenced. May be set to an single bundle, or to an array of
|
||||
* allowed bundles.
|
||||
*
|
||||
* @DataType(
|
||||
* id = "entity_reference_field",
|
||||
* label = @Translation("Entity reference field item"),
|
||||
* @FieldType(
|
||||
* id = "entity_reference",
|
||||
* label = @Translation("Entity reference"),
|
||||
* description = @Translation("An entity field containing an entity reference."),
|
||||
* list_class = "\Drupal\Core\Entity\Field\FieldItemList",
|
||||
* configurable = FALSE,
|
||||
* constraints = {"ValidReference" = TRUE}
|
||||
* )
|
||||
*/
|
|
@ -2,23 +2,21 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Plugin\DataType\FloatItem.
|
||||
* Contains \Drupal\Core\Entity\Plugin\field\field_type\FloatItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Plugin\DataType;
|
||||
namespace Drupal\Core\Entity\Plugin\field\field_type;
|
||||
|
||||
use Drupal\Core\TypedData\Annotation\DataType;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
use Drupal\Core\Entity\Field\FieldItemBase;
|
||||
|
||||
/**
|
||||
* Defines the 'float_field' entity field item.
|
||||
* Defines the 'float' entity field type.
|
||||
*
|
||||
* @DataType(
|
||||
* id = "float_field",
|
||||
* label = @Translation("Float field item"),
|
||||
* @FieldType(
|
||||
* id = "float",
|
||||
* label = @Translation("Float"),
|
||||
* description = @Translation("An entity field containing an float value."),
|
||||
* list_class = "\Drupal\Core\Entity\Field\Field"
|
||||
* configurable = FALSE
|
||||
* )
|
||||
*/
|
||||
class FloatItem extends FieldItemBase {
|
|
@ -2,23 +2,21 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Plugin\DataType\IntegerItem.
|
||||
* Contains \Drupal\Core\Entity\Plugin\field\field_type\IntegerItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Plugin\DataType;
|
||||
namespace Drupal\Core\Entity\Plugin\field\field_type;
|
||||
|
||||
use Drupal\Core\TypedData\Annotation\DataType;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
use Drupal\Core\Entity\Field\FieldItemBase;
|
||||
|
||||
/**
|
||||
* Defines the 'integer_field' entity field item.
|
||||
* Defines the 'integer' entity field type.
|
||||
*
|
||||
* @DataType(
|
||||
* id = "integer_field",
|
||||
* label = @Translation("Integer field item"),
|
||||
* @FieldType(
|
||||
* id = "integer",
|
||||
* label = @Translation("Integer"),
|
||||
* description = @Translation("An entity field containing an integer value."),
|
||||
* list_class = "\Drupal\Core\Entity\Field\FieldItemList"
|
||||
* configurable = FALSE
|
||||
* )
|
||||
*/
|
||||
class IntegerItem extends FieldItemBase {
|
|
@ -2,24 +2,22 @@
|
|||
|
||||
/**
|
||||
* @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\Annotation\Translation;
|
||||
use Drupal\Core\Entity\Field\FieldItemBase;
|
||||
use Drupal\Core\Language\Language;
|
||||
|
||||
/**
|
||||
* Defines the 'language_field' entity field item.
|
||||
* Defines the '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."),
|
||||
* list_class = "\Drupal\Core\Entity\Field\FieldItemList",
|
||||
* configurable = FALSE,
|
||||
* constraints = {
|
||||
* "ComplexData" = {
|
||||
* "value" = {"Length" = {"max" = 12}}
|
|
@ -2,23 +2,21 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Plugin\DataType\StringItem.
|
||||
* Contains \Drupal\Core\Entity\Plugin\field\field_type\StringItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Plugin\DataType;
|
||||
namespace Drupal\Core\Entity\Plugin\field\field_type;
|
||||
|
||||
use Drupal\Core\TypedData\Annotation\DataType;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
use Drupal\Core\Entity\Field\FieldItemBase;
|
||||
|
||||
/**
|
||||
* Defines the 'string_field' entity field item.
|
||||
* Defines the 'string' entity field type.
|
||||
*
|
||||
* @DataType(
|
||||
* id = "string_field",
|
||||
* label = @Translation("String field item"),
|
||||
* @FieldType(
|
||||
* id = "string",
|
||||
* label = @Translation("String"),
|
||||
* description = @Translation("An entity field containing a string value."),
|
||||
* list_class = "\Drupal\Core\Entity\Field\FieldItemList"
|
||||
* configurable = FALSE
|
||||
* )
|
||||
*/
|
||||
class StringItem extends FieldItemBase {
|
|
@ -2,23 +2,21 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Plugin\DataType\UriItem.
|
||||
* Contains \Drupal\Core\Entity\Plugin\field\field_type\UriItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Plugin\DataType;
|
||||
namespace Drupal\Core\Entity\Plugin\field\field_type;
|
||||
|
||||
use Drupal\Core\TypedData\Annotation\DataType;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
use Drupal\Core\Entity\Field\FieldItemBase;
|
||||
|
||||
/**
|
||||
* Defines the 'uri_field' entity field item.
|
||||
* Defines the 'uri' entity field type.
|
||||
*
|
||||
* @DataType(
|
||||
* id = "uri_field",
|
||||
* label = @Translation("URI field item"),
|
||||
* @FieldType(
|
||||
* id = "uri",
|
||||
* label = @Translation("URI"),
|
||||
* description = @Translation("An entity field containing a URI."),
|
||||
* list_class = "\Drupal\Core\Entity\Field\FieldItemList"
|
||||
* configurable = FALSE
|
||||
* )
|
||||
*/
|
||||
class UriItem extends FieldItemBase {
|
|
@ -2,24 +2,21 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Plugin\DataType\UuidItem.
|
||||
* Contains \Drupal\Core\Entity\Plugin\field\field_type\UuidItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Plugin\DataType;
|
||||
|
||||
use Drupal\Core\TypedData\Annotation\DataType;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
namespace Drupal\Core\Entity\Plugin\field\field_type;
|
||||
|
||||
/**
|
||||
* Defines the 'uuid_field' entity field item.
|
||||
* Defines the 'uuid' entity field type.
|
||||
*
|
||||
* The field uses a newly generated UUID as default value.
|
||||
*
|
||||
* @DataType(
|
||||
* id = "uuid_field",
|
||||
* label = @Translation("UUID field item"),
|
||||
* @FieldType(
|
||||
* id = "uuid",
|
||||
* label = @Translation("UUID"),
|
||||
* description = @Translation("An entity field containing a UUID."),
|
||||
* list_class = "\Drupal\Core\Entity\Field\FieldItemList",
|
||||
* configurable = FALSE,
|
||||
* constraints = {
|
||||
* "ComplexData" = {
|
||||
* "value" = {"Length" = {"max" = 128}}
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\comment;
|
||||
|
||||
use Drupal\Core\Entity\Plugin\DataType\StringItem;
|
||||
use Drupal\Core\Entity\Plugin\field\field_type\StringItem;
|
||||
|
||||
/**
|
||||
* The field item for the 'fieldname' field.
|
||||
|
|
|
@ -49,11 +49,8 @@ class CommentItem extends ConfigFieldItemBase {
|
|||
'label' => t('Comment status value'),
|
||||
),
|
||||
'cid' => array(
|
||||
'type' => 'entity_reference_field',
|
||||
'type' => 'integer',
|
||||
'label' => t('Last comment ID'),
|
||||
'settings' => array(
|
||||
'target_type' => 'comment',
|
||||
),
|
||||
),
|
||||
'last_comment_timestamp' => array(
|
||||
'label' => t('Last comment timestamp'),
|
||||
|
@ -66,11 +63,8 @@ class CommentItem extends ConfigFieldItemBase {
|
|||
'type' => 'string',
|
||||
),
|
||||
'last_comment_uid' => array(
|
||||
'type' => 'entity_reference_field',
|
||||
'type' => 'integer',
|
||||
'label' => t('Last comment user ID'),
|
||||
'settings' => array(
|
||||
'target_type' => 'user',
|
||||
),
|
||||
),
|
||||
'comment_count' => array(
|
||||
'label' => t('Number of comments'),
|
||||
|
|
|
@ -31,9 +31,16 @@ function email_help($path, $arg) {
|
|||
* Implements hook_field_info_alter().
|
||||
*/
|
||||
function email_field_info_alter(&$info) {
|
||||
$info['email']['configurable'] = TRUE;
|
||||
$info['email']['class'] = '\Drupal\email\ConfigurableEmailItem';
|
||||
$info['email']['list_class'] = '\Drupal\field\Plugin\Type\FieldType\ConfigFieldItemList';
|
||||
$info['email']['default_widget'] = 'email_default';
|
||||
if (\Drupal::moduleHandler()->moduleExists('text')) {
|
||||
$info['email']['default_formatter'] = 'text_plain';
|
||||
}
|
||||
else {
|
||||
$info['email']['default_formatter'] = 'email_mailto';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,26 +2,21 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\email\Plugin\field\field_type\ConfigurableEmailItem.
|
||||
* Contains \Drupal\email\ConfigurableEmailItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\email\Plugin\field\field_type;
|
||||
namespace Drupal\email;
|
||||
|
||||
use Drupal\Core\Entity\Plugin\DataType\EmailItem;
|
||||
use Drupal\Core\Entity\Plugin\field\field_type\EmailItem;
|
||||
use Drupal\field\FieldInterface;
|
||||
use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemInterface;
|
||||
|
||||
/**
|
||||
* Plugin implementation of the 'email' field type.
|
||||
* Alternative plugin implementation for the 'email' entity field type.
|
||||
*
|
||||
* @FieldType(
|
||||
* id = "email",
|
||||
* label = @Translation("E-mail"),
|
||||
* description = @Translation("This field stores an e-mail address in the database."),
|
||||
* default_widget = "email_default",
|
||||
* default_formatter = "email_mailto"
|
||||
* )
|
||||
* Replaces the default implementation and supports configurable fields.
|
||||
*/
|
||||
class ConfigurableEmailItem extends EmailItem {
|
||||
class ConfigurableEmailItem extends EmailItem implements ConfigFieldItemInterface {
|
||||
|
||||
/**
|
||||
* Defines the max length for an email address
|
||||
|
@ -69,4 +64,19 @@ class ConfigurableEmailItem extends EmailItem {
|
|||
return $constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsForm(array $form, array &$form_state, $has_data) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function instanceSettingsForm(array $form, array &$form_state) {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -15,11 +15,15 @@ use Drupal\field\FieldInterface;
|
|||
* Implements hook_field_info_alter().
|
||||
*/
|
||||
function entity_reference_field_info_alter(&$info) {
|
||||
if (!\Drupal::moduleHandler()->moduleExists('node')) {
|
||||
// Fall back to another primary entity type if the Node module is not
|
||||
// available.
|
||||
$info['entity_reference']['settings']['target_type'] = 'user';
|
||||
}
|
||||
// Make the entity reference field configurable.
|
||||
$info['entity_reference']['configurable'] = TRUE;
|
||||
$info['entity_reference']['class'] = '\Drupal\entity_reference\ConfigurableEntityReferenceItem';
|
||||
$info['entity_reference']['list_class'] = '\Drupal\field\Plugin\Type\FieldType\ConfigFieldItemList';
|
||||
$info['entity_reference']['settings']['target_type'] = \Drupal::moduleHandler()->moduleExists('node') ? 'node' : 'user';
|
||||
$info['entity_reference']['instance_settings']['handler'] = 'default';
|
||||
$info['entity_reference']['instance_settings']['handler_settings'] = array();
|
||||
$info['entity_reference']['default_widget'] = 'entity_reference_autocomplete';
|
||||
$info['entity_reference']['default_formatter'] = 'entity_reference_label';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,7 +31,7 @@ function entity_reference_field_info_alter(&$info) {
|
|||
*
|
||||
* Set the "target_type" property definition for entity reference fields.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem::getPropertyDefinitions()
|
||||
* @see \Drupal\Core\Entity\Plugin\field\field_type\EntityReferenceItem::getPropertyDefinitions()
|
||||
*
|
||||
* @param array $info
|
||||
* The property info array as returned by hook_entity_field_info().
|
||||
|
|
|
@ -2,39 +2,23 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\entity_reference\Plugin\field\field_type\ConfigurableEntityReferenceItem.
|
||||
* Contains \Drupal\entity_reference\ConfigurableEntityReferenceItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\entity_reference\Plugin\field\field_type;
|
||||
namespace Drupal\entity_reference;
|
||||
|
||||
use Drupal\field\Plugin\Type\FieldType\ConfigEntityReferenceItemBase;
|
||||
use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemInterface;
|
||||
use Drupal\field\FieldInterface;
|
||||
|
||||
/**
|
||||
* Plugin implementation of the 'entity_reference' field type.
|
||||
* Alternative plugin implementation of the 'entity_reference' field type.
|
||||
*
|
||||
* @FieldType(
|
||||
* id = "entity_reference",
|
||||
* label = @Translation("Entity Reference"),
|
||||
* description = @Translation("This field references another entity."),
|
||||
* settings = {
|
||||
* "target_type" = "node"
|
||||
* },
|
||||
* instance_settings = {
|
||||
* "handler" = "default",
|
||||
* "handler_settings" = { }
|
||||
* },
|
||||
* default_widget = "entity_reference_autocomplete",
|
||||
* default_formatter = "entity_reference_label",
|
||||
* constraints = {"ValidReference" = TRUE}
|
||||
* )
|
||||
* Replaces the Core 'entity_reference' entity field type implementation, this
|
||||
* supports configurable fields, auto-creation of referenced entities and more.
|
||||
*
|
||||
* Extends the Core 'entity_reference' entity field item with properties for
|
||||
* revision ids, labels (for autocreate) and access.
|
||||
* @see entity_reference_field_info_alter().
|
||||
*
|
||||
* Required settings (below the definition's 'settings' key) are:
|
||||
* - target_type: The entity type to reference.
|
||||
*/
|
||||
class ConfigurableEntityReferenceItem extends ConfigEntityReferenceItemBase implements ConfigFieldItemInterface {
|
||||
|
||||
|
@ -84,7 +68,7 @@ class ConfigurableEntityReferenceItem extends ConfigEntityReferenceItemBase impl
|
|||
$entity = $this->get('entity')->getValue();
|
||||
$target_id = $this->get('target_id')->getValue();
|
||||
|
||||
if (empty($target_id) && !empty($entity) && $entity->isNew()) {
|
||||
if (!$target_id && !empty($entity) && $entity->isNew()) {
|
||||
$entity->save();
|
||||
$this->set('target_id', $entity->id());
|
||||
}
|
|
@ -24,14 +24,14 @@ use Drupal\field\Field;
|
|||
* @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()
|
||||
* \Drupal::service('plugin.manager.entity.field.field_type')->getConfigurableDefinitions().
|
||||
*/
|
||||
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 \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions();
|
||||
return \Drupal::service('plugin.manager.entity.field.field_type')->getConfigurableDefinitions();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,19 +99,23 @@ function field_help($path, $arg) {
|
|||
$items = array();
|
||||
$info = system_get_info('module');
|
||||
$field_widgets = \Drupal::service('plugin.manager.field.widget')->getDefinitions();
|
||||
$field_types = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions();
|
||||
foreach (array_merge($field_types, $field_widgets) as $field_module) {
|
||||
$modules[] = $field_module['provider'];
|
||||
$field_types = \Drupal::service('plugin.manager.entity.field.field_type')->getConfigurableDefinitions();
|
||||
foreach (array_merge($field_types, $field_widgets) as $plugin) {
|
||||
$providers[] = $plugin['provider'];
|
||||
}
|
||||
$modules = array_unique($modules);
|
||||
sort($modules);
|
||||
foreach ($modules as $module) {
|
||||
$display = $info[$module]['name'];
|
||||
if (\Drupal::moduleHandler()->implementsHook($module, 'help')) {
|
||||
$items[] = l($display, 'admin/help/' . $module);
|
||||
}
|
||||
else {
|
||||
$items[] = $display;
|
||||
$providers = array_unique($providers);
|
||||
sort($providers);
|
||||
foreach ($providers as $provider) {
|
||||
// Skip plugins provided by core components as they do not implement
|
||||
// hook_help().
|
||||
if (isset($info[$provider]['name'])) {
|
||||
$display = $info[$provider]['name'];
|
||||
if (\Drupal::moduleHandler()->implementsHook($provider, 'help')) {
|
||||
$items[] = l($display, 'admin/help/' . $provider);
|
||||
}
|
||||
else {
|
||||
$items[] = $display;
|
||||
}
|
||||
}
|
||||
}
|
||||
$item_list = array(
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\field\Plugin\Type\FieldType;
|
||||
|
||||
use Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem;
|
||||
use Drupal\Core\Entity\Plugin\field\field_type\EntityReferenceItem;
|
||||
use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemInterface;
|
||||
use Drupal\field\FieldInterface;
|
||||
use Drupal\field\FieldInstanceInterface;
|
||||
|
|
|
@ -40,7 +40,15 @@ class ConfigFieldItemList extends FieldItemList implements ConfigFieldItemListIn
|
|||
if (!isset($this->instance)) {
|
||||
$entity = $this->getEntity();
|
||||
$instances = FieldAPI::fieldInfo()->getBundleInstances($entity->entityType(), $entity->bundle());
|
||||
$this->instance = $instances[$this->getName()];
|
||||
if (isset($instances[$this->getName()])) {
|
||||
$this->instance = $instances[$this->getName()];
|
||||
}
|
||||
else {
|
||||
// For base fields, fall back to the parent implementation.
|
||||
// @todo: Inject the field definition with
|
||||
// https://drupal.org/node/2047229.
|
||||
return parent::getFieldDefinition();
|
||||
}
|
||||
}
|
||||
return $this->instance;
|
||||
}
|
||||
|
|
|
@ -63,11 +63,10 @@ class LegacyFieldTypeDiscoveryDecorator implements DiscoveryInterface {
|
|||
$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\LegacyConfigFieldItemList',
|
||||
);
|
||||
$definition['id'] = $plugin_id;
|
||||
$definition['provider'] = $module;
|
||||
$definition['configurable'] = TRUE;
|
||||
$definition['list_class'] = '\Drupal\field\Plugin\field\field_type\LegacyConfigFieldItemList';
|
||||
$definitions[$plugin_id] = $definition;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class FieldInfoTest extends FieldUnitTestBase {
|
|||
// Test that field_test module's fields, widgets, and formatters show up.
|
||||
|
||||
$field_test_info = $this->getExpectedFieldTypeDefinition();
|
||||
$info = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions();
|
||||
$info = \Drupal::service('plugin.manager.entity.field.field_type')->getConfigurableDefinitions();
|
||||
foreach ($field_test_info as $t_key => $field_type) {
|
||||
foreach ($field_type as $key => $val) {
|
||||
$this->assertEqual($info[$t_key][$key], $val, format_string('Field type %t_key key %key is %value', array('%t_key' => $t_key, '%key' => $key, '%value' => print_r($val, TRUE))));
|
||||
|
|
|
@ -47,7 +47,7 @@ abstract class DisplayOverviewBase extends OverviewBase {
|
|||
public function __construct(EntityManager $entity_manager, FieldTypePluginManager $field_type_manager, PluginManagerBase $plugin_manager) {
|
||||
parent::__construct($entity_manager);
|
||||
|
||||
$this->fieldTypes = $field_type_manager->getDefinitions();
|
||||
$this->fieldTypes = $field_type_manager->getConfigurableDefinitions();
|
||||
$this->pluginManager = $plugin_manager;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class FieldListController extends ConfigEntityListController {
|
|||
$this->entityManager = $entity_manager;
|
||||
$this->bundles = entity_get_bundles();
|
||||
$this->fieldTypeManager = $field_type_manager;
|
||||
$this->fieldTypes = $this->fieldTypeManager->getDefinitions();
|
||||
$this->fieldTypes = $this->fieldTypeManager->getConfigurableDefinitions();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -89,7 +89,7 @@ class FieldOverview extends OverviewBase {
|
|||
|
||||
// Gather bundle information.
|
||||
$instances = field_info_instances($this->entity_type, $this->bundle);
|
||||
$field_types = $this->fieldTypeManager->getDefinitions();
|
||||
$field_types = $this->fieldTypeManager->getConfigurableDefinitions();
|
||||
|
||||
// Field prefix.
|
||||
$field_prefix = \Drupal::config('field_ui.settings')->get('field_prefix');
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\field_ui\Tests;
|
||||
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Component\Utility\String;
|
||||
|
||||
/**
|
||||
* Tests the functionality of the 'Manage fields' screen.
|
||||
|
@ -423,7 +424,7 @@ class ManageFieldsTest extends FieldUiTestBase {
|
|||
|
||||
// Check that the field type is not available in the 'add new field' row.
|
||||
$this->drupalGet($bundle_path);
|
||||
$this->assertFalse($this->xpath('//select[@id="edit-add-new-field-type"]//option[@value="hidden_test_field"]'), "The 'add new field' select respects field types 'no_ui' property.");
|
||||
$this->assertFalse($this->xpath('//select[@id="edit-fields-add-new-field-type"]//option[@value="hidden_test_field"]'), "The 'add new field' select respects field types 'no_ui' property.");
|
||||
|
||||
// Create a field and an instance programmatically.
|
||||
$field_name = 'hidden_test_field';
|
||||
|
@ -447,13 +448,24 @@ class ManageFieldsTest extends FieldUiTestBase {
|
|||
// Check that the newly added instance appears on the 'Manage Fields'
|
||||
// screen.
|
||||
$this->drupalGet($bundle_path);
|
||||
$this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $instance['label'], 'Field was created and appears in the overview page.');
|
||||
$this->assertFieldByXPath('//table[@id="field-overview"]//tr[@id="hidden-test-field"]//td[1]', $instance['label'], 'Field was created and appears in the overview page.');
|
||||
|
||||
// Check that the instance does not appear in the 're-use existing field' row
|
||||
// on other bundles.
|
||||
$bundle_path = 'admin/structure/types/manage/article/fields/';
|
||||
$this->drupalGet($bundle_path);
|
||||
$this->assertFalse($this->xpath('//select[@id="edit-add-existing-field-field-name"]//option[@value=:field_name]', array(':field_name' => $field_name)), "The 're-use existing field' select respects field types 'no_ui' property.");
|
||||
|
||||
// Check that non-configurable fields are not available.
|
||||
$field_types = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions();
|
||||
foreach ($field_types as $field_type => $definition) {
|
||||
if ($definition['configurable'] && empty($definition['no_ui'])) {
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-fields-add-new-field-type"]//option[@value=:field_type]', array(':field_type' => $field_type)), String::format('Configurable field type @field_type is available.', array('@field_type' => $field_type)));
|
||||
}
|
||||
else {
|
||||
$this->assertFalse($this->xpath('//select[@id="edit-fields-add-new-field-type"]//option[@value=:field_type]', array(':field_type' => $field_type)), String::format('Non-configurable field type @field_type is not available.', array('@field_type' => $field_type)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\file\Plugin\field\field_type;
|
||||
|
||||
use Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem;
|
||||
use Drupal\Core\Entity\Plugin\field\field_type\EntityReferenceItem;
|
||||
use Drupal\field\FieldInterface;
|
||||
use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemInterface;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $supportedInterfaceOrClass = 'Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem';
|
||||
protected $supportedInterfaceOrClass = 'Drupal\Core\Entity\Plugin\field\field_type\EntityReferenceItem';
|
||||
|
||||
/**
|
||||
* Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
|
||||
|
|
|
@ -83,7 +83,7 @@ function node_access_test_permission() {
|
|||
function node_access_test_entity_field_info($entity_type) {
|
||||
if ($entity_type === 'node') {
|
||||
$info['definitions']['private'] = array(
|
||||
'type' => 'boolean_field',
|
||||
'type' => 'field_item:boolean',
|
||||
'label' => t('Private'),
|
||||
'computed' => TRUE,
|
||||
'list' => TRUE,
|
||||
|
|
|
@ -2,23 +2,21 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\path\Plugin\DataType\PathItem.
|
||||
* Contains \Drupal\path\Plugin\field\field_type\PathItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\path\Plugin\DataType;
|
||||
namespace Drupal\path\Plugin\field\field_type;
|
||||
|
||||
use Drupal\Core\TypedData\Annotation\DataType;
|
||||
use Drupal\Core\Annotation\Translation;
|
||||
use Drupal\Core\Entity\Field\FieldItemBase;
|
||||
|
||||
/**
|
||||
* Defines the 'path_field' entity field item.
|
||||
* Defines the 'path' entity field type.
|
||||
*
|
||||
* @DataType(
|
||||
* id = "path_field",
|
||||
* label = @Translation("Path field item"),
|
||||
* @FieldType(
|
||||
* id = "path",
|
||||
* label = @Translation("Path"),
|
||||
* description = @Translation("An entity field containing a path alias and related data."),
|
||||
* list_class = "\Drupal\Core\Entity\Field\FieldItemList"
|
||||
* configurable = FALSE
|
||||
* )
|
||||
*/
|
||||
class PathItem extends FieldItemBase {
|
|
@ -217,7 +217,7 @@ function path_form_taxonomy_term_form_alter(&$form, $form_state) {
|
|||
function path_entity_field_info($entity_type) {
|
||||
if ($entity_type === 'taxonomy_term' || $entity_type === 'node') {
|
||||
$info['definitions']['path'] = array(
|
||||
'type' => 'path_field',
|
||||
'type' => 'field_item:path',
|
||||
'label' => t('The path alias'),
|
||||
'computed' => TRUE,
|
||||
'list' => TRUE,
|
||||
|
|
|
@ -356,8 +356,8 @@ class EntityFieldTest extends EntityUnitTestBase {
|
|||
// @todo: Make this work without having to create entity objects.
|
||||
$entity = entity_create($entity_type, array());
|
||||
$definitions = $entity->getPropertyDefinitions();
|
||||
$this->assertEqual($definitions['name']['type'], 'string_field', $entity_type .': Name field found.');
|
||||
$this->assertEqual($definitions['user_id']['type'], 'entity_reference_field', $entity_type .': User field found.');
|
||||
$this->assertEqual($definitions['name']['type'], 'field_item:string', $entity_type .': Name field found.');
|
||||
$this->assertEqual($definitions['user_id']['type'], 'field_item:entity_reference', $entity_type .': User field found.');
|
||||
$this->assertEqual($definitions['field_test_text']['type'], 'field_item:text', $entity_type .': Test-text-field field found.');
|
||||
|
||||
// Test introspecting an entity object.
|
||||
|
@ -365,8 +365,8 @@ class EntityFieldTest extends EntityUnitTestBase {
|
|||
$entity = entity_create($entity_type, array());
|
||||
|
||||
$definitions = $entity->getPropertyDefinitions();
|
||||
$this->assertEqual($definitions['name']['type'], 'string_field', $entity_type .': Name field found.');
|
||||
$this->assertEqual($definitions['user_id']['type'], 'entity_reference_field', $entity_type .': User field found.');
|
||||
$this->assertEqual($definitions['name']['type'], 'field_item:string', $entity_type .': Name field found.');
|
||||
$this->assertEqual($definitions['user_id']['type'], 'field_item:entity_reference', $entity_type .': User field found.');
|
||||
$this->assertEqual($definitions['field_test_text']['type'], 'field_item:text', $entity_type .': Test-text-field field found.');
|
||||
|
||||
$name_properties = $entity->name->getPropertyDefinitions();
|
||||
|
@ -537,7 +537,7 @@ class EntityFieldTest extends EntityUnitTestBase {
|
|||
$entity->save();
|
||||
// Create a reference field item and let it reference the entity.
|
||||
$definition = array(
|
||||
'type' => 'entity_reference_field',
|
||||
'type' => 'field_item:entity_reference',
|
||||
'settings' => array(
|
||||
'target_type' => 'entity_test',
|
||||
),
|
||||
|
@ -564,7 +564,7 @@ class EntityFieldTest extends EntityUnitTestBase {
|
|||
|
||||
// Test bundle validation.
|
||||
$definition = array(
|
||||
'type' => 'entity_reference_field',
|
||||
'type' => 'field_item:entity_reference',
|
||||
'settings' => array(
|
||||
'target_type' => 'node',
|
||||
'target_bundle' => 'article',
|
||||
|
|
|
@ -548,7 +548,7 @@ class TypedDataTest extends DrupalUnitTestBase {
|
|||
// Test validating property containers and make sure the NotNull and Null
|
||||
// constraints work with typed data containers.
|
||||
$definition = array(
|
||||
'type' => 'integer_field',
|
||||
'type' => 'field_item:integer',
|
||||
'constraints' => array(
|
||||
'NotNull' => array(),
|
||||
),
|
||||
|
@ -569,7 +569,7 @@ class TypedDataTest extends DrupalUnitTestBase {
|
|||
|
||||
// Test the Null constraint with typed data containers.
|
||||
$definition = array(
|
||||
'type' => 'float_field',
|
||||
'type' => 'field_item:float',
|
||||
'constraints' => array(
|
||||
'Null' => array(),
|
||||
),
|
||||
|
@ -605,7 +605,7 @@ class TypedDataTest extends DrupalUnitTestBase {
|
|||
// Test validating a list of a values and make sure property paths starting
|
||||
// with "0" are created.
|
||||
$definition = array(
|
||||
'type' => 'integer_field',
|
||||
'type' => 'field_item:integer',
|
||||
'list' => TRUE,
|
||||
);
|
||||
$violations = $this->typedData->create($definition, array(array('value' => 10)))->validate();
|
||||
|
|
|
@ -56,6 +56,13 @@ class User extends ContentEntityBase implements UserInterface {
|
|||
return $this->get('uid')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isNew() {
|
||||
return !empty($this->enforceIsNew) || $this->id() === NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue