| Server IP : 195.130.67.5 / Your IP : 216.73.217.154 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Old Sites/enoikio/modules/webform/src/Element/ |
Upload File : |
<?php
namespace Drupal\webform\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\Checkboxes;
/**
* Provides a webform element for term checkboxes.
*
* @FormElement("webform_term_checkboxes")
*/
class WebformTermCheckboxes extends Checkboxes {
use WebformTermReferenceTrait;
/**
* {@inheritdoc}
*/
public function getInfo() {
return [
'#vocabulary' => '',
'#tree_delimiter' => ' ',
'#breadcrumb' => FALSE,
'#breadcrumb_delimiter' => ' › ',
'#scroll' => TRUE,
] + parent::getInfo();
}
/**
* {@inheritdoc}
*/
public static function processCheckboxes(&$element, FormStateInterface $form_state, &$complete_form) {
static::setOptions($element);
$element = parent::processCheckboxes($element, $form_state, $complete_form);
if (!\Drupal::moduleHandler()->moduleExists('taxonomy')) {
return $element;
}
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
$tree = static::loadTree($element['#vocabulary']);
if (empty($element['#breadcrumb'])) {
foreach ($tree as $item) {
$item = $entity_repository->getTranslationFromContext($item);
$element[$item->id()]['#title'] = $item->label();
$element[$item->id()]['#field_prefix'] = str_repeat($element['#tree_delimiter'], $item->depth);
}
}
$element['#attributes']['class'][] = 'js-webform-term-checkboxes';
$element['#attributes']['class'][] = 'webform-term-checkboxes';
if (!empty($element['#scroll'])) {
$element['#attributes']['class'][] = 'webform-term-checkboxes-scroll';
}
$element['#attached']['library'][] = 'webform/webform.element.term_checkboxes';
return $element;
}
/**
* {@inheritdoc}
*/
protected static function getOptionsTree(array $element, $language) {
$element += ['#tree_delimiter' => '-'];
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
$tree = static::loadTree($element['#vocabulary']);
$options = [];
foreach ($tree as $item) {
// Set the item in the correct language for display.
$item = $entity_repository->getTranslationFromContext($item);
if (!$item->access('view')) {
continue;
}
$options[$item->id()] = $item->getName();
}
return $options;
}
}