You are here

public function RulesPluginUI::buildContent in Rules 7.2

Implements RulesPluginUIInterface.

Shows a preview of the configuration settings.

Overrides RulesPluginUIInterface::buildContent

1 call to RulesPluginUI::buildContent()
RulesContainerPluginUI::buildContent in ui/ui.core.inc
Implements RulesPluginUIInterface.
1 method overrides RulesPluginUI::buildContent()
RulesContainerPluginUI::buildContent in ui/ui.core.inc
Implements RulesPluginUIInterface.

File

ui/ui.core.inc, line 740
Contains core Rules UI functions.

Class

RulesPluginUI
Faces UI extender for all kind of Rules plugins.

Code

public function buildContent() {
  $config_name = $this->element
    ->root()->name;
  $content['label'] = array(
    '#type' => 'link',
    '#title' => $this->element
      ->label(),
    '#href' => $this->element
      ->isRoot() ? RulesPluginUI::path($config_name) : RulesPluginUI::path($config_name, 'edit', $this->element),
    '#prefix' => '<div class="rules-element-label">',
    '#suffix' => '</div>',
  );

  // Put the elements below in a "description" div.
  $content['description'] = array(
    '#prefix' => '<div class="description">',
  );
  $content['description']['parameter'] = array(
    '#caption' => t('Parameter'),
    '#theme' => 'rules_content_group',
  );
  foreach ($this->element
    ->pluginParameterInfo() as $name => $parameter) {
    $element = array();
    if (!empty($this->element->settings[$name . ':select'])) {
      $element['content'] = array(
        '#markup' => '[' . $this->element->settings[$name . ':select'] . ']',
      );
    }
    elseif (isset($this->element->settings[$name])) {
      $class = $this
        ->getDataTypeClass($parameter['type'], $parameter);
      $method = empty($parameter['options list']) ? 'render' : 'renderOptionsLabel';

      // We cannot use method_exists() here as it would trigger a PHP bug.
      // @see https://www.drupal.org/node/1258284
      $element = call_user_func(array(
        $class,
        $method,
      ), $this->element->settings[$name], $name, $parameter, $this->element);
    }

    // Only add parameters that are really configured / not default.
    if ($element) {
      $content['description']['parameter'][$name] = array(
        '#theme' => 'rules_parameter_configuration',
        '#info' => $parameter,
      ) + $element;
    }
  }
  foreach ($this->element
    ->providesVariables() as $name => $var_info) {
    $content['description']['provides'][$name] = array(
      '#theme' => 'rules_variable_view',
      '#info' => $var_info,
      '#name' => $name,
    );
  }
  if (!empty($content['description']['provides'])) {
    $content['description']['provides'] += array(
      '#caption' => t('Provides variables'),
      '#theme' => 'rules_content_group',
    );
  }

  // Add integrity exception messages if there are any for this element.
  try {
    $this->element
      ->integrityCheck();

    // A configuration is still marked as dirty, but already works again.
    if (!empty($this->element->dirty)) {
      rules_config_update_dirty_flag($this->element);
      $variables = array(
        '%label' => $this->element
          ->label(),
        '%name' => $this->element->name,
        '@plugin' => $this->element
          ->plugin(),
      );
      drupal_set_message(t('The @plugin %label (%name) was marked dirty, but passes the integrity check now and is active again.', $variables));
      rules_clear_cache();
    }
  } catch (RulesIntegrityException $e) {
    $content['description']['integrity'] = array(
      '#theme' => 'rules_content_group',
      '#caption' => t('Error'),
      '#attributes' => array(
        'class' => array(
          'rules-content-group-integrity-error',
        ),
      ),
      'error' => array(
        '#markup' => filter_xss($e
          ->getMessage()),
      ),
    );

    // Also make sure the rule is marked as dirty.
    if (empty($this->element->dirty)) {
      rules_config_update_dirty_flag($this->element);
      rules_clear_cache();
    }
  }
  $content['#suffix'] = '</div>';
  $content['#type'] = 'container';
  $content['#attributes']['class'][] = 'rules-element-content';
  return $content;
}