You are here

public function Color::prepare in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/Color.php \Drupal\webform\Plugin\WebformElement\Color::prepare()

Prepare an element to be rendered within a webform.

Parameters

array $element: An element.

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission. Webform submission is optional since it is not used by composite sub elements.

Overrides WebformElementBase::prepare

See also

\Drupal\webform\Element\WebformCompositeBase::processWebformComposite

File

src/Plugin/WebformElement/Color.php, line 44

Class

Color
Provides a 'color' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function prepare(array &$element, WebformSubmissionInterface $webform_submission = NULL) {
  parent::prepare($element, $webform_submission);

  // Set the color swatches size.
  $color_size = isset($element['#color_size']) ? $element['#color_size'] : 'medium';
  $element['#attributes']['class'][] = 'form-color-' . $color_size;

  // Add helpful attributes to better support older browsers.
  // @see http://www.wufoo.com/html5/types/6-color.html
  $element['#attributes'] += [
    'title' => $this
      ->t('Hexadecimal color'),
    'pattern' => '#[a-f0-9]{6}',
    'placeholder' => '#000000',
  ];
  $element['#attached']['library'][] = 'webform/webform.element.color';
}