You are here

public static function IframeWidgetBase::validateWidth in Iframe 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/IframeWidgetBase.php \Drupal\iframe\Plugin\Field\FieldWidget\IframeWidgetBase::validateWidth()

Validate width(if minimum url is defined)

See also

\Drupal\Core\Form\FormValidator

File

src/Plugin/Field/FieldWidget/IframeWidgetBase.php, line 290

Class

IframeWidgetBase
Plugin implementation base functions.

Namespace

Drupal\iframe\Plugin\Field\FieldWidget

Code

public static function validateWidth(&$form, FormStateInterface &$form_state) {
  $parents = $form['#parents'];
  $itemfield = $parents[0];
  $iteminst = $parents[1];

  /*
   * $value = $form['#value'];
   * $itemname = $parents[2];
   * $itemid = $form['#id'];
   */
  $node = $form_state
    ->getUserInput();
  $me = $node[$itemfield][$iteminst];

  // \iframe_debug(0, 'validateWidth', $me);
  if (!empty($me['url']) && isset($me['width'])) {
    if (empty($me['width']) || !preg_match('#^(\\d+\\%?|auto)$#', $me['width'])) {
      $form_state
        ->setError($form, self::getSizedescription());
    }
  }
}