You are here

function safeword_context_condition::options_form in Safeword 7

Same name and namespace in other branches
  1. 8 safeword_context/safeword_context_condition.inc \safeword_context_condition::options_form()

Options form. Provide additional options for your condition.

Overrides context_condition::options_form

File

safeword_context/safeword_context_condition.inc, line 31

Class

safeword_context_condition

Code

function options_form($context) {
  $entity_types = array_map(function ($type) {
    return $type['label'];
  }, entity_get_info());
  $options = $this
    ->fetch_from_context($context, 'options');
  return array(
    'entity_types' => array(
      '#title' => t('Only entity types'),
      '#type' => 'checkboxes',
      '#options' => $entity_types,
      '#description' => t('Leave empty to match all entity types.'),
      '#default_value' => isset($options['entity_types']) ? array_filter($options['entity_types']) : array(),
      // This gets rid of all the unchecked options that Drupal would normally keep: node => 0, file => 'file' etc.
      '#element_validate' => array(
        function ($element, &$form_state) {
          form_set_value($element, array_filter($element['#value']), $form_state);
        },
      ),
    ),
  );
}