You are here

trait CalendarViewsTrait in Calendar 8

The trait.

Hierarchy

1 file declares its use of CalendarViewsTrait
Calendar.php in src/Plugin/views/row/Calendar.php

File

src/CalendarViewsTrait.php, line 11

Namespace

Drupal\calendar
View source
trait CalendarViewsTrait {

  /**
   * {@inheritDoc}
   */
  protected function getTableEntityType($table) {
    static $recursion = 0;
    if ($table = Views::viewsData()
      ->get($table)) {
      if (!empty($table['table']['entity type'])) {

        // Reset recursion when we found a value.
        $recursion = 0;
        return $table['table']['entity type'];
      }
      elseif (!empty($table['table']['join']) && count($table['table']['join']) == 1) {
        if (empty($recursion)) {
          $join_table = array_pop(array_keys($table['table']['join']));
          $recursion++;
          return $this
            ->getTableEntityType($join_table);
        }
      }
    }
    return NULL;
  }

  /**
   * Determine if this field is Entity Reference field that references a taxonomy term.
   *
   * @todo Change to a more generic is Content Entity Reference.
   *
   * @param $field_info
   * @param \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager
   *   The entity field manager service.
   */
  protected function isTermReferenceField($field_info, EntityFieldManagerInterface $field_manager) {
    if (!empty($field_info['type']) && $field_info['type'] == 'entity_reference_label') {
      if ($entity_type = $this
        ->getTableEntityType($field_info['table'])) {
        $field_definitions = $field_manager
          ->getFieldStorageDefinitions($entity_type);
        $field_definition = $field_definitions[$field_info['field']];
        $target_type = $field_definition
          ->getSetting('target_type');
        return $target_type == 'taxonomy_term';
      }
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CalendarViewsTrait::getTableEntityType protected function
CalendarViewsTrait::isTermReferenceField protected function Determine if this field is Entity Reference field that references a taxonomy term.