getDefinition('entity_subqueue'); // Find all entity types that need an 'entityqueue' relationship. $target_entity_type_ids = []; $queues = EntityQueue::loadMultiple(); foreach ($queues as $queue) { $target_entity_type_ids[$queue->getTargetEntityTypeId()] = TRUE; } // Filter entity types to those that have a 'views_data' handler and use a SQL // storage. /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */ $entity_types = []; foreach (array_keys($target_entity_type_ids) as $entity_type_id) { $entity_type = $entity_type_manager->getDefinition($entity_type_id); if ($entity_type->hasHandlerClass('views_data') && $entity_type_manager->getStorage($entity_type->id()) instanceof SqlEntityStorageInterface) { $entity_types[$entity_type_id] = $entity_type; } } foreach ($entity_types as $entity_type_id => $entity_type) { $field_name = 'items'; $field_storage = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_subqueue')[$field_name]; $target_base_table = $entity_type->getDataTable() ?: $entity_type->getBaseTable(); /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */ $table_mapping = $entity_type_manager->getStorage('entity_subqueue')->getTableMapping(); $columns = $table_mapping->getColumnNames($field_name); $subqueue_items_table_name = $table_mapping->getDedicatedDataTableName($field_storage); $data[$target_base_table]['entityqueue_relationship']['relationship'] = [ 'id' => 'entity_queue', 'title' => t('@target_label queue', ['@target_label' => $entity_type->getLabel()]), 'label' => t('@target_label queue', ['@target_label' => $entity_type->getLabel()]), 'group' => t('Entityqueue'), 'help' => t('Create a relationship from @target_label to an entityqueue.', ['@target_label' => $entity_type->getLabel()]), 'base' => $entity_subqueue->getDataTable() ?: $entity_subqueue->getBaseTable(), 'entity_type' => 'entity_subqueue', 'base field' => $entity_subqueue->getKey('id'), 'field_name' => $field_storage->getName(), 'field table' => $subqueue_items_table_name, 'field field' => $columns['target_id'], ]; $data[$target_base_table]['entityqueue_relationship']['sort'] = array( 'id' => 'entity_queue_position', 'group' => t('Entityqueue'), 'title' => t('@target_label Queue Position', array( '@target_label' => $entity_type->getLabel(), )), 'label' => t('@target_label Queue Position', array( '@target_label' => $entity_type->getLabel(), )), 'help' => t('Position of item in the @target_label queue.', array( '@target_label' => $entity_type->getLabel(), )), 'field' => 'delta', 'field table' => $subqueue_items_table_name, 'field_name' => $field_name, ); $data[$target_base_table]['entityqueue_relationship']['filter'] = array( 'id' => 'entity_queue_in_queue', 'type' => 'yes-no', 'group' => t('Entityqueue'), 'title' => t('@target_label In Queue', array( '@target_label' => $entity_type->getLabel(), )), 'label' => t('@target_label In Queue', array( '@target_label' => $entity_type->getLabel(), )), 'help' => t('Filter for entities that are available or not in the @target_label entity queue.', array( '@target_label' => $entity_type->getLabel(), )), 'field table' => $subqueue_items_table_name, 'field field' => $columns['target_id'], ); } }