Chris@0: currentRouteMatch = $current_route_match; Chris@0: $this->migrationConfigEntityPluginManager = $migration_config_entity_plugin_manager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { Chris@0: return new static( Chris@0: $entity_type, Chris@0: $container->get('entity.manager')->getStorage($entity_type->id()), Chris@0: $container->get('current_route_match'), Chris@0: $container->get('plugin.manager.config_entity_migration') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Builds the header row for the entity listing. Chris@0: * Chris@0: * @return array Chris@0: * A render array structure of header strings. Chris@0: * Chris@0: * @see Drupal\Core\Entity\EntityListController::render() Chris@0: */ Chris@0: public function buildHeader() { Chris@0: $header['label'] = $this->t('Migration'); Chris@0: $header['machine_name'] = $this->t('Machine Name'); Chris@0: $header['status'] = $this->t('Status'); Chris@0: $header['total'] = $this->t('Total'); Chris@0: $header['imported'] = $this->t('Imported'); Chris@0: $header['unprocessed'] = $this->t('Unprocessed'); Chris@0: $header['messages'] = $this->t('Messages'); Chris@0: $header['last_imported'] = $this->t('Last Imported'); Chris@0: return $header; // + parent::buildHeader(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Builds a row for a migration plugin. Chris@0: * Chris@0: * @param \Drupal\Core\Entity\EntityInterface $migration Chris@0: * The migration plugin for which to build the row. Chris@0: * Chris@0: * @return array Chris@0: * A render array of the table row for displaying the plugin information. Chris@0: * Chris@0: * @see Drupal\Core\Entity\EntityListController::render() Chris@0: */ Chris@0: public function buildRow(EntityInterface $migration_entity) { Chris@0: $migration = $this->migrationConfigEntityPluginManager->createInstance($migration_entity->id()); Chris@0: $row['label'] = $migration->label(); Chris@0: $row['machine_name'] = $migration->id(); Chris@0: $row['status'] = $migration->getStatusLabel(); Chris@0: Chris@0: // Derive the stats. Chris@0: $source_plugin = $migration->getSourcePlugin(); Chris@0: $row['total'] = $source_plugin->count(); Chris@0: $map = $migration->getIdMap(); Chris@0: $row['imported'] = $map->importedCount(); Chris@0: // -1 indicates uncountable sources. Chris@0: if ($row['total'] == -1) { Chris@0: $row['total'] = $this->t('N/A'); Chris@0: $row['unprocessed'] = $this->t('N/A'); Chris@0: } Chris@0: else { Chris@0: $row['unprocessed'] = $row['total'] - $map->processedCount(); Chris@0: } Chris@0: $migration_group = $migration->get('migration_group'); Chris@0: if (!$migration_group) { Chris@0: $migration_group = 'default'; Chris@0: } Chris@0: $route_parameters = array( Chris@0: 'migration_group' => $migration_group, Chris@0: 'migration' => $migration->id() Chris@0: ); Chris@0: $row['messages'] = array( Chris@0: 'data' => array( Chris@0: '#type' => 'link', Chris@0: '#title' => $map->messageCount(), Chris@0: '#url' => Url::fromRoute("migrate_tools.messages", $route_parameters), Chris@0: ), Chris@0: ); Chris@0: $migrate_last_imported_store = \Drupal::keyValue('migrate_last_imported'); Chris@0: $last_imported = $migrate_last_imported_store->get($migration->id(), FALSE); Chris@0: if ($last_imported) { Chris@0: /** @var DateFormatter $date_formatter */ Chris@0: $date_formatter = \Drupal::service('date.formatter'); Chris@0: $row['last_imported'] = $date_formatter->format($last_imported / 1000, Chris@0: 'custom', 'Y-m-d H:i:s'); Chris@0: } Chris@0: else { Chris@0: $row['last_imported'] = ''; Chris@0: } Chris@0: return $row + parent::buildRow($migration_entity); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getDefaultOperations(EntityInterface $entity) { Chris@0: $operations = parent::getDefaultOperations($entity); Chris@0: $migration_group = $entity->get('migration_group'); Chris@0: if (!$migration_group) { Chris@0: $migration_group = 'default'; Chris@0: } Chris@0: // $this->addGroupParameter($operations['edit']['url'], $migration_group); Chris@0: // $this->addGroupParameter($operations['delete']['url'], $migration_group); Chris@0: return $operations; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @param \Drupal\Core\Url $url Chris@0: * The URL associated with an operation. Chris@0: * Chris@0: * @param $migration_group Chris@0: * The migration's parent group. Chris@0: */ Chris@0: protected function addGroupParameter(Url $url, $migration_group) { Chris@0: if (!$migration_group) { Chris@0: $migration_group = 'default'; Chris@0: } Chris@0: $route_parameters = $url->getRouteParameters() + ['migration_group' => $migration_group]; Chris@0: $url->setRouteParameters($route_parameters); Chris@0: } Chris@0: Chris@0: }