summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-03-13 15:21:59 (GMT)
committerAlex Pott2015-03-13 15:21:59 (GMT)
commit643f13652c87c04898d3dc9b1f714d013c9e8b2b (patch)
tree528329b7a72e7f952605ba8c7bda8799ab3e7e23
parentc0161655f9bfaaea6d0ba03649bd1c88dcabe6a6 (diff)
Issue #2076321 by yched, Mac_Weber, pcambra: Link "title" validation should use a static method
-rw-r--r--core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php28
1 files changed, 15 insertions, 13 deletions
diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
index f5a5353..c402f76 100644
--- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
+++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
@@ -133,6 +133,8 @@ class LinkWidget extends WidgetBase {
}
/**
+ * Form element validation handler for the 'uri' element.
+ *
* Disallows saving inaccessible or untrusted URLs.
*/
public static function validateUriElement($element, FormStateInterface $form_state, $form) {
@@ -150,6 +152,18 @@ class LinkWidget extends WidgetBase {
}
/**
+ * Form element validation handler for the 'title' element.
+ *
+ * Conditionally requires the link title if a URL value was filled in.
+ */
+ public static function validateTitleElement(&$element, FormStateInterface $form_state, $form) {
+ if ($element['uri']['#value'] !== '' && $element['title']['#value'] === '') {
+ $element['title']['#required'] = TRUE;
+ $form_state->setError($element['title'], t('!name field is required.', array('!name' => $element['title']['#title'])));
+ }
+ }
+
+ /**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
@@ -207,7 +221,7 @@ class LinkWidget extends WidgetBase {
// non-empty. Omit the validation on the field edit form, since the field
// settings cannot be saved otherwise.
if (!$this->isDefaultValueWidget($form_state) && $this->getFieldSetting('title') == DRUPAL_REQUIRED) {
- $element['#element_validate'][] = array($this, 'validateTitle');
+ $element['#element_validate'][] = array(get_called_class(), 'validateTitleElement');
}
// Exposing the attributes array in the widget is left for alternate and more
@@ -312,18 +326,6 @@ class LinkWidget extends WidgetBase {
}
/**
- * Form element validation handler; Validates the title property.
- *
- * Conditionally requires the link title if a URL value was filled in.
- */
- public function validateTitle(&$element, FormStateInterface $form_state, $form) {
- if ($element['uri']['#value'] !== '' && $element['title']['#value'] === '') {
- $element['title']['#required'] = TRUE;
- $form_state->setError($element['title'], $this->t('!name field is required.', array('!name' => $element['title']['#title'])));
- }
- }
-
- /**
* {@inheritdoc}
*/
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {