You are here

class FacetapiDependencyRole in Facet API 7.2

Same name and namespace in other branches
  1. 6.3 plugins/facetapi/dependency_role.inc \FacetapiDependencyRole
  2. 7 plugins/facetapi/dependency_role.inc \FacetapiDependencyRole

Dependency plugin adding the user role conditions.

The role dependency plugin adds conditions based on the current user's role. Although the backend should handle access control, this plugin can help personalize the search interface based on the user's role by exposing facets to certain users while hiding them from others.

Hierarchy

Expanded class hierarchy of FacetapiDependencyRole

1 string reference to 'FacetapiDependencyRole'
facetapi_facetapi_dependencies in ./facetapi.facetapi.inc
Implements hook_facetapi_dependencies().

File

plugins/facetapi/dependency_role.inc, line 16
The role dependency class.

View source
class FacetapiDependencyRole extends FacetapiDependency {

  /**
   * Implements FacetapiDependency::execute().
   */
  public function execute() {
    global $user;
    if (1 != $user->uid) {
      $roles = array_filter($this->settings['roles']);
      if ($roles && !array_intersect_key($user->roles, $roles)) {
        return FALSE;
      }
    }
  }

  /**
   * Overrides FacetapiDependency::settingsForm().
   */
  public function settingsForm(&$form, &$form_state) {
    $form[$this->id]['roles'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Show facet for specific roles'),
      '#default_value' => $this->settings['roles'],
      '#options' => array_map('check_plain', user_roles()),
      '#description' => t('Show this facet only for the selected role(s). If you select no roles, the facet will be visible to all users.'),
    );
  }

  /**
   * Overrides FacetapiDependency::getDefaultSettings().
   */
  public function getDefaultSettings() {
    return array(
      'roles' => array(),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FacetapiDependency::$activeItems protected property The facet's active items as returned by FacetapiAdapter::getActiveItems().
FacetapiDependency::$adapter protected property The adapter associated with facet whose dependencies are being checked.
FacetapiDependency::$facet protected property The facet definition as returned by facetapi_facet_load().
FacetapiDependency::$id protected property The machine name of the plugin associated with this instance.
FacetapiDependency::$settings protected property An array of dependency settings.
FacetapiDependency::getFacet public function Gets the facet definition as returned by facetapi_facet_load().
FacetapiDependency::getId public function Gets the machine name of the plugin.
FacetapiDependency::__construct public function Constructs a FacetapiDependency object.
FacetapiDependencyRole::execute public function Implements FacetapiDependency::execute(). Overrides FacetapiDependency::execute
FacetapiDependencyRole::getDefaultSettings public function Overrides FacetapiDependency::getDefaultSettings(). Overrides FacetapiDependency::getDefaultSettings
FacetapiDependencyRole::settingsForm public function Overrides FacetapiDependency::settingsForm(). Overrides FacetapiDependency::settingsForm