class RulesDataUI

Default UI related class for data types.

Hierarchy

Expanded class hierarchy of RulesDataUI

1 string reference to 'RulesDataUI'
RulesPluginUI::getDataTypeClass in ui/ui.core.inc
Returns the name of class for the given data type.

File

ui/ui.data.inc, line 60

View source
class RulesDataUI {
    
    /**
     * Specifies the default input mode per data type.
     */
    public static function getDefaultMode() {
        return 'selector';
    }
    
    /**
     * Provides the selection form for a parameter.
     */
    public static function selectionForm($name, $info, $settings, RulesPlugin $element) {
        if (!isset($settings[$name . ':select'])) {
            $settings[$name . ':select'] = '';
            $vars = $element->availableVariables();
            // Default to variables with the same name as the parameter.
            if (isset($vars[$name])) {
                $settings[$name . ':select'] = $name;
            }
            elseif (count($matches = RulesData::matchingDataSelector($vars, $info, '', 1, FALSE)) == 1) {
                $settings[$name . ':select'] = rules_array_key($matches);
            }
        }
        $form[$name . ':select'] = array(
            '#type' => 'rules_data_selection',
            '#title' => t('Data selector'),
            '#default_value' => $settings[$name . ':select'],
            '#required' => empty($info['optional']),
            '#autocomplete_path' => RulesPluginUI::path($element->root()->name, 'autocomplete' . '/' . $name),
            // Make the autocomplete textfield big enough so that it can display
            // descriptions without word wraps.
'#size' => 75,
            '#description' => t("The data selector helps you drill down into the data available to Rules. <em>To make entity fields appear in the data selector, you may have to use the condition 'Entity has field' (or 'Entity is of bundle').</em> More useful tips about data selection are available in <a href='@url'>the online documentation</a>.", array(
                '@url' => rules_external_help('data-selection'),
            )),
        );
        $cache = rules_get_cache();
        $form['types_help'] = array(
            '#theme' => 'rules_settings_help',
            '#heading' => t('Data types'),
        );
        if ($info['type'] == '*') {
            $type_labels[] = t('any');
        }
        else {
            $types = is_array($info['type']) ? $info['type'] : array(
                $info['type'],
            );
            $type_labels = array();
            foreach ($types as $type) {
                $type_labels[] = drupal_ucfirst(isset($cache['data_info'][$type]['label']) ? $cache['data_info'][$type]['label'] : $type);
            }
        }
        $form['types_help']['#text'] = format_plural(count($type_labels), 'Select data of the type %types.', 'Select data of the types %types.', array(
            '%types' => implode(', ', $type_labels),
        ));
        if (!empty($info['translatable'])) {
            if (empty($info['custom translation language'])) {
                $text = t('If a multilingual data source (i.e. a translatable field) is given, the argument is translated to the current interface language.');
            }
            else {
                $text = t('If a multilingual data source (i.e. a translatable field) is given, the argument is translated to the configured language.');
            }
            $form['translation'] = array(
                '#theme' => 'rules_settings_help',
                '#text' => $text,
                '#heading' => t('Translation'),
            );
        }
        $form['help'] = array(
            '#theme' => 'rules_data_selector_help',
            '#variables' => $element->availableVariables(),
            '#parameter' => $info,
        );
        // Add data processor.
        $settings += array(
            $name . ':process' => array(),
        );
        $form[$name . ':process'] = array();
        RulesDataProcessor::attachForm($form[$name . ':process'], $settings[$name . ':process'], $info, $element->availableVariables());
        return $form;
    }
    
    /**
     * Renders the value with a label if an options list is available.
     *
     * Used for data UI classes implementing the
     * RulesDataDirectInputFormInterface.
     *
     * In case an options list is available, the usual render() method won't
     * be invoked, instead the selected entry is rendered via this method.
     *
     * @todo for Drupal 8: Refactor to avoid implementations have to care about
     * option lists when generating the form, but not when rendering values.
     */
    public static function renderOptionsLabel($value, $name, $info, RulesPlugin $element) {
        if (!empty($info['options list'])) {
            $element->call('loadBasicInclude');
            $options = entity_property_options_flatten(call_user_func($info['options list'], $element, $name));
            if (!is_array($value) && isset($options[$value])) {
                $value = $options[$value];
            }
            elseif (is_array($value)) {
                foreach ($value as $key => $single_value) {
                    if (isset($options[$single_value])) {
                        $value[$key] = $options[$single_value];
                    }
                }
                $value = implode(', ', $value);
            }
            return array(
                'content' => array(
                    '#markup' => check_plain($value),
                ),
                '#attributes' => array(
                    'class' => array(
                        'rules-parameter-options-entry',
                    ),
                ),
            );
        }
    }
    
    /**
     * Returns the data type and parameter information for the given arguments.
     *
     * This helper may be used by options list callbacks operation at data-type
     * level, see RulesDataInputOptionsListInterface.
     */
    public static function getTypeInfo(RulesPlugin $element, $name) {
        $parameters = $element->pluginParameterInfo();
        return array(
            $parameters[$name]['type'],
            $parameters[$name],
        );
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
RulesDataUI::getDefaultMode public static function Specifies the default input mode per data type. 2
RulesDataUI::getTypeInfo public static function Returns the data type and parameter information for the given arguments.
RulesDataUI::renderOptionsLabel public static function Renders the value with a label if an options list is available.
RulesDataUI::selectionForm public static function Provides the selection form for a parameter.