Loading select_icons.module +3 −3 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ use Drupal\Core\Render\Element; /** * Implements hook_theme(). */ function select_icons_theme($existing, $type, $theme, $path) { function select_icons_theme(): array { return [ 'select_icons' => [ 'render element' => 'element', Loading @@ -36,7 +36,7 @@ function select_icons_theme($existing, $type, $theme, $path) { * Properties used: #title, #value, #options, #description, #extra, * #multiple, #required, #name, #attributes, #size. */ function template_preprocess_select_icons(array &$variables) { function template_preprocess_select_icons(array &$variables): void { $element = $variables['element']; Element::setAttributes($element, ['id', 'name', 'size']); RenderElement::setAttributes($element, ['form-select']); Loading @@ -54,7 +54,7 @@ function template_preprocess_select_icons(array &$variables) { /** * Implements hook_library_info_alter(). */ function select_icons_library_info_alter(&$libraries, $extension) { function select_icons_library_info_alter(array &$libraries, string $extension): void { // Remove jQuery UI theme to avoid side effect on non-select icons fields. if ($extension == 'core' && isset($libraries['jquery.ui'])) { unset($libraries['jquery.ui']['css']['theme']['assets/vendor/jquery.ui/themes/base/theme.css']); Loading src/Element/SelectIcons.php +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ class SelectIcons extends Select { /** * {@inheritdoc} */ public function getInfo() { public function getInfo(): array { $info = parent::getInfo(); // We need to override theme function. Loading templates/select-icons.html.twig +1 −1 Original line number Diff line number Diff line {# /** * @file * Default theme implementation for a select element dedicated for use with jQuery UI. * Default theme implementation for a select icons element. * * Available variables: * - attributes: HTML attributes for the select tag. Loading tests/modules/select_icons_test/src/Form/SelectIconsFormElementTestForm.php +3 −3 Original line number Diff line number Diff line Loading @@ -17,14 +17,14 @@ class SelectIconsFormElementTestForm extends FormBase { /** * {@inheritdoc} */ public function getFormId() { public function getFormId(): string { return 'select_icons_form_element_test_form'; } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state): array { $form['select_icons_select'] = [ '#type' => 'select_icons', '#attributes' => ['id' => 'select-icons-test-element'], Loading @@ -46,7 +46,7 @@ class SelectIconsFormElementTestForm extends FormBase { /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state): void { $form_state->setResponse(new JsonResponse($form_state->getValues())); } Loading tests/src/FunctionalJavascript/SelectIconsElementIntegrationTest.php +8 −23 Original line number Diff line number Diff line Loading @@ -16,18 +16,15 @@ class SelectIconsElementIntegrationTest extends WebDriverTestBase { /** * {@inheritdoc} */ public static $modules = [ 'select_icons', 'select_icons_test', ]; protected $defaultTheme = 'seven'; /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); $this->enableTheme('seven'); } public static $modules = [ 'select_icons', 'select_icons_test', ]; /** * Test select icons element. Loading @@ -38,33 +35,21 @@ class SelectIconsElementIntegrationTest extends WebDriverTestBase { $page = $this->getSession()->getPage(); // Check if selecticons select is hidden. /** @var \Behat\Mink\Element\NodeElement $selecticons_select */ $selecticons_select = $page->find('css', 'select#select-icons-test-element'); $this->assertFalse($selecticons_select->isVisible(), 'Selectmenu select is hidden.'); // Check if selecticons select has options with data attribute. /** @var \Behat\Mink\Element\NodeElement $option_red */ $option_red = $page->find('css', 'select#select-icons-test-element option[value="r"]'); $this->assertEquals('colour red', $option_red->getAttribute('data-class')); // Check if selectmenu is opened. /** @var \Behat\Mink\Element\NodeElement $selecticons_widget */ $selecticons_widget = $page->find('css', '.js-form-type-select-icons .ui-selectmenu-button'); $selecticons_widget->click(); // $this->createScreenshot('public://test_screenshot.jpg'); $selecticons_widget->find('css', 'ui-selectmenu-open'); $this->assertTrue($selecticons_widget->isVisible(), 'Selectmenu is visible.'); } /** * Enables a theme. * * @param string $theme * The theme. */ public function enableTheme($theme) { // Enable the theme. \Drupal::service('theme_installer')->install([$theme]); $theme_config = \Drupal::configFactory()->getEditable('system.theme'); $theme_config->set('default', $theme); $theme_config->save(); } } Loading
select_icons.module +3 −3 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ use Drupal\Core\Render\Element; /** * Implements hook_theme(). */ function select_icons_theme($existing, $type, $theme, $path) { function select_icons_theme(): array { return [ 'select_icons' => [ 'render element' => 'element', Loading @@ -36,7 +36,7 @@ function select_icons_theme($existing, $type, $theme, $path) { * Properties used: #title, #value, #options, #description, #extra, * #multiple, #required, #name, #attributes, #size. */ function template_preprocess_select_icons(array &$variables) { function template_preprocess_select_icons(array &$variables): void { $element = $variables['element']; Element::setAttributes($element, ['id', 'name', 'size']); RenderElement::setAttributes($element, ['form-select']); Loading @@ -54,7 +54,7 @@ function template_preprocess_select_icons(array &$variables) { /** * Implements hook_library_info_alter(). */ function select_icons_library_info_alter(&$libraries, $extension) { function select_icons_library_info_alter(array &$libraries, string $extension): void { // Remove jQuery UI theme to avoid side effect on non-select icons fields. if ($extension == 'core' && isset($libraries['jquery.ui'])) { unset($libraries['jquery.ui']['css']['theme']['assets/vendor/jquery.ui/themes/base/theme.css']); Loading
src/Element/SelectIcons.php +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ class SelectIcons extends Select { /** * {@inheritdoc} */ public function getInfo() { public function getInfo(): array { $info = parent::getInfo(); // We need to override theme function. Loading
templates/select-icons.html.twig +1 −1 Original line number Diff line number Diff line {# /** * @file * Default theme implementation for a select element dedicated for use with jQuery UI. * Default theme implementation for a select icons element. * * Available variables: * - attributes: HTML attributes for the select tag. Loading
tests/modules/select_icons_test/src/Form/SelectIconsFormElementTestForm.php +3 −3 Original line number Diff line number Diff line Loading @@ -17,14 +17,14 @@ class SelectIconsFormElementTestForm extends FormBase { /** * {@inheritdoc} */ public function getFormId() { public function getFormId(): string { return 'select_icons_form_element_test_form'; } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state): array { $form['select_icons_select'] = [ '#type' => 'select_icons', '#attributes' => ['id' => 'select-icons-test-element'], Loading @@ -46,7 +46,7 @@ class SelectIconsFormElementTestForm extends FormBase { /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state): void { $form_state->setResponse(new JsonResponse($form_state->getValues())); } Loading
tests/src/FunctionalJavascript/SelectIconsElementIntegrationTest.php +8 −23 Original line number Diff line number Diff line Loading @@ -16,18 +16,15 @@ class SelectIconsElementIntegrationTest extends WebDriverTestBase { /** * {@inheritdoc} */ public static $modules = [ 'select_icons', 'select_icons_test', ]; protected $defaultTheme = 'seven'; /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); $this->enableTheme('seven'); } public static $modules = [ 'select_icons', 'select_icons_test', ]; /** * Test select icons element. Loading @@ -38,33 +35,21 @@ class SelectIconsElementIntegrationTest extends WebDriverTestBase { $page = $this->getSession()->getPage(); // Check if selecticons select is hidden. /** @var \Behat\Mink\Element\NodeElement $selecticons_select */ $selecticons_select = $page->find('css', 'select#select-icons-test-element'); $this->assertFalse($selecticons_select->isVisible(), 'Selectmenu select is hidden.'); // Check if selecticons select has options with data attribute. /** @var \Behat\Mink\Element\NodeElement $option_red */ $option_red = $page->find('css', 'select#select-icons-test-element option[value="r"]'); $this->assertEquals('colour red', $option_red->getAttribute('data-class')); // Check if selectmenu is opened. /** @var \Behat\Mink\Element\NodeElement $selecticons_widget */ $selecticons_widget = $page->find('css', '.js-form-type-select-icons .ui-selectmenu-button'); $selecticons_widget->click(); // $this->createScreenshot('public://test_screenshot.jpg'); $selecticons_widget->find('css', 'ui-selectmenu-open'); $this->assertTrue($selecticons_widget->isVisible(), 'Selectmenu is visible.'); } /** * Enables a theme. * * @param string $theme * The theme. */ public function enableTheme($theme) { // Enable the theme. \Drupal::service('theme_installer')->install([$theme]); $theme_config = \Drupal::configFactory()->getEditable('system.theme'); $theme_config->set('default', $theme); $theme_config->save(); } }