You are here

class GathercontentContentImportConfirmForm in GatherContent 8

Class GathercontentContentImportConfirmForm.

@package Drupal\gathercontent\Form

Hierarchy

Expanded class hierarchy of GathercontentContentImportConfirmForm

1 string reference to 'GathercontentContentImportConfirmForm'
gathercontent.routing.yml in ./gathercontent.routing.yml
gathercontent.routing.yml

File

src/Form/GathercontentContentImportConfirmForm.php, line 16

Namespace

Drupal\gathercontent\Form
View source
class GathercontentContentImportConfirmForm extends GathercontentMultistepFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'gathercontent_content_confirm_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildForm($form, $form_state);
    $nodes = $this->store
      ->get('nodes');
    $form['title'] = array(
      'form_title' => array(
        '#type' => 'html_tag',
        '#tag' => 'h2',
        '#value' => \Drupal::translation()
          ->formatPlural(count($nodes), 'Confirm import selection (@count item)', 'Confirm import selection (@count items)'),
      ),
      'form_description' => array(
        '#type' => 'html_tag',
        '#tag' => 'p',
        '#value' => t('Please review your import selection before importing.'),
      ),
    );
    $header = array(
      'status' => t('Status'),
      'title' => t('Item name'),
      'template' => t('GatherContent Template'),
    );
    $options = array();
    $tmp_obj = new Template();
    $templates = $tmp_obj
      ->getTemplates($this->store
      ->get('project_id'));
    foreach ($nodes as $node) {
      $content_obj = new Content();
      $content = $content_obj
        ->getContent($node);
      $options[$content->id] = array(
        'status' => '<div style="width:20px; height: 20px; float: left; margin-right: 5px; background: ' . $content->status->data->color . ';"></div>' . $content->status->data->name,
        'title' => $content->name,
        'template' => $templates[$content->template_id],
      );
    }
    $form['table'] = array(
      '#type' => 'table',
      '#header' => $header,
      '#rows' => $options,
    );
    $options = array();
    $project_obj = new Project();
    $statuses = $project_obj
      ->getStatuses($this->store
      ->get('project_id'));
    foreach ($statuses as $status) {
      $options[$status->id] = $status->name;
    }
    $form['status'] = array(
      '#type' => 'select',
      '#options' => $options,
      '#title' => t('After successful import change status to:'),
      '#empty_option' => t("- Don't change status -"),
    );
    $form['actions']['submit']['#value'] = $this
      ->t('Import');
    $form['actions']['back'] = array(
      '#type' => 'submit',
      '#value' => $this
        ->t('Back'),
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    if ($form_state
      ->getTriggeringElement()['#id'] === 'edit-submit') {
      $operation = GathercontentOperation::create(array(
        'type' => 'import',
      ));
      $operation
        ->save();
      $operations = array();
      $stack = array();
      $import_content = $this->store
        ->get('nodes');
      foreach ($import_content as $k => $value) {
        if ($this->store
          ->get('menu')[$value] && $this->store
          ->get('menu')[$value] != -1) {
          $parent_menu_item = $this->store
            ->get('menu')[$value] ? $this->store
            ->get('menu')[$value] : NULL;
          $operations[] = array(
            'gc_import_process',
            array(
              $value,
              $form_state
                ->getValue('status'),
              $operation
                ->uuid(),
              $parent_menu_item,
            ),
          );
          $stack[] = $value;
          unset($import_content[$k]);
        }
      }
      if (!empty($import_content)) {

        // Load all by project_id.
        $first = reset($import_content);
        $content_obj = new Content();
        $content = $content_obj
          ->getContent($first);
        $contents_source = $content_obj
          ->getContents($content->project_id);
        $content = array();
        foreach ($contents_source as $value) {
          $content[$value->id] = $value;
        }
        while (!empty($import_content)) {
          $current = reset($import_content);
          if (isset($stack[$content[$current]->parent_id])) {
            $parent_menu_item = 'node:' . $content[$current]->parent_id;
            $operations[] = array(
              'gathercontent_import_process',
              array(
                $current,
                $form_state
                  ->getValue('status'),
                $operation
                  ->uuid(),
                $parent_menu_item,
              ),
            );
            $stack[] = $current;
            array_shift($import_content);
          }
          else {
            array_shift($import_content);
            array_push($import_content, $current);
          }
        }
      }
      $batch = array(
        'title' => t('Importing content ...'),
        'operations' => $operations,
        'finished' => 'gathercontent_import_finished',
        'file' => drupal_get_path('module', 'gathercontent') . '/gathercontent.module',
        'init_message' => t('Import is starting ...'),
        'progress_message' => t('Processed @current out of @total.'),
        'error_message' => t('An error occurred during processing'),
      );
      batch_set($batch);
    }
    else {
    }
  }

}

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::$configFactory protected property The config factory. 1
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
GathercontentContentImportConfirmForm::buildForm public function Form constructor. Overrides GathercontentMultistepFormBase::buildForm
GathercontentContentImportConfirmForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
GathercontentContentImportConfirmForm::submitForm public function Form submission handler. Overrides GathercontentMultistepFormBase::submitForm
GathercontentMultistepFormBase::$date_formatter protected property Drupal\Core\Datetime\DateFormatter definition.
GathercontentMultistepFormBase::$entityQuery protected property
GathercontentMultistepFormBase::$entity_manager protected property Drupal\Core\Entity\EntityManager definition.
GathercontentMultistepFormBase::$store protected property
GathercontentMultistepFormBase::$tempStoreFactory protected property
GathercontentMultistepFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create
GathercontentMultistepFormBase::deleteStore protected function Helper method that removes all the keys from the store collection used for the multistep form.
GathercontentMultistepFormBase::saveData protected function Saves the data from the multistep form.
GathercontentMultistepFormBase::__construct public function
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.
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.