You are here

public function ACKEntityField::viewsDataAlter in Access Control Kit 7

Overrides AccessControlKitHandler::viewsDataAlter().

Overrides AccessControlKitHandler::viewsDataAlter

File

handlers/ack_entity_field.inc, line 110
Contains the handler class for Field API fields on entities.

Class

ACKEntityField
Controls access to a fieldable entity based on a Field API field.

Code

public function viewsDataAlter(&$data, $scheme_machine_name, $realm_field_table_name, $realm_field_table_value, $object_type) {
  if (!empty($this->fieldName)) {
    $entity_info = entity_get_info($object_type);
    $entity_field = field_info_field($this->fieldName);
    if (isset($entity_info['base table']) && $entity_field['storage']['type'] == 'field_sql_storage') {
      $entity_field_table = $entity_field['storage']['details']['sql'][FIELD_LOAD_CURRENT];
      $entity_field_table_name = key($entity_field_table);
      if (isset($entity_field_table[$entity_field_table_name][$this->fieldValueKey])) {
        $entity_field_table_value = $entity_field_table[$entity_field_table_name][$this->fieldValueKey];
        $pseudo_field_name = 'ack_' . $scheme_machine_name;
        $scheme_names = access_scheme_names();
        $t_args = array(
          '@entity' => $object_type,
          '@field' => $entity_field['field_name'],
          '@scheme' => $scheme_names[$scheme_machine_name],
          '@machine' => $scheme_machine_name,
        );

        // Relate the entity field to access grants through the realm field.
        $data[$entity_info['base table']][$pseudo_field_name] = array(
          'title' => t('Access grants on @entity for @scheme', $t_args),
          'real field' => $entity_info['entity keys']['id'],
          'relationship' => array(
            'label' => t('@machine access grants', $t_args),
            'help' => t('Relate the @entity to @scheme access grants through the @field field.', $t_args),
            'handler' => 'access_handler_relationship_ack_entity_field',
            'base' => 'access_grant',
            'field' => $entity_info['entity keys']['id'],
            'scheme' => $scheme_machine_name,
            'entity type' => $object_type,
            'entity table' => $entity_field_table_name,
            'entity field' => $entity_field_table_value,
            'realm table' => $realm_field_table_name,
            'realm field' => $realm_field_table_value,
          ),
        );
      }
    }
  }
}