You are here

class MigrationBase in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x modules/cms_content_sync_migrate_acquia_content_hub/src/Form/MigrationBase.php \Drupal\cms_content_sync_migrate_acquia_content_hub\Form\MigrationBase
  2. 2.0.x modules/cms_content_sync_migrate_acquia_content_hub/src/Form/MigrationBase.php \Drupal\cms_content_sync_migrate_acquia_content_hub\Form\MigrationBase

Content Sync advanced debug form.

Hierarchy

Expanded class hierarchy of MigrationBase

2 files declare their use of MigrationBase
cms_content_sync_migrate_acquia_content_hub.drush.inc in modules/cms_content_sync_migrate_acquia_content_hub/cms_content_sync_migrate_acquia_content_hub.drush.inc
Contains Drush commands for Content Sync.
CreateStatusEntities.php in modules/cms_content_sync_migrate_acquia_content_hub/src/CreateStatusEntities.php

File

modules/cms_content_sync_migrate_acquia_content_hub/src/Form/MigrationBase.php, line 22

Namespace

Drupal\cms_content_sync_migrate_acquia_content_hub\Form
View source
class MigrationBase extends FormBase {

  /**
   * The acquia content hub entity manager.
   *
   * @var \Drupal\acquia_contenthub\EntityManager
   */
  protected $acquiaEntityManager;

  /**
   * The entity type bundle info manager interface.
   *
   * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
   */
  protected $entityTypeBundleInfo;

  /**
   * The field type plugin manager.
   *
   * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
   */
  protected $fieldTypePluginManager;

  /**
   * The configuration factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The Drupal module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandler
   */
  protected $moduleHandler;

  /**
   * The core entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManager
   */
  protected $entityTypeManager;

  /**
   *
   */
  public static function getTermsFromFilter($tags) {
    if (empty($tags)) {
      return [];
    }
    $uuids = explode(',', $tags);
    $tags = [];
    foreach ($uuids as $uuid) {
      $terms = \Drupal::entityTypeManager()
        ->getStorage('taxonomy_term')
        ->loadByProperties([
        'uuid' => $uuid,
      ]);
      if (!count($terms)) {
        \Drupal::messenger()
          ->addMessage('Term ' . $uuid . ' could not be loaded and has been ignored.', 'warning');
        continue;
      }
      $term = reset($terms);
      $tags[] = $term;
    }
    return $tags;
  }

  /**
   * Create the pools based on the user selected terms.
   *
   * @param $pools
   * @param $backend_url
   * @param $authentication_type
   */
  public static function createPools($pools, $backend_url, $authentication_type) {
    foreach ($pools as $machine_name => $name) {
      Pool::createPool($name, $machine_name, $backend_url, $authentication_type);
    }
    \Drupal::messenger()
      ->addMessage('Content Sync Pools have been created.');
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'cms_content_sync_migrate_acquia_content_hub.migration_base';
  }

  /**
   * Constructs a new FieldStorageAddForm object.
   *
   * @param \Drupal\acquia_contenthub\EntityManager $acquia_entity_manager
   * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
   * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager
   *   The field type plugin manager.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration factory.
   *
   * @param \Drupal\Core\Extension\ModuleHandler $module_handler
   *
   * @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
   *
   * @internal param \Drupal\Core\Entity\EntityManagerInterface $entity_manager The entity manager.*   The entity manager.
   */
  public function __construct(EntityManager $acquia_entity_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, FieldTypePluginManagerInterface $field_type_plugin_manager, ConfigFactoryInterface $config_factory, ModuleHandler $module_handler, EntityTypeManager $entity_type_manager) {
    $this->acquiaEntityManager = $acquia_entity_manager;
    $this->entityTypeBundleInfo = $entity_type_bundle_info;
    $this->fieldTypePluginManager = $field_type_plugin_manager;
    $this->configFactory = $config_factory;
    $this->moduleHandler = $module_handler;
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('acquia_contenthub.entity_manager'), $container
      ->get('entity_type.bundle.info'), $container
      ->get('plugin.manager.field.field_type'), $container
      ->get('config.factory'), $container
      ->get('module_handler'), $container
      ->get('entity_type.manager'));
  }

  /**
   *
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['backend_url'] = [
      '#type' => 'url',
      '#title' => $this
        ->t('Sync Core URL'),
      '#required' => TRUE,
    ];
    $auth_options = [
      IApplicationInterface::AUTHENTICATION_TYPE_COOKIE => $this
        ->t("Standard (Cookie)"),
    ];
    if ($this->moduleHandler
      ->moduleExists('basic_auth')) {
      $auth_options[IApplicationInterface::AUTHENTICATION_TYPE_BASIC_AUTH] = $this
        ->t("Basic Auth");
    }
    $form['authentication_type'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Authentication'),
      '#description' => $this
        ->t(PoolForm::AUTHENTICATION_TYPE_DESCRIPTION),
      '#options' => $auth_options,
      '#required' => TRUE,
    ];
    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Create configuration'),
      '#button_type' => 'primary',
    ];
    return $form;
  }
  const DEFAULT_POOL_MACHINE_NAME = 'content';
  const DEFAULT_POOL = [
    self::DEFAULT_POOL_MACHINE_NAME => 'Content',
  ];

  /**
   *
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $content_hub_filter = '';
    if (isset($this->content_hub_filter)) {
      $content_hub_filter = $this->content_hub_filter;
    }
    if (!isset($this->migrationType)) {
      return;
    }

    // Create pools.
    MigratePush::createPools(self::DEFAULT_POOL, $form_state
      ->getValue('backend_url'), $form_state
      ->getValue('authentication_type'));
    if ($this->migrationType == 'push') {

      // Create flow.
      $flow = MigratePush::createFlow(MigrationBase::DEFAULT_POOL_MACHINE_NAME, $form_state
        ->getValue('node_push_behavior'), $form_state
        ->getValue('pull_updates_behavior'));
    }
    else {

      // Create flow.
      $flow = MigratePull::createFlow(MigrationBase::DEFAULT_POOL_MACHINE_NAME, $form_state
        ->getValue('node_push_behavior'), $form_state
        ->getValue('pull_updates_behavior'), $content_hub_filter);
    }

    // Create status entities.
    $create_status_entities = new CreateStatusEntities();
    $operations = $create_status_entities
      ->prepare($flow['flow_id'], $flow['flow_configuration'], MigrationBase::DEFAULT_POOL_MACHINE_NAME, $flow['type'], $content_hub_filter ? $content_hub_filter->tags : '');
    $batch = [
      'title' => t('Creating status entities'),
      'operations' => $operations,
    ];
    batch_set($batch);

    // Redirect user to flow form.
    $route_paramenters = [
      'cms_content_sync_flow' => $flow['flow_id'],
    ];
    $form_state
      ->setRedirect('entity.cms_content_sync_flow.edit_form', $route_paramenters);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
MigrationBase::$acquiaEntityManager protected property The acquia content hub entity manager.
MigrationBase::$configFactory protected property The configuration factory. Overrides FormBase::$configFactory
MigrationBase::$entityTypeBundleInfo protected property The entity type bundle info manager interface.
MigrationBase::$entityTypeManager protected property The core entity type manager.
MigrationBase::$fieldTypePluginManager protected property The field type plugin manager.
MigrationBase::$moduleHandler protected property The Drupal module handler.
MigrationBase::buildForm public function Form constructor. Overrides FormInterface::buildForm 2
MigrationBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create
MigrationBase::createPools public static function Create the pools based on the user selected terms.
MigrationBase::DEFAULT_POOL constant
MigrationBase::DEFAULT_POOL_MACHINE_NAME constant
MigrationBase::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId 2
MigrationBase::getTermsFromFilter public static function
MigrationBase::submitForm public function Form submission handler. Overrides FormInterface::submitForm
MigrationBase::__construct public function Constructs a new FieldStorageAddForm object. 2
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.