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/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..dfca5eb 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,48 @@ 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(), + ); + if (($field_data_definition = $field->getDefinition()) && isset($field_data_definition['default_widget'])) { + $options['configuration']['type'] = $field_data_definition['default_widget']; + } + $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(), + ); + if (($field_data_definition = $field->getDefinition()) && isset($field_data_definition['default_widget'])) { + $options['configuration']['type'] = $field_data_definition['default_widget']; + } + $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/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 2c362b6..6cf82f9 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -108,14 +108,8 @@ public function form(array $form, array &$form_state) { $node_type = node_type_load($node->type); if ($node_type->has_title) { - $form['title'] = array( - '#type' => 'textfield', - '#title' => check_plain($node_type->title_label), - '#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 +323,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..91b4e35 100644 --- a/core/modules/node/lib/Drupal/node/NodeStorageController.php +++ b/core/modules/node/lib/Drupal/node/NodeStorageController.php @@ -154,7 +154,9 @@ 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, + 'default_widget' => 'node_title', ); $properties['uid'] = array( 'label' => t('User ID'), diff --git a/core/modules/node/lib/Drupal/node/Plugin/field/widget/TitleWidget.php b/core/modules/node/lib/Drupal/node/Plugin/field/widget/TitleWidget.php new file mode 100644 index 0000000..2b0b8e3 --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Plugin/field/widget/TitleWidget.php @@ -0,0 +1,67 @@ +fieldDefinition->getFieldName(); + $addition[$field_name] = array( + '#type' => 'textfield', + '#title' => check_plain($this->fieldDefinition->getFieldLabel()), + '#required' => $this->fieldDefinition->isFieldRequired(), + '#default_value' => isset($items[0]['value']) ? $items[0]['value'] : '', + '#maxlength' => $this->fieldDefinition->getFieldSetting('max_length'), + ); + return $addition; + } + + /** + * {@inheritdoc} + */ + public function extractFormValues(EntityInterface $entity, $langcode, array &$items, array $form, array &$form_state) { + $field_name = $this->fieldDefinition->getFieldName(); + + // Extract the values from $form_state['values']. + $path = array_merge($form['#parents'], array($field_name)); + $key_exists = NULL; + $value = NestedArray::getValue($form_state['values'], $path, $key_exists); + + if ($key_exists) { + $items = array(array('value' => $value)); + } + } + + /** + * {@inheritdoc} + */ + public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + return array(); + } +} 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();