Add a condition plugin for domain name

Created on 28 July 2017, over 7 years ago
Updated 14 November 2024, 3 months ago

Hi,

On a project I'm working on we needed a plugin condition for the domain name and a colleague suggested it might be suitable for ctools.

Thanks

Feature request
Status

Closed: works as designed

Version

3.0

Component

Code

Created by

🇬🇧United Kingdom AndyF

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇪Belgium sfcamil

    THX,
    Working well for me with just two small modifications:
    validateConfigurationForm it's not called for me (why?) so I moved the code (Store the trimmed domains as an array) in submitConfigurationForm:

     public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
        // Store the trimmed domains as an array.
          $domains = explode(PHP_EOL, $form_state->getValue('domains'));
          $form_state->setValue('domains', array_filter(array_map('trim', $domains)));
    
        $this->configuration['domains'] = $form_state->getValue('domains');
        parent::submitConfigurationForm($form, $form_state);
      }

    Changed in evaluate (mb_strtolower)

          $host = mb_strtolower($this->requestStack->getCurrentRequest()->getHost());
          return in_array($host, array_map('mb_strtolower', $domains));
Production build 0.71.5 2024