class GathercontentContentImportSelectForm in GatherContent 8
Class GathercontentContentImportSelectForm.
@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\GathercontentContentImportSelectForm
- class \Drupal\gathercontent\Form\GathercontentMultistepFormBase
Expanded class hierarchy of GathercontentContentImportSelectForm
1 string reference to 'GathercontentContentImportSelectForm'
File
- src/
Form/ GathercontentContentImportSelectForm.php, line 14
Namespace
Drupal\gathercontent\FormView source
class GathercontentContentImportSelectForm extends GathercontentMultistepFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'gathercontent_content_import_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$gc_module_path = drupal_get_path('module', 'gc');
$form = parent::buildForm($form, $form_state);
$created_mapping_ids = GathercontentMapping::loadMultiple();
$projects = array();
$mapping_array = array();
foreach ($created_mapping_ids as $mapping) {
/** @var $mapping GathercontentMapping */
if ($mapping
->hasMapping()) {
$projects[$mapping
->getGathercontentProjectId()] = $mapping
->getGathercontentProject();
$mapping_array[$mapping
->getGathercontentTemplateId()] = array(
'gc_template' => $mapping
->getGathercontentTemplate(),
'ct' => $mapping
->getContentTypeName(),
);
}
}
$form['project'] = array(
'#type' => 'select',
'#title' => t('Select project'),
'#options' => $projects,
'#empty_option' => t('- Select -'),
'#required' => TRUE,
'#ajax' => array(
'callback' => 'Drupal\\gathercontent\\Form\\GathercontentContentImportSelectForm::getContentTable',
'wrapper' => 'edit-import',
'method' => 'replace',
'effect' => 'fade',
),
'#default_value' => $this->store
->get('project_id') ? $this->store
->get('project_id') : 0,
'#description' => t('You can only see projects with mapped templates in the dropdown.'),
);
$form['import'] = array(
'#prefix' => '<div id="edit-import">',
'#suffix' => '</div>',
'#attached' => array(
'library' => array(
'gathercontent/filter',
),
),
);
$form['menu'] = array(
'#type' => 'value',
);
if ($form_state
->hasValue('project') || $this->store
->get('project_id')) {
$project_id = $form_state
->hasValue('project') ? $form_state
->getValue('project') : $this->store
->get('project_id');
$content_obj = new Content();
$content = $content_obj
->getContents($project_id);
$content_table = array();
foreach ($content as $item) {
// If template is not empty, we have mapped template and item
// isn't synced yet.
if (!is_null($item->template_id) && $item->template_id != 'null' && isset($mapping_array[$item->template_id])) {
// @FIXME
// menu_parent_options() is gone in Drupal 8. To generate or work with menu trees, you'll need to
// use the menu.link_tree service.
//
//
// @see https://www.drupal.org/node/2226481
// @see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Menu%21MenuLinkTree.php/class/MenuLinkTree/8
$content_table[$item->id] = array(
'status' => array(
'data' => '<div class="gc-item--status--color" style="background: ' . $item->status->data->color . ';"></div>' . $item->status->data->name,
'class' => array(
'gc-item',
'status-item',
),
),
'title' => array(
'data' => $item->name,
'class' => array(
'gc-item',
'gc-item--name',
),
),
'updated' => array(
'data' => date('F d, Y - H:i', strtotime($item->updated_at->date)),
'class' => array(
'gc-item',
'gc-item-date',
),
'data-date' => date('Y-m-d.H:i:s', strtotime($item->updated_at->date)),
),
'template' => array(
'data' => $mapping_array[$item->template_id]['gc_template'],
'class' => array(
'template-name-item',
),
),
);
}
}
$header = array(
'status' => t('Status'),
'title' => t('Item Name'),
'updated' => t('Last updated in GatherContent'),
'template' => t('GatherContent Template Name'),
);
$form['import']['content'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $content_table,
'#empty' => t('No content available.'),
// '#filterwrapper' => array(
// 'filter_wrapper' => array('gc-table--filter-wrapper', 'clearfix'),
// 'counter_wrapper' => array('gc-table--counter', 'clearfix'),
// ),
// '#filterdescription' => t('You can only see items with mapped templates in the table.'),
'#default_value' => $this->store
->get('nodes') ? $this->store
->get('nodes') : NULL,
);
// @FIXME
// l() expects a Url object, created from a route name or external URI.
// $form['import']['back_button'] = array(
// '#type' => 'markup',
// '#markup' => l(t('Back'), '/admin/config/gc/import', array('attributes' => array('class' => array('button')))),
// );
}
$form['actions']['submit']['#value'] = $this
->t('Next');
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->store
->set('project_id', $form_state
->getValue('project'));
$this->store
->set('nodes', array_filter($form_state
->getValue('content')));
$this->store
->set('menu', array_intersect_key(array_filter($form_state
->getValue('menu')), array_filter($form_state
->getValue('content'))));
$form_state
->setRedirect('gathercontent.import_confirm_form');
}
public function getContentTable(array &$form, FormStateInterface $form_state) {
$form_state
->setRebuild(TRUE);
return $form['import'];
}
}
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 |
GathercontentContentImportSelectForm:: |
public | function |
Form constructor. Overrides GathercontentMultistepFormBase:: |
|
GathercontentContentImportSelectForm:: |
public | function | ||
GathercontentContentImportSelectForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
GathercontentContentImportSelectForm:: |
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. |