You are here

gathercontent_ui.module in GatherContent 8.5

Same filename and directory in other branches
  1. 8.4 gathercontent_ui/gathercontent_ui.module

GatherContent UI.

File

gathercontent_ui/gathercontent_ui.module
View source
<?php

/**
 * @file
 * GatherContent UI.
 */
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;

/**
 * Implements hook_entity_type_alter().
 */
function gathercontent_ui_entity_type_alter(array &$entity_types) {
  if (isset($entity_types['gathercontent_mapping'])) {
    $entity_types['gathercontent_mapping']
      ->setListBuilderClass('Drupal\\gathercontent_ui\\MappingListBuilder');
    $entity_types['gathercontent_mapping']
      ->setFormClass('default', 'Drupal\\gathercontent_ui\\Form\\MappingImportForm');
    $entity_types['gathercontent_mapping']
      ->setFormClass('add', 'Drupal\\gathercontent_ui\\Form\\MappingImportForm');
    $entity_types['gathercontent_mapping']
      ->setFormClass('edit', 'Drupal\\gathercontent_ui\\Form\\MappingEditForm');
    $entity_types['gathercontent_mapping']
      ->setFormClass('delete', 'Drupal\\gathercontent_ui\\Form\\MappingDeleteForm');
    $entity_types['gathercontent_mapping']
      ->setHandlerClass('route_provider', [
      'html' => 'Drupal\\gathercontent_ui\\MappingHtmlRouteProvider',
    ]);
    $entity_types['gathercontent_mapping']
      ->set('admin_permission', 'administer gathercontent');
    $entity_types['gathercontent_mapping']
      ->setLinkTemplate('canonical', '/admin/config/gathercontent/mapping/{gathercontent_mapping}');
    $entity_types['gathercontent_mapping']
      ->setLinkTemplate('add-form', '/admin/config/gathercontent/mapping/create');
    $entity_types['gathercontent_mapping']
      ->setLinkTemplate('edit-form', '/admin/config/gathercontent/mapping/{gathercontent_mapping}/edit');
    $entity_types['gathercontent_mapping']
      ->setLinkTemplate('delete-form', '/admin/config/gathercontent/mapping/{gathercontent_mapping}/delete');
    $entity_types['gathercontent_mapping']
      ->setLinkTemplate('collection', '/admin/config/gathercontent/mapping');
  }
}

/**
 * Finished callback.
 *
 * {@inheritdoc}
 */
function gathercontent_ui_import_finished($success, $results, $operations) {
  $messenger = \Drupal::messenger();
  if ($success) {
    if ($results['success'] > 0) {
      $messenger
        ->addStatus(\Drupal::translation()
        ->formatPlural($results['success'], '1 item was imported successfully.', '@count items were imported successfully.'));
    }
    if ($results['failed'] > 0) {
      $messenger
        ->addError(\Drupal::translation()
        ->formatPlural($results['failed'], '1 item was not imported. Check errors below.', '@count items were not imported. Check errors below.'));
    }
    if ($results['failed'] == 0 && $results['success'] == 0) {
      $messenger
        ->addStatus(t('Nothing was imported or updated.'));
    }
    if (isset($results['messages']) && count($results['messages']) > 0) {
      foreach ($results['messages'] as $message) {
        $messenger
          ->addError($message);
      }
    }
  }
  else {
    $error_operation = reset($operations);
    $messenger
      ->addError(t('An error occurred while processing @operation with arguments : @args', [
      '@operation' => $error_operation[0],
      '@args' => print_r($error_operation[0], TRUE),
    ]));
  }
  return new RedirectResponse(Url::fromRoute('gathercontent_ui.tracked_entities_list')
    ->toString());
}