You are here

class PhotosViewsData in Album Photos 6.0.x

Same name and namespace in other branches
  1. 8.5 src/PhotosViewsData.php \Drupal\photos\PhotosViewsData

Provides the views data for photos module and the photos_image entity type.

Hierarchy

Expanded class hierarchy of PhotosViewsData

File

src/PhotosViewsData.php, line 10

Namespace

Drupal\photos
View source
class PhotosViewsData extends EntityViewsData {

  /**
   * {@inheritdoc}
   */
  public function getViewsData() {
    $data = parent::getViewsData();
    $data['photos_album'] = [];
    $data['photos_album']['table'] = [];
    $data['photos_album']['table']['group'] = $this
      ->t('Photos');
    $data['photos_album']['table']['provider'] = 'photos';

    // Join {node_field_data} and {photos_image_field_data}.
    $data['photos_album']['table']['join'] = [
      'node_field_data' => [
        'left_field' => 'nid',
        'field' => 'album_id',
      ],
      'photos_image_field_data' => [
        'left_field' => 'album_id',
        'field' => 'album_id',
      ],
    ];

    // Cover ID field.
    $data['photos_album']['cover_id'] = [
      'title' => $this
        ->t('Album cover'),
      'help' => $this
        ->t('The album cover image.'),
      'field' => [
        'id' => 'photos_image_cover',
      ],
      'sort' => [
        'id' => 'standard',
      ],
    ];

    // Album weight.
    $data['photos_album']['weight'] = [
      'title' => $this
        ->t('Album weight'),
      'help' => $this
        ->t('The weight of this album.'),
      'field' => [
        'id' => 'numeric',
      ],
      'filter' => [
        'id' => 'numeric',
      ],
      'sort' => [
        'id' => 'standard',
      ],
    ];

    // Album image count.
    // @todo move out to photos_count table.
    $data['photos_album']['count'] = [
      'title' => $this
        ->t('Album image count'),
      'help' => $this
        ->t('The number of images in this album.'),
      'field' => [
        'id' => 'numeric',
      ],
      'filter' => [
        'id' => 'numeric',
      ],
      'sort' => [
        'id' => 'standard',
      ],
    ];
    $data['photos_image_field_data']['table']['group'] = $this
      ->t('Photos');
    $data['photos_image_field_data']['table']['provider'] = 'photos';

    // Join album info to images.
    $data['photos_image_field_data']['table']['join'] = [
      'node_field_data' => [
        'left_field' => 'nid',
        'field' => 'album_id',
      ],
      'photos_album' => [
        'left_field' => 'album_id',
        'field' => 'album_id',
      ],
    ];

    // Album node ID table field.
    $data['photos_image_field_data']['album_id'] = [
      'title' => $this
        ->t('Album'),
      'help' => $this
        ->t('Album nid.'),
      'sort' => [
        'id' => 'standard',
      ],
      'relationship' => [
        'id' => 'standard',
        'base' => 'node_field_data',
        'entity type' => 'node',
        'base field' => 'nid',
        'label' => $this
          ->t('The album'),
        'title' => $this
          ->t('Album'),
        'help' => $this
          ->t('The album associated with this image.'),
      ],
      'argument' => [
        'id' => 'node_nid',
        'name field' => 'title',
        'numeric' => TRUE,
        'validate type' => 'nid',
      ],
    ];

    // Set as album cover link.
    $data['photos_image_field_data']['set_cover'] = [
      'field' => [
        'title' => $this
          ->t('Set as album cover link'),
        'help' => $this
          ->t('Provide a link to set this image as the album cover.'),
        'id' => 'photos_image_set_cover',
      ],
    ];

    // Image views count.
    $data['photos_count'] = [];
    $data['photos_count']['table'] = [];
    $data['photos_count']['table']['group'] = $this
      ->t('Photos');
    $data['photos_count']['table']['provider'] = 'photos';

    // Join {photos_image_field_data}.
    $data['photos_count']['table']['join'] = [
      'photos_image_field_data' => [
        'left_field' => 'id',
        'field' => 'cid',
        'extra' => [
          [
            'field' => 'type',
            'value' => 'image_views',
          ],
        ],
      ],
    ];
    $data['photos_count']['value'] = [
      'title' => $this
        ->t('Image views'),
      'help' => $this
        ->t('Number of times this image has been viewed.'),
      'field' => [
        'id' => 'numeric',
      ],
      'filter' => [
        'id' => 'numeric',
      ],
      'sort' => [
        'id' => 'standard',
      ],
    ];
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityViewsData::$entityFieldManager protected property The entity field manager.
EntityViewsData::$entityType protected property Entity type for this views data handler instance.
EntityViewsData::$entityTypeManager protected property The entity type manager.
EntityViewsData::$fieldStorageDefinitions protected property The field storage definitions for all base fields of the entity type.
EntityViewsData::$moduleHandler protected property The module handler.
EntityViewsData::$storage protected property The storage used for this entity type.
EntityViewsData::$translationManager protected property The translation manager.
EntityViewsData::addEntityLinks protected function Sets the entity links in case corresponding link templates exist.
EntityViewsData::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface::createInstance
EntityViewsData::getFieldStorageDefinitions protected function Gets the field storage definitions.
EntityViewsData::getViewsTableForEntityType public function Gets the table of an entity type to be used as base table in views. Overrides EntityViewsDataInterface::getViewsTableForEntityType
EntityViewsData::mapFieldDefinition protected function Puts the views data for a single field onto the views data.
EntityViewsData::mapSingleFieldViewsData protected function Provides the views data for a given data type and schema field.
EntityViewsData::processViewsDataForEntityReference protected function Processes the views data for an entity reference field.
EntityViewsData::processViewsDataForLanguage protected function Processes the views data for a language field.
EntityViewsData::processViewsDataForTextLong protected function Processes the views data for a text field with formatting.
EntityViewsData::processViewsDataForUuid protected function Processes the views data for a UUID field.
EntityViewsData::__construct public function Constructs an EntityViewsData object.
PhotosViewsData::getViewsData public function Returns views data for the entity type. Overrides EntityViewsData::getViewsData
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.