You are here

YamlFormCheckboxesOther.php in YAML Form 8

File

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

namespace Drupal\yamlform\Plugin\YamlFormElement;

use Drupal\yamlform\YamlFormSubmissionInterface;

/**
 * Provides a 'checkboxes_other' element.
 *
 * @YamlFormElement(
 *   id = "yamlform_checkboxes_other",
 *   label = @Translation("Checkboxes other"),
 *   category = @Translation("Options elements"),
 *   multiple = TRUE,
 * )
 */
class YamlFormCheckboxesOther extends Checkboxes {

  /**
   * {@inheritdoc}
   */
  public function getDefaultProperties() {
    return parent::getDefaultProperties() + self::getOtherProperties();
  }

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

  /**
   * {@inheritdoc}
   */
  public function getElementSelectorOptions(array $element) {
    $title = $this
      ->getAdminLabel($element);
    $name = $element['#yamlform_key'];
    $selectors = [];
    foreach ($element['#options'] as $input_name => $input_title) {
      $selectors[":input[name=\"{$name}[checkboxes][{$input_name}]\"]"] = $input_title . ' [' . $this
        ->t('Checkboxes') . ']';
    }
    $selectors[":input[name=\"{$name}[other]\"]"] = $title . ' [' . $this
      ->t('Textfield') . ']';
    return [
      $title => $selectors,
    ];
  }

}

Classes

Namesort descending Description
YamlFormCheckboxesOther Provides a 'checkboxes_other' element.