X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fphp%2Fsrc%2FPlugin%2FCondition%2FPhp.php;fp=web%2Fmodules%2Fcontrib%2Fphp%2Fsrc%2FPlugin%2FCondition%2FPhp.php;h=ca13a5aa491f3176a35eb60db5a09ba3e340ac08;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/php/src/Plugin/Condition/Php.php b/web/modules/contrib/php/src/Plugin/Condition/Php.php new file mode 100644 index 000000000..ca13a5aa4 --- /dev/null +++ b/web/modules/contrib/php/src/Plugin/Condition/Php.php @@ -0,0 +1,75 @@ + ''] + parent::defaultConfiguration(); + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + $form['php'] = [ + '#type' => 'textarea', + '#title' => $this->t('When the following PHP return TRUE (experts only)'), + '#default_value' => $this->configuration['php'], + '#description' => $this->t('Enter PHP code between <?php ?>. Note that executing incorrect PHP code can break your Drupal site. Return TRUE in order for this condition to evaluate as TRUE.'), + '#access' => \Drupal::currentUser()->hasPermission('use PHP for settings') + ]; + + return parent::buildConfigurationForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + $this->configuration['php'] = $form_state->getValue('php'); + parent::submitConfigurationForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function summary() { + if (!empty($this->configuration['php'])) { + return t('When the given PHP evaluates as @state.', ['@state' => !empty($this->configuration['negate']) ? 'FALSE' : 'TRUE']); + } + else { + return t('No PHP code has been provided.'); + } + } + + /** + * {@inheritdoc} + */ + public function evaluate() { + return php_eval($this->configuration['php']); + } + +}