class Php

Provides a 'Php' condition.

Plugin annotation


@Plugin(
  id = "php",
  label = @Translation("PHP"),
  module = "php"
)

Hierarchy

Expanded class hierarchy of Php

File

drupal/core/modules/php/lib/Drupal/php/Plugin/Condition/Php.php, line 23
Contains \Drupal\php\Plugin\Condition\Php.

Namespace

Drupal\php\Plugin\Condition
View source
class Php extends ConditionPluginBase {

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, array &$form_state) {
    $form = parent::buildForm($form, $form_state);
    if (empty($this->configuration['php'])) {

      // Initialize an empty value.
      $this->configuration['php'] = FALSE;
    }
    $form['php'] = array(
      '#type' => 'textarea',
      '#title' => t('When the following PHP return TRUE (experts only)'),
      '#default_value' => $this->configuration['php'],
      '#description' => 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' => user_access('use PHP for settings'),
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, array &$form_state) {
    $this->configuration['php'] = $form_state['values']['php'];
    parent::submitForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function summary() {
    if (!empty($this->configuration['php'])) {
      return t('When the given PHP evaluates as @state.', array(
        '@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']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConditionPluginBase::execute public function Implements \Drupal\Core\Executable\ExecutablePluginBase::execute(). Overrides ExecutableInterface::execute
ConditionPluginBase::getFormID public function Implements \Drupal\Core\Form\FormInterface::getFormID(). Overrides FormInterface::getFormID
ConditionPluginBase::isNegated public function Implements \Drupal\condition\Plugin\ConditionInterface::isNegated(). Overrides ConditionInterface::isNegated
ConditionPluginBase::validateForm public function Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface::validateForm 1
ContextAwarePluginBase::$context protected property The data objects representing the context of this plugin.
ContextAwarePluginBase::getContext public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContext(). Overrides ContextAwarePluginInterface::getContext
ContextAwarePluginBase::getContextDefinition public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextDefinition(). Overrides ContextAwarePluginInterface::getContextDefinition
ContextAwarePluginBase::getContextDefinitions public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextDefinitions(). Overrides ContextAwarePluginInterface::getContextDefinitions
ContextAwarePluginBase::getContexts public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContexts(). Overrides ContextAwarePluginInterface::getContexts
ContextAwarePluginBase::getContextValue public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextValue(). Overrides ContextAwarePluginInterface::getContextValue
ContextAwarePluginBase::getContextValues public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextValues(). Overrides ContextAwarePluginInterface::getContextValues
ContextAwarePluginBase::setContextValue public function Override of \Drupal\Component\Plugin\ContextAwarePluginBase::setContextValue(). Overrides ContextAwarePluginBase::setContextValue
ContextAwarePluginBase::validateContexts public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::valdidateContexts(). Overrides ContextAwarePluginInterface::validateContexts
ContextAwarePluginBase::__construct public function Override of \Drupal\Component\Plugin\ContextAwarePluginBase::__construct(). Overrides ContextAwarePluginBase::__construct
ExecutablePluginBase::$executableManager protected property The condition manager to proxy execute calls through.
ExecutablePluginBase::getConfig public function Gets all configuration values.
ExecutablePluginBase::getConfigDefinition public function Gets the definition of a configuration option.
ExecutablePluginBase::getConfigDefinitions public function Gets an array of definitions of available configuration options.
ExecutablePluginBase::setConfig public function Sets the value of a particular configuration option.
ExecutablePluginBase::setExecutableManager public function
Php::buildForm public function Implements \Drupal\Core\Form\FormInterface::buildForm(). Overrides ConditionPluginBase::buildForm
Php::evaluate public function Evaluates the condition and returns TRUE or FALSE accordingly. Overrides ConditionInterface::evaluate
Php::submitForm public function Implements \Drupal\Core\Form\FormInterface::submitForm(). Overrides ConditionPluginBase::submitForm
Php::summary public function Provides a human readable summary of the condition's configuration. Overrides ConditionInterface::summary
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId