You are here

public function FacetapiDependencyFacet::settingsForm in Facet API Bonus 7

Adds dependency settings to the form.

File

plugins/facetapi/dependency_facet.inc, line 84
Performs a dependency check against other specified facets/facet values

Class

FacetapiDependencyFacet
Adds a dependency on another facet being active.

Code

public function settingsForm(&$form, &$form_state) {

  // Get enabled facets (minus this dependency's one).
  $facets = $this
    ->getEnabledFacets();
  $form[$this->id]['facets'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Show this facet only for specific other facets'),
    '#default_value' => $this->settings['facets'],
    '#options' => array_map('check_plain', $facets),
    '#description' => t('Show this facet only if another one of these selected facet(s) is actively in use. If you select no other facets, the facet will be visible not depend on other facets.'),
  );
  $form[$this->id]['reverse_dependency'] = array(
    '#type' => 'checkbox',
    '#title' => t('Reverse dependency.'),
    '#default_value' => $this->settings['reverse_dependency'],
    '#description' => t('Reverse dependency logic: the facet will be deactivated in the dependency is met.'),
  );
  $form[$this->id]['force_deactivation'] = array(
    '#type' => 'checkbox',
    '#title' => t('Force deactivation for unmet dependency.'),
    '#default_value' => $this->settings['force_deactivation'],
    '#description' => t('Deactivate this facet if dependency is not met anymore, even if this facet has had active items itself (recommended)'),
  );
  $form[$this->id]['regex'] = array(
    '#title' => t('Regular expressions used'),
    '#type' => 'checkbox',
    '#description' => t('Interpret each facet item of each list below as a regular expression pattern.<br /><small>(Slashes are escaped automatically, patterns using a comma can be wrapped in "double quotes", and if such a pattern uses double quotes itself, just make them double-double-quotes (""))</small>.'),
    '#default_value' => $this->settings['regex'],
  );

  // Add optional value field and extend default settings for each facet.
  foreach ($facets as $facet_name => $facet_title) {
    $id = 'facet_items_' . $facet_name;
    $checkboxid = '#edit-facets-' . str_replace('_', '-', drupal_strtolower($facet_name));
    $form[$this->id][$id] = array(
      '#title' => t('Facet items for %facet', array(
        '%facet' => $facet_title,
      )),
      '#type' => 'textfield',
      '#description' => t("Comma separated list of facet items to depend on, matching against an facet item's value."),
      '#default_value' => isset($this->settings[$id]) ? $this->settings[$id] : NULL,
      '#states' => array(
        'visible' => array(
          $checkboxid => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $this->defaultSettings[$id] = '';
  }
}