You are here

Checkboxes.php in YAML Form 8

File

src/Plugin/YamlFormElement/Checkboxes.php
View source
<?php

namespace Drupal\yamlform\Plugin\YamlFormElement;

use Drupal\yamlform\YamlFormSubmissionInterface;

/**
 * Provides a 'checkboxes' element.
 *
 * @YamlFormElement(
 *   id = "checkboxes",
 *   api = "https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!Checkboxes.php/class/Checkboxes",
 *   label = @Translation("Checkboxes"),
 *   category = @Translation("Options elements"),
 *   multiple = TRUE,
 * )
 */
class Checkboxes extends OptionsBase {

  /**
   * {@inheritdoc}
   */
  public function getDefaultProperties() {
    return parent::getDefaultProperties() + [
      // Options settings.
      'options_display' => 'one_column',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
    parent::prepare($element, $yamlform_submission);
    $element['#element_validate'][] = [
      get_class($this),
      'validateMultipleOptions',
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function getElementSelectorInputsOptions(array $element) {
    $selectors = $element['#options'];
    foreach ($selectors as &$text) {
      $text .= ' [' . $this
        ->t('Checkbox') . ']';
    }
    return $selectors;
  }

}

Classes

Namesort descending Description
Checkboxes Provides a 'checkboxes' element.