You are here

class RulesFormsDataElement in Rules Forms Support 7

Defines the form element data type UI.

Hierarchy

Expanded class hierarchy of RulesFormsDataElement

1 string reference to 'RulesFormsDataElement'
rules_forms_rules_data_info in ./rules_forms.rules.inc
Implements hook_rules_data_type_info().

File

includes/rules_forms.ui.inc, line 48
Defines data type classes for forms and form elements.

View source
class RulesFormsDataElement extends RulesFormsDataUI {

  /**
   * An array of attributes and the form element types to which they apply.
   *
   * This array is used to filter the form element options available during
   * specific attribute setting actions.
   *
   * @var array
   */
  private static $attributes = array(
    'access' => 'all',
    'changed' => array(
      'textfield',
      'textarea',
      'checkbox',
      'checkboxes',
      'password',
      'radio',
      'radios',
      'select',
    ),
    'clicked' => array(
      'button',
      'submit',
    ),
    'disabled' => array(
      'textfield',
      'textarea',
      'checkbox',
      'checkboxes',
      'password',
      'radio',
      'radios',
      'select',
      'button',
      'submit',
    ),
    'default' => array(
      'textfield',
      'textarea',
      'checkbox',
      'checkboxes',
      'radio',
      'radios',
      'select',
    ),
    'description' => array(
      'textfield',
      'textarea',
      'checkbox',
      'checkboxes',
      'password',
      'radio',
      'radios',
      'select',
      'item',
    ),
    'error' => 'all',
    'options' => array(
      'select',
      'checkboxes',
    ),
    'required' => array(
      'textfield',
      'textarea',
      'checkbox',
      'checkboxes',
      'password',
      'radio',
      'radios',
      'select',
    ),
    'suffix' => 'all',
    'title' => array(
      'textfield',
      'textarea',
      'checkbox',
      'checkboxes',
      'password',
      'radio',
      'radios',
      'select',
      'item',
    ),
    'weight' => 'all',
    'value' => array(
      'textfield',
      'textarea',
      'checkbox',
      'checkboxes',
      'password',
      'radio',
      'radios',
      'select',
    ),
  );

  /**
   * Returns a select list with options including only available elements.
   */
  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
    $options = array();

    // Get the type of attribute being set from the end of the element name.
    // The action name should directly correspond with the attribute it sets
    // for this reason.
    $element_name = $element
      ->getElementName();
    $attributes = explode('_', $element_name);
    $attribute = array_pop($attributes);

    // Loop through each variable and retrieve the options that apply to
    // this field type.
    foreach ($element
      ->availableVariables() as $key => $value) {

      // Populate the options list with only form elements.
      if (!in_array($key, array(
        'site',
        'form',
        'form_state',
        'form_id',
        'user',
      ))) {
        $type = substr($key, 0, strpos($key, ':'));

        // Filter the elements by determining whether this attribute
        // can be applied to them.
        if (isset(self::$attributes[$attribute]) && (self::$attributes[$attribute] == 'all' || in_array($type, self::$attributes[$attribute]))) {
          if (!isset($options[$type])) {
            $options[$type] = array();
          }
          $options[$type][$key] = $value['label'];
        }
      }
    }
    ksort($options);
    $form = parent::defaultForm($name, $info, $settings, 'Form element');
    $form[$name]['#options'] = $options;
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
RulesFormsDataElement::$attributes private static property An array of attributes and the form element types to which they apply.
RulesFormsDataElement::inputForm public static function Returns a select list with options including only available elements. Overrides RulesDataDirectInputFormInterface::inputForm
RulesFormsDataUI::defaultForm public static function Provides the default form.
RulesFormsDataUI::getDefaultMode public static function Provides the default mode. Overrides RulesDataUI::getDefaultMode
RulesFormsDataUI::render public static function Renders a parameter value. Overrides RulesDataDirectInputFormInterface::render