You are here

content_synchronizer.module in Content Synchronizer 3.x

Same filename and directory in other branches
  1. 8.2 content_synchronizer.module
  2. 8 content_synchronizer.module

Hooks definitions for content_synchronizer module.

File

content_synchronizer.module
View source
<?php

/**
 * @file
 * Hooks definitions for content_synchronizer module.
 */
use Drupal\content_synchronizer\Service\EntityExportFormBuilder;
use Drupal\Core\Form\FormStateInterface;
use Drupal\content_synchronizer\Service\ExportManager;
use Drupal\content_synchronizer\Service\GlobalReferenceManager;
use Drupal\Core\Entity\EntityInterface;
use Drupal\content_synchronizer\Service\ArchiveDownloader;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\content_synchronizer\Entity\ImportEntity;

/**
 * Implements hook_help().
 */
function content_synchronizer_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the dillon module.
    case 'help.page.test_module':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Please check the module information page : <a href="//@dest">@dest</a>', [
        '@dest' => 'www.drupal.org/projects/content_synchronizer',
      ]) . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_theme().
 */
function content_synchronizer_theme($existing, $type, $theme, $path) {
  $items = [
    'entities_list_table' => [
      'variables' => [
        'entities' => NULL,
        'title' => NULL,
        'checkbox_name' => NULL,
        'status_or_bundle' => NULL,
      ],
    ],
  ];
  return $items;
}

/**
 * Implements hook_form_alter().
 */
function content_synchronizer_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  \Drupal::service(EntityExportFormBuilder::SERVICE_NAME)
    ->addExportFields($form, $form_state);
}

/**
 * Implements hook_entity_delete().
 */
function content_synchronizer_entity_delete(EntityInterface $entity) {
  \Drupal::service(GlobalReferenceManager::SERVICE_NAME)
    ->onEntityDelete($entity);
  \Drupal::service(ExportManager::SERVICE_NAME)
    ->onEntityDelete($entity);
}

/**
 * Implements hook_preprocess().
 */
function content_synchronizer_preprocess_page(&$vars) {
  \Drupal::service(ArchiveDownloader::SERVICE_NAME)
    ->donwloadArchive($vars);
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function content_synchronizer_form_import_entity_add_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $form[ImportEntity::FIELD_ARCHIVE]['widget'][0]['#upload_location'] = ImportEntity::ARCHIVE_DESTINATION;
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function content_synchronizer_form_import_entity_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $form[ImportEntity::FIELD_ARCHIVE]['widget'][0]['#upload_location'] = ImportEntity::ARCHIVE_DESTINATION;
}