| 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 roles (checkboxes) element.
*
* @FormElement("webform_roles")
*/
class WebformRoles extends Checkboxes {
/**
* {@inheritdoc}
*/
public function getInfo() {
$info = parent::getInfo();
$class = get_class($this);
$info['#element_validate'] = [
[$class, 'validateWebformRoles'],
];
$info['#include_anonymous'] = TRUE;
return $info;
}
/**
* Processes a webform roles (checkboxes) element.
*/
public static function processCheckboxes(&$element, FormStateInterface $form_state, &$complete_form) {
$membersonly = (empty($element['#include_anonymous'])) ? TRUE : FALSE;
$element['#options'] = array_map('\Drupal\Component\Utility\Html::escape', user_role_names($membersonly));
$element['#attached']['library'][] = 'webform/webform.element.roles';
$element['#attributes']['class'][] = 'js-webform-roles-role';
return parent::processCheckboxes($element, $form_state, $complete_form);
}
/**
* Webform element validation handler for webform roles (checkboxes) element.
*/
public static function validateWebformRoles(&$element, FormStateInterface $form_state, &$complete_form) {
$value = $form_state->getValue($element['#parents'], []);
$value = array_values(array_filter($value));
$element['#value'] = $value;
$form_state->setValueForElement($element, $value);
}
}