public function Color::prepare in YAML Form 8
Prepare an element to be rendered within a form.
Parameters
array $element: An element.
\Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission: A form submission.
Overrides YamlFormElementBase::prepare
File
- src/
Plugin/ YamlFormElement/ Color.php, line 34
Class
- Color
- Provides a 'color' element.
Namespace
Drupal\yamlform\Plugin\YamlFormElementCode
public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
parent::prepare($element, $yamlform_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'][] = 'yamlform/yamlform.element.color';
}