diff --git a/core/lib/Drupal/Core/Field/FieldDefinition.php b/core/lib/Drupal/Core/Field/FieldDefinition.php index bb4aceb..a5ab05a 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinition.php +++ b/core/lib/Drupal/Core/Field/FieldDefinition.php @@ -22,11 +22,8 @@ class FieldDefinition extends ListDefinition implements FieldDefinitionInterface * @param string $type * The type of the field. * - * @return \Drupal\Core\Field\FieldDefinition + * @return static * A new field definition object. - * - * @todo Type-hint the return value with the interface when setters are added - * in https://drupal.org/node/2143297. */ public static function create($type) { return new static(array(), DataDefinition::create('field_item:' . $type)); diff --git a/core/lib/Drupal/Core/Field/FieldItemBase.php b/core/lib/Drupal/Core/Field/FieldItemBase.php index 8a41f6d..28a6597 100644 --- a/core/lib/Drupal/Core/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Field/FieldItemBase.php @@ -31,10 +31,6 @@ public function __construct(DataDefinitionInterface $definition, $name = NULL, T // Initialize computed properties by default, such that they get cloned // with the whole item. foreach ($this->getPropertyDefinitions() as $name => $definition) { - if (!is_object($definition)) { - echo '
';
- print_r($definition);
- }
if ($definition->isComputed()) {
$this->properties[$name] = \Drupal::typedData()->getPropertyInstance($this, $name);
}
diff --git a/core/lib/Drupal/Core/Plugin/Context/Context.php b/core/lib/Drupal/Core/Plugin/Context/Context.php
index fbdf658..e1b9f62 100644
--- a/core/lib/Drupal/Core/Plugin/Context/Context.php
+++ b/core/lib/Drupal/Core/Plugin/Context/Context.php
@@ -10,6 +10,7 @@
use Drupal\Component\Plugin\Context\Context as ComponentContext;
use Drupal\Core\Entity\Plugin\DataType\EntityWrapper;
use Drupal\Core\TypedData\ComplexDataInterface;
+use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\ListInterface;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\Core\Validation\DrupalTranslator;
@@ -49,7 +50,7 @@ public function getContextValue() {
public function setContextValue($value) {
// Make sure the value set is a typed data object.
if (!empty($this->contextDefinition['type']) && !$value instanceof TypedDataInterface) {
- $value = \Drupal::typedData()->create($this->contextDefinition, $value);
+ $value = \Drupal::typedData()->create(new DataDefinition($this->contextDefinition), $value);
}
parent::setContextValue($value);
}
diff --git a/core/lib/Drupal/Core/TypedData/DataDefinition.php b/core/lib/Drupal/Core/TypedData/DataDefinition.php
index 9fec1a3..89d9f4e 100644
--- a/core/lib/Drupal/Core/TypedData/DataDefinition.php
+++ b/core/lib/Drupal/Core/TypedData/DataDefinition.php
@@ -10,7 +10,7 @@
/**
* A class for defining data based on defined data types.
*/
-class DataDefinition implements DataDefinitionInterface {
+class DataDefinition implements DataDefinitionInterface, \ArrayAccess {
/**
* The array holding values for all definition keys.
@@ -300,6 +300,51 @@ public function addConstraint($constraint_name, $options = NULL) {
}
/**
+ * {@inheritdoc}
+ *
+ * This is for BC support only.
+ * @todo: Remove in https://drupal.org/node/1928868.
+ */
+ public function offsetExists($offset) {
+ // PHP's array access does not work correctly with isset(), so we have to
+ // bake isset() in here. See https://bugs.php.net/bug.php?id=41727.
+ return array_key_exists($offset, $this->definition) && isset($this->definition[$offset]);
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * This is for BC support only.
+ * @todo: Remove in https://drupal.org/node/1928868.
+ */
+ public function &offsetGet($offset) {
+ if (!isset($this->definition[$offset])) {
+ $this->definition[$offset] = NULL;
+ }
+ return $this->definition[$offset];
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * This is for BC support only.
+ * @todo: Remove in https://drupal.org/node/1928868.
+ */
+ public function offsetSet($offset, $value) {
+ $this->definition[$offset] = $value;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * This is for BC support only.
+ * @todo: Remove in https://drupal.org/node/1928868.
+ */
+ public function offsetUnset($offset) {
+ unset($this->definition[$offset]);
+ }
+
+ /**
* Returns all definition values as array.
*
* @return array
diff --git a/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php b/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php
index 219cd30..e026fe8 100644
--- a/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php
+++ b/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php
@@ -118,8 +118,9 @@ public function getSetting($setting_name);
* See \Drupal\Core\TypedData\TypedDataManager::getConstraints() for details.
*
* @return array
- * Array of constraints, each being an instance of
- * \Symfony\Component\Validator\Constraint.
+ * An array of validation constraint definitions, keyed by constraint name.
+ * Each constraint definition can be used for instantiating
+ * \Symfony\Component\Validator\Constraint objects.
*/
public function getConstraints();
@@ -131,8 +132,9 @@ public function getConstraints();
* @param string $constraint_name
* The name of the the constraint, i.e. its plugin id.
*
- * @return \Symfony\Component\Validator\Constraint
- * A validation constraint.
+ * @return array
+ * A validation constraint definition which can be used for instantiating a
+ * \Symfony\Component\Validator\Constraint object.
*/
public function getConstraint($constraint_name);
diff --git a/core/lib/Drupal/Core/TypedData/TypedData.php b/core/lib/Drupal/Core/TypedData/TypedData.php
index dd97479..bf5f787 100644
--- a/core/lib/Drupal/Core/TypedData/TypedData.php
+++ b/core/lib/Drupal/Core/TypedData/TypedData.php
@@ -51,8 +51,12 @@
* root of a typed data tree. Defaults to NULL.
*
* @see \Drupal\Core\TypedData\TypedDataManager::create()
+ *
+ * @todo When \Drupal\Core\Config\TypedConfigManager has been fixed to use
+ * class-based definitions, type-hint $definition to
+ * DataDefinitionInterface. https://drupal.org/node/1928868
*/
- public function __construct(DataDefinitionInterface $definition, $name = NULL, TypedDataInterface $parent = NULL) {
+ public function __construct($definition, $name = NULL, TypedDataInterface $parent = NULL) {
$this->definition = $definition;
$this->parent = $parent;
$this->name = $name;
diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php
index 9d8990c..cd660cb 100644
--- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php
+++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php
@@ -274,13 +274,12 @@ public static function baseFieldDefinitions($entity_type) {
->setLabel(t('Refresh'))
->setDescription(t('How often to check for new feed items, in seconds.'));
- // @todo Do we need a "timestamp" field? Not sure how DateItem is supposed
- // to store its data.
+ // @todo Convert to a "timestamp" field in https://drupal.org/node/2145103.
$fields['checked'] = FieldDefinition::create('integer')
->setLabel(t('Checked'))
->setDescription(t('Last time feed was checked for new items, as Unix timestamp.'));
- // @todo Candidate for timestamp.
+ // @todo Convert to a "timestamp" field in https://drupal.org/node/2145103.
$fields['queued'] = FieldDefinition::create('integer')
->setLabel(t('Queued'))
->setDescription(t('Time when this feed was queued for refresh, 0 if not queued.'));
@@ -305,7 +304,7 @@ public static function baseFieldDefinitions($entity_type) {
->setLabel(t('Etag'))
->setDescription(t('Entity tag HTTP response header, used for validating cache.'));
- // @todo Candidate for timestamp.
+ // @todo Convert to a "changed" field in https://drupal.org/node/2145103.
$fields['modified'] = FieldDefinition::create('integer')
->setLabel(t('Modified'))
->setDescription(t('When the feed was last modified, as a Unix timestamp.'));
diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php
index a0366a5..818f463 100644
--- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php
+++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php
@@ -112,7 +112,7 @@ public static function baseFieldDefinitions($entity_type) {
->setLabel(t('Description'))
->setDescription(t('The body of the feed item.'));
- // @todo Candidate for timestamp.
+ // @todo Convert to a "timestamp" field in https://drupal.org/node/2145103.
$fields['timestamp'] = FieldDefinition::create('integer')
->setLabel(t('Posted timestamp'))
->setDescription(t('Posted date of the feed item, as a Unix timestamp.'));
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 c254c0a..d50db2e 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
@@ -276,7 +276,7 @@ public static function baseFieldDefinitions($entity_type) {
->setLabel(t('Revision log message'))
->setDescription(t('The revision log message.'));
- // @todo Candidate for timestamp.
+ // @todo Convert to a "changed" field in https://drupal.org/node/2145103.
$fields['changed'] = FieldDefinition::create('integer')
->setLabel(t('Changed'))
->setDescription(t('The time that the custom block was last edited.'))
diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
index 29b76f4..6c411ba 100644
--- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
+++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
@@ -407,12 +407,12 @@ public static function baseFieldDefinitions($entity_type) {
->setLabel(t('Hostname'))
->setDescription(t("The comment author's hostname."));
- // @todo Candidate for timestamp.
+ // @todo Convert to a "created" field in https://drupal.org/node/2145103.
$fields['created'] = FieldDefinition::create('integer')
->setLabel(t('Created'))
->setDescription(t('The time that the comment was created.'));
- // @todo Candidate for timestamp.
+ // @todo Convert to a "changed" field in https://drupal.org/node/2145103.
$fields['changed'] = FieldDefinition::create('integer')
->setLabel(t('Changed'))
->setDescription(t('The time that the comment was last edited.'))
diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php
index 5efae7f..3fbcca1 100644
--- a/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php
+++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php
@@ -52,9 +52,7 @@ public function getPropertyDefinitions() {
->setDescription(t('The computed DateTime object.'))
->setComputed(TRUE)
->setClass('\Drupal\datetime\DateTimeComputed')
- ->setSettings(array(
- 'date source' => 'value',
- ));
+ ->setSetting('date source', 'value');
}
return static::$propertyDefinitions;
diff --git a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php
index 909e0a3..88b6e1f 100644
--- a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php
+++ b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php
@@ -243,7 +243,7 @@ protected function simplify(array &$form, array &$form_state) {
*/
protected function getChangedFieldName(EntityInterface $entity) {
foreach ($entity as $field_name => $field) {
- $constraints = $field->getDefinition()->getConstraints();
+ $constraints = $field->getItemDefinition()->getConstraints();
if (isset($constraints['ComplexData']['value']['EntityChanged'])) {
return $field_name;
}
diff --git a/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php b/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php
index e2dd5a7..dc83b6d 100644
--- a/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php
+++ b/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php
@@ -7,8 +7,8 @@
namespace Drupal\locale;
+use Drupal\Core\Language\Language;
use Drupal\Core\TypedData\ContextAwareInterface;
-use Drupal\Core\TypedData\DataDefinitionInterface;
use Drupal\Core\Config\Schema\Element;
use Drupal\Core\Config\Schema\ArrayElement;
@@ -50,7 +50,7 @@ class LocaleTypedConfig extends Element {
* @param \Drupal\locale\LocaleConfigManager $localeConfig;
* The locale configuration manager object.
*/
- public function __construct(DataDefinitionInterface $definition, $name, $langcode, LocaleConfigManager $localeConfig) {
+ public function __construct($definition, $name, $langcode, LocaleConfigManager $localeConfig) {
parent::__construct($definition, $name);
$this->langcode = $langcode;
$this->localeConfig = $localeConfig;
diff --git a/core/modules/node/lib/Drupal/node/Entity/Node.php b/core/modules/node/lib/Drupal/node/Entity/Node.php
index a7311a3..acd8258 100644
--- a/core/modules/node/lib/Drupal/node/Entity/Node.php
+++ b/core/modules/node/lib/Drupal/node/Entity/Node.php
@@ -373,12 +373,12 @@ public static function baseFieldDefinitions($entity_type) {
->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the node is published.'));
- // @todo Candidate for timestamp.
+ // @todo Convert to a "created" field in https://drupal.org/node/2145103.
$fields['created'] = FieldDefinition::create('integer')
->setLabel(t('Created'))
->setDescription(t('The time that the node was created.'));
- // @todo Candidate for timestamp.
+ // @todo Convert to a "changed" field in https://drupal.org/node/2145103.
$fields['changed'] = FieldDefinition::create('integer')
->setLabel(t('Changed'))
->setDescription(t('The time that the node was last edited.'))
@@ -392,7 +392,7 @@ public static function baseFieldDefinitions($entity_type) {
->setLabel(t('Sticky'))
->setDescription(t('A boolean indicating whether the node should be displayed at the top of lists in which it appears.'));
- // @todo Candidate for timestamp.
+ // @todo Convert to a "timestamp" field in https://drupal.org/node/2145103.
$fields['revision_timestamp'] = FieldDefinition::create('integer')
->setLabel(t('Revision timestamp'))
->setDescription(t('The time that the current revision was created.'))
diff --git a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php
index 1408b47..90a7229 100644
--- a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php
@@ -552,7 +552,7 @@ public function testTypedDataValidation() {
$field_item = $this->typedData->create($definition, array('value' => 'no integer'));
$violations = $field_item->validate();
$this->assertEqual($violations->count(), 1);
- $this->assertEqual($violations[0]->getPropertyPath(), 'value');
+ $this->assertEqual($violations[0]->getPropertyPath(), '0.value');
// Test that the field item may not be empty.
$field_item = $this->typedData->create($definition);
diff --git a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php
index a41b77a..90d86c2 100644
--- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php
+++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php
@@ -39,9 +39,7 @@ public function getPropertyDefinitions() {
->setDescription(t('The text value with the text format applied.'))
->setComputed(TRUE)
->setClass('\Drupal\text\TextProcessed')
- ->setSettings(array(
- 'text source' => 'value',
- ));
+ ->setSetting('text source', 'value');
}
return static::$propertyDefinitions;
}
diff --git a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php
index 08525d1..835d77c 100644
--- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php
+++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php
@@ -49,9 +49,7 @@ public function getPropertyDefinitions() {
->setDescription(t('The summary text value with the text format applied.'))
->setComputed(TRUE)
->setClass('\Drupal\text\TextProcessed')
- ->setSettings(array(
- 'text source' => 'summary',
- ));
+ ->setSetting('text source', 'summary');
}
return static::$propertyDefinitions;
}
diff --git a/core/modules/user/lib/Drupal/user/Entity/User.php b/core/modules/user/lib/Drupal/user/Entity/User.php
index 530fe83..1b1128a 100644
--- a/core/modules/user/lib/Drupal/user/Entity/User.php
+++ b/core/modules/user/lib/Drupal/user/Entity/User.php
@@ -497,18 +497,18 @@ public static function baseFieldDefinitions($entity_type) {
->setDescription(t('Whether the user is active (1) or blocked (0).'))
->setFieldSetting('default_value', 1);
- // @todo Candidate for timestamp.
+ // @todo Convert to a "created" field in https://drupal.org/node/2145103.
$fields['created'] = FieldDefinition::create('integer')
->setLabel(t('Created'))
->setDescription(t('The time that the user was created.'));
- // @todo Candidate for timestamp.
+ // @todo Convert to a "timestamp" field in https://drupal.org/node/2145103.
$fields['access'] = FieldDefinition::create('integer')
->setLabel(t('Last access'))
->setDescription(t('The time that the user last accessed the site.'))
->setFieldSetting('default_value', 0);
- // @todo Candidate for timestamp.
+ // @todo Convert to a "timestamp" field in https://drupal.org/node/2145103.
$fields['login'] = FieldDefinition::create('integer')
->setLabel(t('Last login'))
->setDescription(t('The time that the user last logged in.'))