diff --git a/core/lib/Drupal/Core/Entity/Field/FieldDefinition.php b/core/lib/Drupal/Core/Entity/Field/FieldDefinition.php new file mode 100644 index 0000000..5ff9247 --- /dev/null +++ b/core/lib/Drupal/Core/Entity/Field/FieldDefinition.php @@ -0,0 +1,107 @@ +field = $field; + $this->definition = $field->getDefinition() + \Drupal::typedData()->getDefinition($field->getType()); + } + + /** + * {@inheritdoc} + */ + public function getFieldName() { + return $this->field->getName(); + } + + /** + * {@inheritdoc} + */ + public function getFieldType() { + return $this->definition['field_type']; + } + + /** + * {@inheritdoc} + */ + public function getFieldSettings() { + return $this->definition['settings']; + } + + /** + * {@inheritdoc} + */ + public function getFieldSetting($setting_name) { + return $this->definition['settings'][$setting_name]; + } + + /** + * {@inheritdoc} + */ + public function getFieldPropertyNames() { + return array_keys($this->field->getPropertyDefinitions()); + } + + /** + * {@inheritdoc} + */ + public function isFieldTranslatable() { + return !empty($this->definition['translatable']); + } + + /** + * {@inheritdoc} + */ + public function getFieldLabel() { + return $this->definition['label']; + } + + /** + * {@inheritdoc} + */ + public function getFieldDescription() { + return $this->definition['description']; + } + + /** + * {@inheritdoc} + */ + public function getFieldCardinality() { + return isset($this->definition['cardinality']) ? $this->definition['cardinality'] : 1; + } + + /** + * {@inheritdoc} + */ + public function isFieldRequired() { + return !empty($this->definition['required']); + } + +} diff --git a/core/lib/Drupal/Core/Entity/Field/FieldInterface.php b/core/lib/Drupal/Core/Entity/Field/FieldInterface.php index c2dfbdb..4db0c48 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldInterface.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldInterface.php @@ -28,6 +28,13 @@ interface FieldInterface extends ListInterface, AccessibleInterface { /** + * Gets the field definition. + * + * @return \Drupal\Core\Entity\Field\FieldDefinitionInterface + */ + public function getFieldDefinition(); + + /** * Filters out empty field items and re-numbers the item deltas. */ public function filterEmptyValues(); diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index 46a66b9..20b25cc 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -37,6 +37,13 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface } /** + * {@inheritdoc} + */ + public function getFieldDefinition() { + return $this->getParent()->getFieldDefinition(); + } + + /** * Overrides \Drupal\Core\TypedData\TypedData::setValue(). * * @param array|null $values diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemInterface.php b/core/lib/Drupal/Core/Entity/Field/FieldItemInterface.php index 059a477..5d380a2 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemInterface.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemInterface.php @@ -24,6 +24,13 @@ interface FieldItemInterface extends ComplexDataInterface { /** + * Gets the field definition. + * + * @return \Drupal\Core\Entity\Field\FieldDefinitionInterface + */ + public function getFieldDefinition(); + + /** * Magic method: Gets a property value. * * @param $property_name diff --git a/core/lib/Drupal/Core/Entity/Field/Type/Field.php b/core/lib/Drupal/Core/Entity/Field/Type/Field.php index 4d53c18..4b8186d 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/Field.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/Field.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity\Field\Type; +use Drupal\Core\Entity\Field\FieldDefinition; use Drupal\Core\Entity\Field\FieldInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\TypedDataInterface; @@ -37,6 +38,13 @@ class Field extends ItemList implements FieldInterface { protected $list = array(); /** + * The field definition. + * + * @var \Drupal\Core\Entity\Field\FieldDefinitionInterface + */ + protected $fieldDefinition; + + /** * Overrides TypedData::__construct(). */ public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL) { @@ -51,6 +59,16 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface /** * {@inheritdoc} */ + public function getFieldDefinition() { + if (!isset($this->fieldDefinition)) { + $this->fieldDefinition = new FieldDefinition($this); + } + return $this->fieldDefinition; + } + + /** + * {@inheritdoc} + */ public function filterEmptyValues() { if (isset($this->list)) { $this->list = array_values(array_filter($this->list, function($item) { diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/FieldDataTypeDerivative.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/FieldDataTypeDerivative.php index 504e427..81fc77f 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/FieldDataTypeDerivative.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/FieldDataTypeDerivative.php @@ -43,6 +43,16 @@ public function getDerivativeDefinitions(array $base_plugin_definition) { $definition['list class'] = $definition['list_class']; unset($definition['list_class']); + // Provide easy access to the field type without requiring consuming code + // to parse it from the full data type. + $definition['field_type'] = $plugin_id; + + // The distinction between 'settings' and 'instance_settings' is only + // meaningful at the field type plugin level. At the Typed data API level, + // merge them. + $definition['settings'] = $definition['instance_settings'] + $definition['settings']; + unset($definition['instance_settings']); + $this->derivatives[$plugin_id] = $definition; } return $this->derivatives; diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php index 6450975..b333f8c 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php @@ -356,11 +356,13 @@ function getHtmlEntitiesSample() { * (optional) The number of nodes to generate. Defaults to five. */ function createSampleNodes($count = 5) { + // @todo Reconcile difference between title and body language handling. $langcode = Language::LANGCODE_NOT_SPECIFIED; + $langcode2 = language_default()->langcode; // Post $count article nodes. for ($i = 0; $i < $count; $i++) { $edit = array(); - $edit['title'] = $this->randomName(); + $edit["title[$langcode2][0][value]"] = $this->randomName(); $edit["body[$langcode][0][value]"] = $this->randomName(); $this->drupalPost('node/add/article', $edit, t('Save')); } diff --git a/core/modules/book/lib/Drupal/book/Tests/BookTest.php b/core/modules/book/lib/Drupal/book/Tests/BookTest.php index b13a4e7..e5a1eab 100644 --- a/core/modules/book/lib/Drupal/book/Tests/BookTest.php +++ b/core/modules/book/lib/Drupal/book/Tests/BookTest.php @@ -243,8 +243,10 @@ function createBookNode($book_nid, $parent = NULL) { static $number = 0; // Used to ensure that when sorted nodes stay in same order. $edit = array(); + // @todo Reconcile difference between title and body language handling. $langcode = Language::LANGCODE_NOT_SPECIFIED; - $edit["title"] = $number . ' - SimpleTest test node ' . $this->randomName(10); + $langcode2 = language_default()->langcode; + $edit["title[$langcode2][0][value]"] = $number . ' - SimpleTest test node ' . $this->randomName(10); $edit["body[$langcode][0][value]"] = 'SimpleTest test body ' . $this->randomName(32) . ' ' . $this->randomName(32); $edit['book[bid]'] = $book_nid; @@ -259,7 +261,7 @@ function createBookNode($book_nid, $parent = NULL) { } // Check to make sure the book node was created. - $node = $this->drupalGetNodeByTitle($edit['title']); + $node = $this->drupalGetNodeByTitle($edit["title[$langcode2][0][value]"]); $this->assertNotNull(($node === FALSE ? NULL : $node), 'Book node found in database.'); $number++; diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php index 47efe82..74e0d58 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php @@ -90,12 +90,14 @@ function testCommentLanguage() { // language and interface language do not influence comment language, as // only content language has to. foreach (language_list() as $node_langcode => $node_language) { + // @todo Reconcile difference between title and body language handling. $langcode_not_specified = Language::LANGCODE_NOT_SPECIFIED; + $langcode_default = language_default()->langcode; // Create "Article" content. $title = $this->randomName(); $edit = array( - "title" => $title, + "title[$langcode_default][0][value]" => $title, "body[$langcode_not_specified][0][value]" => $this->randomName(), "langcode" => $node_langcode, ); diff --git a/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php b/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php index e619fff..022e473 100644 --- a/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php +++ b/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php @@ -311,8 +311,8 @@ private function doNode($type) { // Create a node using the form in order to generate an add content event // (which is not triggered by drupalCreateNode). $edit = $this->getContent($type); - $langcode = Language::LANGCODE_NOT_SPECIFIED; - $title = $edit["title"]; + $langcode = language_default()->langcode; + $title = $edit["title[$langcode][0][value]"]; $this->drupalPost('node/add/' . $type, $edit, t('Save')); $this->assertResponse(200); // Retrieve the node object. @@ -369,11 +369,13 @@ private function doNode($type) { * Random content needed by various node types. */ private function getContent($type) { + // @todo Reconcile difference between title and body language handling. $langcode = Language::LANGCODE_NOT_SPECIFIED; + $langcode2 = language_default()->langcode; switch ($type) { case 'forum': $content = array( - "title" => $this->randomName(8), + "title[$langcode2][0][value]" => $this->randomName(8), "taxonomy_forums[$langcode]" => array(1), "body[$langcode][0][value]" => $this->randomName(32), ); @@ -381,7 +383,7 @@ private function getContent($type) { default: $content = array( - "title" => $this->randomName(8), + "title[$langcode2][0][value]" => $this->randomName(8), "body[$langcode][0][value]" => $this->randomName(32), ); break; diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php index 2d1f3bb..8c1ed39 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php @@ -91,7 +91,7 @@ public function testAutoCreate() { $this->assertFalse($result, 'Referenced node does not exist yet.'); $edit = array( - 'title' => $this->randomName(), + 'title[en][0][value]' => $this->randomName(), 'test_field[und][0][target_id]' => $new_title, ); $this->drupalPost("node/add/$this->referencing_type", $edit, 'Save'); diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 19bf6ed..0fa26dc 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -173,6 +173,9 @@ function field_theme() { 'field' => array( 'render element' => 'element', ), + 'field__title' => array( + 'base hook' => 'field', + ), 'field_multiple_value_form' => array( 'render element' => 'element', ), @@ -1099,6 +1102,13 @@ function theme_field($variables) { } /** + * @todo Document. + */ +function theme_field__title($variables) { + return '' . drupal_render($variables['items']) . ''; +} + +/** * Assembles a partial entity structure with initial IDs. * * @param stdClass $ids diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php index 3134160..1e356b3 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php @@ -24,6 +24,13 @@ class ConfigField extends Field implements ConfigFieldInterface { protected $instance; /** + * @todo Document. + * + * @var array + */ + protected $instances; + + /** * {@inheritdoc} */ public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL) { @@ -37,9 +44,14 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface * {@inheritdoc} */ public function getInstance() { - if (!isset($this->instance) && $parent = $this->getParent()) { - $instances = FieldAPI::fieldInfo()->getBundleInstances($parent->entityType(), $parent->bundle()); - $this->instance = $instances[$this->getName()]; + if (!isset($this->instance)) { + if (!isset($this->instances) && $parent = $this->getParent()) { + $this->instances = FieldAPI::fieldInfo()->getBundleInstances($parent->entityType(), $parent->bundle()); + } + $field_name = $this->getName(); + if (isset($this->instances[$field_name])) { + $this->instance = $this->instances[$field_name]; + } } return $this->instance; } @@ -47,18 +59,25 @@ public function getInstance() { /** * {@inheritdoc} */ + public function getFieldDefinition() { + return $this->getInstance() ?: parent::getFieldDefinition(); + } + + /** + * {@inheritdoc} + */ public function getConstraints() { $constraints = array(); // Check that the number of values doesn't exceed the field cardinality. For // form submitted values, this can only happen with 'multiple value' // widgets. - $cardinality = $this->getInstance()->getField()->cardinality; + $cardinality = $this->getFieldDefinition()->getFieldCardinality(); if ($cardinality != FIELD_CARDINALITY_UNLIMITED) { $constraints[] = \Drupal::typedData() ->getValidationConstraintManager() ->create('Count', array( 'max' => $cardinality, - 'maxMessage' => t('%name: this field cannot hold more than @count values.', array('%name' => $this->getInstance()->label, '@count' => $cardinality)), + 'maxMessage' => t('%name: this field cannot hold more than @count values.', array('%name' => $this->getFieldDefinition()->getFieldLabel(), '@count' => $cardinality)), )); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php index fa780a5..b6e70f7 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php @@ -134,7 +134,7 @@ protected function checkFieldAccess($op, $entity) { return field_access($op, $field, $entity->entityType(), $entity); } else { - return FALSE; + return TRUE; } } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php index 39deee9..3235a6d 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php @@ -12,7 +12,7 @@ use Drupal\Core\Plugin\Discovery\CacheDecorator; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\AlterDecorator; -use Drupal\field\Plugin\Core\Entity\FieldInstance; +use Drupal\Core\Entity\Field\FieldInterface; /** * Plugin type manager for field formatters. @@ -175,4 +175,31 @@ public function getDefaultSettings($type) { return isset($info['settings']) ? $info['settings'] : array(); } + /** + * @todo Document. + */ + public function viewBaseField(FieldInterface $field) { + $options = array( + 'field_definition' => $field->getFieldDefinition(), + 'view_mode' => 'default', + 'configuration' => array( + 'label' => 'hidden', + ), + ); + $formatter = $this->getInstance($options); + + $entity = $field->getParent()->getBCEntity(); + $entity_id = $entity->id(); + $langcode = $entity->language()->langcode; + $items = $field->getValue(); + + $items_multi = array($entity_id => $items); + $formatter->prepareView(array($entity_id => $entity), $langcode, $items_multi); + $items = $items_multi[$entity_id]; + + $result = $formatter->view($entity, $langcode, $items); + $field_name = $field->getName(); + return isset($result[$field_name]) ? $result[$field_name] : array(); + } + } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php index 654cbbe..e0c2432 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php @@ -449,7 +449,7 @@ protected function checkFieldAccess($op, $entity) { return field_access($op, $field, $entity->entityType(), $entity); } else { - return FALSE; + return TRUE; } } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php index b8213ca..070dd25 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php @@ -12,6 +12,7 @@ use Drupal\Core\Plugin\Discovery\CacheDecorator; use Drupal\Core\Plugin\Discovery\AlterDecorator; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; +use Drupal\Core\Entity\Field\FieldInterface; /** * Plugin type manager for field widgets. @@ -176,4 +177,42 @@ public function getDefaultSettings($type) { return isset($info['settings']) ? $info['settings'] : array(); } + /** + * @todo Document. + */ + public function baseFieldForm(FieldInterface $field, array &$form, array &$form_state, $langcode) { + $options = array( + 'field_definition' => $field->getFieldDefinition(), + 'form_mode' => 'default', + 'configuration' => array(), + ); + $widget = $this->getInstance($options); + + $entity = $field->getParent()->getBCEntity(); + $items = $field->getValue(); + + $form += array('#parents' => array()); + $result = $widget->form($entity, $langcode, $items, $form, $form_state); + $field_name = $field->getName(); + return isset($result[$field_name]) ? $result[$field_name] : array(); + } + + /** + * @todo Document. + */ + public function baseFieldExtractFormValues(FieldInterface $field, array &$form, array &$form_state, $langcode) { + $options = array( + 'field_definition' => $field->getFieldDefinition(), + 'form_mode' => 'default', + 'configuration' => array(), + ); + $widget = $this->getInstance($options); + + $entity = $field->getParent()->getBCEntity(); + $items = $field->getValue(); + + $widget->extractFormValues($entity, $langcode, $items, $form, $form_state); + $field->setValue($items); + } + } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index 965c44d..9597264 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -137,9 +137,11 @@ function updateFileField($name, $type_name, $instance_settings = array(), $widge * Uploads a file to a node. */ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, $extras = array()) { + // @todo Reconcile difference between title and field language handling. $langcode = Language::LANGCODE_NOT_SPECIFIED; + $langcode2 = language_default()->langcode; $edit = array( - "title" => $this->randomName(), + "title[$langcode2][0][value]" => $this->randomName(), 'revision' => (string) (int) $new_revision, ); diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php index 35af5e1..b155da8 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php @@ -224,13 +224,15 @@ function testFilterAdmin() { $edit = array(); $langcode = Language::LANGCODE_NOT_SPECIFIED; - $edit["title"] = $this->randomName(); + $langcode2 = language_default()->langcode; + $title = $this->randomName(); + $edit["title[$langcode2][0][value]"] = $title; $edit["body[$langcode][0][value]"] = $text; $edit["body[$langcode][0][format]"] = $basic; $this->drupalPost('node/add/page', $edit, t('Save')); - $this->assertRaw(t('Basic page %title has been created.', array('%title' => $edit["title"])), 'Filtered node created.'); + $this->assertRaw(t('Basic page %title has been created.', array('%title' => $title)), 'Filtered node created.'); - $node = $this->drupalGetNodeByTitle($edit["title"]); + $node = $this->drupalGetNodeByTitle($title); $this->assertTrue($node, 'Node found in database.'); $this->drupalGet('node/' . $node->nid); diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 2c362b6..5a28f34 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -114,8 +114,9 @@ public function form(array $form, array &$form_state) { '#required' => TRUE, '#default_value' => $node->title, '#maxlength' => 255, - '#weight' => -5, ); + $form['title'] = \Drupal::service('plugin.manager.field.widget')->baseFieldForm($node->getNGEntity()->title, $form, $form_state, $this->getFormLangcode($form_state)); + $form['title']['#weight'] = -5; } $language_configuration = module_invoke('language', 'get_default_configuration', 'node', $node->type); @@ -329,6 +330,15 @@ protected function actions(array $form, array &$form_state) { } /** + * {@inheritdoc} + */ + public function buildEntity(array $form, array &$form_state) { + $node = parent::buildEntity($form, $form_state); + \Drupal::service('plugin.manager.field.widget')->baseFieldExtractFormValues($node->getNGEntity()->title, $form, $form_state, $this->getFormLangcode($form_state)); + return $node; + } + + /** * Overrides Drupal\Core\Entity\EntityFormController::validate(). */ public function validate(array $form, array &$form_state) { diff --git a/core/modules/node/lib/Drupal/node/NodeStorageController.php b/core/modules/node/lib/Drupal/node/NodeStorageController.php index 524036b..32245ad 100644 --- a/core/modules/node/lib/Drupal/node/NodeStorageController.php +++ b/core/modules/node/lib/Drupal/node/NodeStorageController.php @@ -154,7 +154,8 @@ public function baseFieldDefinitions() { $properties['title'] = array( 'label' => t('Title'), 'description' => t('The title of this node, always treated as non-markup plain text.'), - 'type' => 'string_field', + 'type' => 'field_item:text', + 'required' => TRUE, ); $properties['uid'] = array( 'label' => t('User ID'), diff --git a/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php b/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php index 31d515f..6ee7d48 100644 --- a/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php @@ -14,7 +14,7 @@ */ class NodeConditionTest extends DrupalUnitTestBase { - public static $modules = array('system', 'node', 'field'); + public static $modules = array('system', 'node', 'field', 'text'); public static function getInfo() { return array( diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTitleTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTitleTest.php index e03e4b0..0deff22 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTitleTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTitleTest.php @@ -59,7 +59,7 @@ function testNodeTitle() { $this->assertEqual(current($this->xpath($xpath)), $node->label(), 'Node breadcrumb is equal to node title.', 'Node'); // Test node title in comment preview. - $this->assertEqual(current($this->xpath('//article[@id=:id]/h2/a', array(':id' => 'node-' . $node->nid))), $node->label(), 'Node preview title is equal to node title.', 'Node'); + $this->assertEqual(current($this->xpath('//article[@id=:id]/h2/a/span', array(':id' => 'node-' . $node->nid))), $node->label(), 'Node preview title is equal to node title.', 'Node'); // Test node title is clickable on teaser list (/node). $this->drupalGet('node'); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index d9a365d..8d15206 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -746,7 +746,7 @@ function template_preprocess_node(&$variables) { $uri = $node->uri(); $variables['node_url'] = url($uri['path'], $uri['options']); - $variables['label'] = check_plain($node->label()); + $variables['label'] = Drupal::service('plugin.manager.field.formatter')->viewBaseField($node->getNGEntity()->title); $variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node); // Helpful $content variable for templates. diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 526ef66..bb29703 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -315,7 +315,7 @@ function rdf_preprocess_node(&$variables) { $element = array( '#tag' => 'meta', '#attributes' => array( - 'content' => $variables['label'], + 'content' => $variables['node']->label(), 'about' => $variables['node_url'], ), ); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 8e295b3..1ca7dbe 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -2048,7 +2048,7 @@ protected function assertNoLinkByHref($href, $message = '', $group = 'Other') { */ protected function clickLink($label, $index = 0) { $url_before = $this->getUrl(); - $urls = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => $label)); + $urls = $this->xpath('//a[normalize-space()=:label]', array(':label' => $label)); if (isset($urls[$index])) { $url_target = $this->getAbsoluteUrl($urls[$index]['href']); diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php index b04e2d8..cb8ec55 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php @@ -17,7 +17,7 @@ */ class ContextPluginTest extends DrupalUnitTestBase { - public static $modules = array('system', 'user', 'node'); + public static $modules = array('system', 'user', 'node', 'text'); public static function getInfo() { return array( diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php index 26326fc..1c79cf7 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php @@ -63,6 +63,27 @@ public static function schema(Field $field) { /** * {@inheritdoc} */ + public function getConstraints() { + $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); + $constraints = parent::getConstraints(); + + if ($max_length = $this->getFieldDefinition()->getFieldSetting('max_length')) { + $constraints[] = $constraint_manager->create('ComplexData', array( + 'value' => array( + 'Length' => array( + 'max' => $max_length, + 'maxMessage' => t('%name: the text may not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getFieldLabel(), '@max' => $max_length)), + ) + ), + )); + } + + return $constraints; + } + + /** + * {@inheritdoc} + */ public function settingsForm(array $form, array &$form_state) { $element = array(); $field = $this->getInstance()->getField(); diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php index 17f2ba3..e16f961 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php @@ -70,38 +70,17 @@ public function isEmpty() { /** * {@inheritdoc} */ - public function getConstraints() { - $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); - $constraints = parent::getConstraints(); - - if (!empty($this->getInstance()->getField()->settings['max_length'])) { - $max_length = $this->getInstance()->getField()->settings['max_length']; - $constraints[] = $constraint_manager->create('ComplexData', array( - 'value' => array( - 'Length' => array( - 'max' => $max_length, - 'maxMessage' => t('%name: the text may not be longer than @max characters.', array('%name' => $this->getInstance()->label, '@max' => $max_length)), - ) - ), - )); - } - - return $constraints; - } - - /** - * {@inheritdoc} - */ public function prepareCache() { // Where possible, generate the sanitized version of each field early so // that it is cached in the field cache. This avoids the need to look up the // field in the filter cache separately. - if (!$this->getInstance()->settings['text_processing'] || filter_format_allowcache($this->get('format')->getValue())) { + $text_processing = $this->getFieldDefinition()->getFieldSetting('text_processing'); + if (!$text_processing || filter_format_allowcache($this->get('format')->getValue())) { $itemBC = $this->getValue(); $langcode = $this->getParent()->getParent()->language()->langcode; - $this->set('safe_value', text_sanitize($this->getInstance()->settings['text_processing'], $langcode, $itemBC, 'value')); + $this->set('safe_value', text_sanitize($text_processing, $langcode, $itemBC, 'value')); if ($this->getType() == 'field_item:text_with_summary') { - $this->set('safe_summary', text_sanitize($this->getInstance()->settings['text_processing'], $langcode, $itemBC, 'summary')); + $this->set('safe_summary', text_sanitize($text_processing, $langcode, $itemBC, 'summary')); } } } diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextWithSummaryItem.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextWithSummaryItem.php index 4d9030d..7aecf67 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextWithSummaryItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextWithSummaryItem.php @@ -106,28 +106,6 @@ public function isEmpty() { /** * {@inheritdoc} */ - public function getConstraints() { - $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); - $constraints = parent::getConstraints(); - - if (!empty($this->getInstance()->getField()->settings['max_length'])) { - $max_length = $this->getInstance()->getField()->settings['max_length']; - $constraints[] = $constraint_manager->create('ComplexData', array( - 'summary' => array( - 'Length' => array( - 'max' => $max_length, - 'maxMessage' => t('%name: the summary may not be longer than @max characters.', array('%name' => $this->getInstance()->label, '@max' => $max_length)), - ) - ), - )); - } - - return $constraints; - } - - /** - * {@inheritdoc} - */ public function instanceSettingsForm(array $form, array &$form_state) { $element = array();