class GathercontentContentImportConfirmForm in GatherContent 8
Class GathercontentContentImportConfirmForm.
@package Drupal\gathercontent\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\gathercontent\Form\GathercontentMultistepFormBase
- class \Drupal\gathercontent\Form\GathercontentContentImportConfirmForm
- class \Drupal\gathercontent\Form\GathercontentMultistepFormBase
Expanded class hierarchy of GathercontentContentImportConfirmForm
1 string reference to 'GathercontentContentImportConfirmForm'
File
- src/
Form/ GathercontentContentImportConfirmForm.php, line 16
Namespace
Drupal\gathercontent\FormView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
GathercontentContentImportConfirmForm:: |
public | function |
Form constructor. Overrides GathercontentMultistepFormBase:: |
|
GathercontentContentImportConfirmForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
GathercontentContentImportConfirmForm:: |
public | function |
Form submission handler. Overrides GathercontentMultistepFormBase:: |
|
GathercontentMultistepFormBase:: |
protected | property | Drupal\Core\Datetime\DateFormatter definition. | |
GathercontentMultistepFormBase:: |
protected | property | ||
GathercontentMultistepFormBase:: |
protected | property | Drupal\Core\Entity\EntityManager definition. | |
GathercontentMultistepFormBase:: |
protected | property | ||
GathercontentMultistepFormBase:: |
protected | property | ||
GathercontentMultistepFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
GathercontentMultistepFormBase:: |
protected | function | Helper method that removes all the keys from the store collection used for the multistep form. | |
GathercontentMultistepFormBase:: |
protected | function | Saves the data from the multistep form. | |
GathercontentMultistepFormBase:: |
public | function | ||
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |