You are here

class classified_context_condition_path in Classified Ads 7.3

Same name and namespace in other branches
  1. 6.3 plugins/classified_context_condition_path.inc \classified_context_condition_path

Merge Classified Ads paths within a Context path condition.

As a context plugin, method names cannot respect naming conventions.

phpcs:disable Drupal.NamingConventions.ValidFunctionName, phpcs:disable Drupal.NamingConventions.ValidClassName phpcs:disable PSR1.Methods.CamelCapsMethodName phpcs:disable PSR1.Classes.ClassDeclaration phpcs:disable Squiz.Classes.ValidClassName

Hierarchy

Expanded class hierarchy of classified_context_condition_path

1 string reference to 'classified_context_condition_path'
classified_context_plugins in ./classified.module
Implements hook_context_plugins().

File

plugins/classified_context_condition_path.inc, line 25
A plugin declaring the Classified Ads paths as context conditions.

View source
class classified_context_condition_path extends context_condition_path {

  /**
   * Helper listing the paths to register.
   *
   * @param bool $assoc
   *   Use associative array format ?
   *
   * @return array|false
   *   The paths.
   */
  protected function get_classified_paths($assoc = FALSE) {
    $ret = array(
      'admin/config/content/classified',
      'admin/config/content/classified/*',
      'classified',
      'classified/*',
      'user/*/classified',
      'user/*/classified/*',
    );
    if ($assoc) {
      $ret = drupal_map_assoc($ret);
    }
    return $ret;
  }

  /**
   * Condition form.
   *
   * @return array
   *   A form array for the condition.
   */
  public function condition_form($context) {
    $form = array();
    $form['1'] = parent::condition_form($context);
    $all_paths = explode("\n", $form['1']['#default_value']);
    $classified_paths = $this
      ->get_classified_paths();
    sort($classified_paths);
    $common_paths = array_values(array_intersect($all_paths, $classified_paths));
    sort($common_paths);
    $form['2'] = array(
      '#title' => t('Auto Classified path set'),
      '#description' => t('Helper: merge all paths belonging to the Classified Ads application into the above list.'),
      '#type' => 'checkbox',
      '#default_value' => $common_paths == $classified_paths,
    );
    return $form;
  }

  /**
   * Condition form submit handler.
   *
   * Merge the Classified Ads paths into the manually entered paths list.
   *
   * @return array
   *   An array of paths on which the condition will hold.
   */
  public function condition_form_submit($values) {
    $auto_path = array_pop($values);
    $values = reset($values);
    $paths = parent::condition_form_submit($values);
    if ($auto_path) {
      $paths = array_merge($paths, $this
        ->get_classified_paths(TRUE));
      sort($paths);
    }

    // Coder limitation: unlike usual FAPI, Context submit handlers return data.
    return $paths;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
classified_context_condition_path::condition_form public function Condition form. Overrides context_condition_path::condition_form
classified_context_condition_path::condition_form_submit public function Condition form submit handler. Overrides context_condition_path::condition_form_submit
classified_context_condition_path::get_classified_paths protected function Helper listing the paths to register.
context_condition::$description property
context_condition::$plugin property
context_condition::$title property
context_condition::$values property
context_condition::condition_met function Marks a context as having met this particular condition.
context_condition::condition_used function Check whether this condition is used by any contexts. Can be used to prevent expensive condition checks from being triggered when no contexts use this condition.
context_condition::editor_form function Context editor form for conditions. 2
context_condition::editor_form_submit function Context editor form submit handler.
context_condition::fetch_from_context function Retrieve options from the context provided.
context_condition::get_contexts function Retrieve all contexts with the condition value provided. 2
context_condition::options_form function Options form. Provide additional options for your condition. 4
context_condition::options_form_submit function Options form submit handler.
context_condition::settings_form function Settings form. Provide variable settings for your condition.
context_condition::__clone function Clone our references when we're being cloned.
context_condition::__construct function Constructor. Do not override.
context_condition_path::condition_values function Omit condition values. We will provide a custom input form for our conditions. Overrides context_condition::condition_values
context_condition_path::execute function Execute. 3
context_condition_path::match protected function Match the subject against a set of regex patterns. Similar to drupal_match_path() but also handles negation through the use of the ~ character.