class DynamicLayoutController in Dynamic Layouts 8
DynamicLayoutController class.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\dynamic_layouts\Controller\DynamicLayoutController
Expanded class hierarchy of DynamicLayoutController
File
- src/
Controller/ DynamicLayoutController.php, line 19
Namespace
Drupal\dynamic_layouts\ControllerView source
class DynamicLayoutController extends ControllerBase {
/**
* The form builder.
*
* @var \Drupal\Core\Form\FormBuilder
*/
protected $formBuilder;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity form builder.
*
* @var \Drupal\Core\Entity\EntityFormBuilderInterface
*/
protected $entityFormBuilder;
/**
* EditRowModalForm constructor.
*
* @param \Drupal\Core\Entity\EntityFormBuilderInterface $entity_form_builder
* The entity form builder.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Form\FormBuilder $formBuilder
* The form builder.
*/
public function __construct(EntityFormBuilderInterface $entity_form_builder, EntityTypeManagerInterface $entityTypeManager, FormBuilder $formBuilder) {
$this->entityTypeManager = $entityTypeManager;
$this->entityFormBuilder = $entity_form_builder;
$this->formBuilder = $formBuilder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.form_builder'), $container
->get('entity_type.manager'), $container
->get('form_builder'));
}
/**
* Checks access to add a new layout.
*/
public function access() {
$settings_created = FALSE;
/** @var \Drupal\dynamic_layouts\DynamicLayoutSettingsInterface $settings */
if (($settings = $this->entityTypeManager
->getStorage('dynamic_layout_settings')
->load('settings')) && $settings
->getFrontendLibrary()) {
$settings_created = TRUE;
}
return AccessResult::allowedIf($settings_created);
}
/**
* Callback for deleting a column.
*
* @param string $dynamic_layout_id
* The dynamic layout id.
* @param int $column_id
* The column id we need to delete.
* @param int $row_id
* The row number we need to delete the column.
*
* @return object
* The ajax response.
*/
public function deleteColumn($dynamic_layout_id, $column_id, $row_id) {
$response = new AjaxResponse();
/* @var \Drupal\dynamic_layouts\DynamicLayoutInterface $config_entity */
if ($config_entity = $this->entityTypeManager
->getStorage(Constants::DYNAMIC_LAYOUT)
->load($dynamic_layout_id)) {
// Delete the specific column from the config entity.
$config_entity
->deleteColumn($row_id, $column_id);
// Save the entity.
$config_entity
->save();
// Replace the layout form with newly updated values.
/* @var \Drupal\dynamic_layouts\Form\DynamicLayoutForm $layout_form */
$layout_form = $this->entityFormBuilder
->getForm($config_entity);
$response
->addCommand(new ReplaceCommand(Constants::DYNAMIC_LAYOUT_FORM_CLASS, $layout_form));
}
return $response;
}
/**
* Callback for adding a column.
*
* @param string $dynamic_layout_id
* The dynamic layout id.
* @param int $row_id
* The row number we need to delete the column.
*
* @return object
* The ajax response.
*/
public function addColumn($dynamic_layout_id, $row_id) {
$response = new AjaxResponse();
/* @var \Drupal\dynamic_layouts\DynamicLayoutInterface $config_entity */
if ($config_entity = $this->entityTypeManager
->getStorage(Constants::DYNAMIC_LAYOUT)
->load($dynamic_layout_id)) {
// Add a column to the config entity.
$config_entity
->addColumn($row_id);
// Save the entity.
$config_entity
->save();
// Replace the layout form with newly updated values.
/* @var \Drupal\dynamic_layouts\Form\DynamicLayoutForm $layout_form */
$layout_form = $this->entityFormBuilder
->getForm($config_entity);
$response
->addCommand(new ReplaceCommand(Constants::DYNAMIC_LAYOUT_FORM_CLASS, $layout_form));
}
return $response;
}
/**
* Callback for opening the modal form.
*
* @param string $dynamic_layout_id
* The dynamic layout id.
* @param int $row_id
* The row number we need to delete.
*
* @return object
* The ajax response.
*/
public function deleteRow($dynamic_layout_id, $row_id) {
$response = new AjaxResponse();
/* @var \Drupal\dynamic_layouts\DynamicLayoutInterface $config_entity */
if ($config_entity = $this->entityTypeManager
->getStorage(Constants::DYNAMIC_LAYOUT)
->load($dynamic_layout_id)) {
// Delete the specific row from the config entity.
$config_entity
->deleteRow($row_id);
// Save the entity.
$config_entity
->save();
// Replace the layout form with newly updated values.
/* @var \Drupal\dynamic_layouts\Form\DynamicLayoutForm $layout_form */
$layout_form = $this->entityFormBuilder
->getForm($config_entity);
$response
->addCommand(new ReplaceCommand(Constants::DYNAMIC_LAYOUT_FORM_CLASS, $layout_form));
}
return $response;
}
/**
* Callback for adding a row.
*
* @param string $dynamic_layout_id
* The dynamic layout id.
*
* @return object
* The ajax response.
*/
public function addRow($dynamic_layout_id) {
$response = new AjaxResponse();
/* @var \Drupal\dynamic_layouts\DynamicLayoutInterface $config_entity */
if ($config_entity = $this->entityTypeManager
->getStorage(Constants::DYNAMIC_LAYOUT)
->load($dynamic_layout_id)) {
// Add a row.
$config_entity
->addRow();
// Save the entity.
$config_entity
->save();
// Replace the layout form with newly updated values.
/* @var \Drupal\dynamic_layouts\Form\DynamicLayoutForm $layout_form */
$layout_form = $this->entityFormBuilder
->getForm($config_entity);
$response
->addCommand(new ReplaceCommand(Constants::DYNAMIC_LAYOUT_FORM_CLASS, $layout_form));
}
return $response;
}
/**
* Callback for opening the edit column modal form.
*/
public function openEditColumnModalForm() {
$response = new AjaxResponse();
// Get the modal form using the form builder.
$modal_form = $this->formBuilder
->getForm('Drupal\\dynamic_layouts\\Form\\EditColumnModalForm');
// Add an AJAX command to open a modal dialog with the form as the content.
$response
->addCommand(new OpenModalDialogCommand('Edit column', $modal_form, [
'width' => '800',
]));
return $response;
}
/**
* Callback for opening the modal form.
*/
public function openEditRowModalForm() {
$response = new AjaxResponse();
// Get the modal form using the form builder.
$modal_form = $this->formBuilder
->getForm('Drupal\\dynamic_layouts\\Form\\EditRowModalForm');
// Add an AJAX command to open a modal dialog with the form as the content.
$response
->addCommand(new OpenModalDialogCommand('Edit row', $modal_form, [
'width' => '800',
]));
return $response;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
DynamicLayoutController:: |
protected | property |
The entity form builder. Overrides ControllerBase:: |
|
DynamicLayoutController:: |
protected | property |
The entity type manager. Overrides ControllerBase:: |
|
DynamicLayoutController:: |
protected | property |
The form builder. Overrides ControllerBase:: |
|
DynamicLayoutController:: |
public | function | Checks access to add a new layout. | |
DynamicLayoutController:: |
public | function | Callback for adding a column. | |
DynamicLayoutController:: |
public | function | Callback for adding a row. | |
DynamicLayoutController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
DynamicLayoutController:: |
public | function | Callback for deleting a column. | |
DynamicLayoutController:: |
public | function | Callback for opening the modal form. | |
DynamicLayoutController:: |
public | function | Callback for opening the edit column modal form. | |
DynamicLayoutController:: |
public | function | Callback for opening the modal form. | |
DynamicLayoutController:: |
public | function | EditRowModalForm constructor. | |
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. |