You are here

class ACKEntityTaxonomyTermReference in Access Control Kit 7

Controls access to an entity based on a taxonomy term reference field.

Hierarchy

Expanded class hierarchy of ACKEntityTaxonomyTermReference

1 string reference to 'ACKEntityTaxonomyTermReference'
AckNodeAccessTest::testFieldAccess in ack_node/ack_node.test
Test controlling access by a field value.

File

handlers/ack_entity_taxonomy_term_reference.inc, line 11
Contains the handler class for term reference fields on entities.

View source
class ACKEntityTaxonomyTermReference extends ACKEntityField {

  /**
   * The machine name of the vocabulary that defines the realms.
   *
   * @var string
   */
  protected $vocabulary;

  /**
   * Overrides ACKEntityField::__construct().
   */
  public function __construct($scheme, array $settings = array()) {
    parent::__construct($scheme, $settings);

    // The choice of field is a handler-level setting.
    $this->fieldName = isset($settings['field_name']) ? $settings['field_name'] : NULL;

    // Taxonomy term reference fields use 'tid' as the value key.
    $this->fieldValueKey = 'tid';

    // Get the vocabulary from the scheme settings.
    $this->vocabulary = isset($scheme->settings['vocabulary']) ? $scheme->settings['vocabulary'] : NULL;
  }

  /**
   * Overrides ACKEntityField::description().
   */
  public function description() {
    return t('The value of the selected term reference field will determine realm membership.');
  }

  /**
   * Overrides AccessControlKitHandler::settingsForm().
   */
  public function settingsForm() {

    // Find all term reference fields that work with the scheme's vocabulary.
    $options = array();
    if (!empty($this->vocabulary)) {
      $fields = field_read_fields(array(
        'type' => 'taxonomy_term_reference',
      ));
      foreach ($fields as $field_name => $field) {
        if (!empty($field['settings']['allowed_values']) && $field['settings']['allowed_values'][0]['vocabulary'] == $this->vocabulary) {
          $options[$field_name] = check_plain($field_name);
        }
      }
    }
    $form['field_name'] = array(
      '#title' => t('The term reference field'),
      '#type' => 'select',
      '#options' => $options,
      '#default_value' => $this->fieldName,
    );
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AccessControlKitHandler::$settings protected property The access handler configuration.
AccessControlKitHandler::getSettings public function Implements AccessControlKitHandlerInterface::getSettings(). Overrides AccessControlKitHandlerInterface::getSettings
AccessControlKitHandler::objectFormSubmit public function Implements AccessControlKitHandlerInterface::objectFormSubmit(). Overrides AccessControlKitHandlerInterface::objectFormSubmit 1
AccessControlKitHandler::objectFormValidate public function Implements AccessControlKitHandlerInterface::objectFormValidate(). Overrides AccessControlKitHandlerInterface::objectFormValidate
ACKEntityField::$fieldName protected property The name of the field that determines access.
ACKEntityField::$fieldValueKey protected property The key that contains the field's value in calls to field_get_items().
ACKEntityField::objectFormAlter public function Overrides AccessControlKitHandler::objectFormAlter(). Overrides AccessControlKitHandler::objectFormAlter
ACKEntityField::objectRealms public function Overrides AccessControlKitHandler::objectRealms(). Overrides AccessControlKitHandler::objectRealms
ACKEntityField::viewsDataAlter public function Overrides AccessControlKitHandler::viewsDataAlter(). Overrides AccessControlKitHandler::viewsDataAlter
ACKEntityTaxonomyTermReference::$vocabulary protected property The machine name of the vocabulary that defines the realms.
ACKEntityTaxonomyTermReference::description public function Overrides ACKEntityField::description(). Overrides ACKEntityField::description
ACKEntityTaxonomyTermReference::settingsForm public function Overrides AccessControlKitHandler::settingsForm(). Overrides AccessControlKitHandler::settingsForm
ACKEntityTaxonomyTermReference::__construct public function Overrides ACKEntityField::__construct(). Overrides ACKEntityField::__construct