diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php index a72557a..951ed03 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php @@ -147,7 +147,9 @@ public function instanceSettingsForm(array $form, array &$form_state) { } /** - * Returns options provided via hook_options_list(). + * Returns options provided via the legacy callback hook_options_list(). + * + * @todo: Convert all legacy callback implementations to methods. * * @see \Drupal\Core\TypedData\AllowedValuesInterface */ 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..5f46930 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 @@ -375,7 +375,9 @@ public function flagErrors(EntityInterface $entity, $langcode, array $items, arr foreach ($delta_violations as $violation) { // @todo: Pass $violation->arrayPropertyPath as property path. $error_element = $this->errorElement($delta_element, $violation, $form, $form_state); - form_error($error_element, $violation->getMessage()); + if ($error_element !== FALSE) { + form_error($error_element, $violation->getMessage()); + } } } // Reinitialize the errors list for the next submit. diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php index fbc939c..1866415 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php @@ -125,18 +125,19 @@ public function formElement(array $items, $delta, array $element, $langcode, arr * @param array $element * An array containing the form element for the widget, as generated by * formElement(). - * @param \Symfony\Component\Validator\ConstraintViolationInterface $violations - * The list of constraint violations reported during the validation phase. + * @param \Symfony\Component\Validator\ConstraintViolationInterface $violation + * A constraint violation reported during the validation phase. * @param array $form * The form structure where field elements are attached to. This might be a * full form structure, or a sub-element of a larger form. * @param array $form_state * An associative array containing the current state of the form. * - * @return array - * The element on which the error should be flagged. + * @return array|false + * The element on which the error should be flagged, or FALSE to completely + * ignore the violation (use with care!). */ - public function errorElement(array $element, ConstraintViolationInterface $violations, array $form, array &$form_state); + public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, array &$form_state); /** * Massages the form values into the format expected for field values. diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php index 7e0596a..1af9d4e 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php @@ -107,7 +107,9 @@ public function prepareCache() { } /** - * Returns options provided via hook_options_list(). + * Returns options provided via the legacy callback hook_options_list(). + * + * @todo: Convert all legacy callback implementations to methods. * * @see \Drupal\Core\TypedData\AllowedValuesInterface */ diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index e2d0c55..1a7c8a6 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -118,19 +118,6 @@ function filter_element_info() { } /** - * Implements hook_data_type_info(). - */ -function filter_data_type_info() { - return array( - 'filter_format' => array( - 'label' => t('Filter format'), - 'class' => 'Drupal\filter\Type\FilterFormat', - 'primitive type' => Primitive::STRING, - ), - ); -} - -/** * Implements hook_menu(). */ function filter_menu() { diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/DataType/FilterFormat.php b/core/modules/filter/lib/Drupal/filter/Plugin/DataType/FilterFormat.php index c8ff730..bb4b567 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/DataType/FilterFormat.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/DataType/FilterFormat.php @@ -17,8 +17,7 @@ * * @DataType( * id = "filter_format", - * label = @Translation("Filter format"), - * primitive_type = 2 + * label = @Translation("Filter format") * ) */ class FilterFormat extends String implements AllowedValuesInterface { diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php index 08dabf1..afa0615 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php @@ -8,7 +8,7 @@ namespace Drupal\filter\Tests; use Drupal\Core\TypedData\AllowedValuesInterface; -use Drupal\filter\Type\FilterFormat; +use Drupal\filter\Plugin\DataType\FilterFormat; use Drupal\system\Tests\Entity\EntityUnitTestBase; use Symfony\Component\Validator\ConstraintViolationListInterface; diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWidget.php b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWidget.php index 72eff19..6c11da3 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWidget.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWidget.php @@ -10,6 +10,7 @@ use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; use Drupal\field\Plugin\Type\Widget\WidgetBase; +use Symfony\Component\Validator\ConstraintViolationInterface; /** * Plugin implementation of the 'text_textarea' widget. @@ -89,4 +90,15 @@ public function formElement(array $items, $delta, array $element, $langcode, arr return $element; } + /** + * {@inheritdoc} + */ + public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, array &$form_state) { + if ($violation->arrayPropertyPath == array('format') && isset($element['format']['#access']) && !$element['format']['#access']) { + // Ignore validation errors for formats if formats may not be changed, + // i.e. when existing formats become invalid. See filter_process_format(). + return FALSE; + } + return $element; + } } diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWithSummaryWidget.php b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWithSummaryWidget.php index 300af18..185ee19 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWithSummaryWidget.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWithSummaryWidget.php @@ -85,6 +85,11 @@ function formElement(array $items, $delta, array $element, $langcode, array &$fo * {@inheritdoc} */ public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, array &$form_state) { + if ($violation->arrayPropertyPath == array('format') && isset($element['format']['#access']) && !$element['format']['#access']) { + // Ignore validation errors for formats if formats may not be changed, + // i.e. when existing formats become invalid. See filter_process_format(). + return FALSE; + } return $element[$violation->arrayPropertyPath[0]]; } diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php index 5319aab..07e7542 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php @@ -10,6 +10,7 @@ use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; use Drupal\field\Plugin\Type\Widget\WidgetBase; +use Symfony\Component\Validator\ConstraintViolationInterface; /** * Plugin implementation of the 'text_textfield' widget. @@ -90,4 +91,16 @@ public function formElement(array $items, $delta, array $element, $langcode, arr return $element; } + /** + * {@inheritdoc} + */ + public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, array &$form_state) { + if ($violation->arrayPropertyPath == array('format') && isset($element['format']['#access']) && !$element['format']['#access']) { + // Ignore validation errors for formats if formats may not be changed, + // i.e. when existing formats become invalid. See filter_process_format(). + return FALSE; + } + return $element; + } + }