Skip to content
Snippets Groups Projects
Commit 9ddecbef authored by Den's avatar Den Committed by Bohdan Minich
Browse files

Issue #3337102 by Chester_, Panchuk, boddy: Configurations off-canvas: route and form

parent e6e3598e
Branches
Tags
1 merge request!15Issue #3337102: Configurations off-canvas: route and form
administer paragraphs gridstack:
title: "Administer Gridstack Optionsets settings"
administer paragraphs gridstack styles:
title: "Administer Gridstack Optionsets styles settings"
......@@ -36,3 +36,12 @@ entity.paragraphs_gridstack.delete_form:
_entity_form: paragraphs_gridstack.delete
requirements:
_entity_access: paragraphs_gridstack.delete
# This is the router item for manage styles of the GridStack Items.
entity.paragraphs_gridstack.manage_styles:
path: "/admin/paragraphs-gridstack/manage/{paragraphs_gridstack}/style-off-canvas"
defaults:
_title: "Get css styles for Gridstack Optionset"
_entity_form: paragraphs_gridstack.manage_styles
requirements:
_permission: "administer paragraphs gridstack styles"
......@@ -41,7 +41,8 @@ use Drupal\Core\Entity\Annotation\ConfigEntityType;
* "form" = {
* "add" = "Drupal\paragraphs_gridstack\Form\ParagraphsGridstackAddForm",
* "edit" = "Drupal\paragraphs_gridstack\Form\ParagraphsGridstackEditForm",
* "delete" = "Drupal\paragraphs_gridstack\Form\ParagraphsGridstackDeleteForm"
* "delete" = "Drupal\paragraphs_gridstack\Form\ParagraphsGridstackDeleteForm",
* "manage_styles" = "Drupal\paragraphs_gridstack\Form\ParagraphsGridstackManageStyles"
* }
* },
* config_prefix = "optionset",
......
<?php
namespace Drupal\paragraphs_gridstack\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\paragraphs_gridstack\GridstackBreakpointsManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class ParagraphsGridstackEditForm.
*
* Provides the edit form for our ParagraphsGridstack optionset entity.
*/
class ParagraphsGridstackManageStyles extends EntityForm {
/**
* An entity query factory for the ParagraphsGridstack entity type.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected EntityStorageInterface $entityStorage;
/**
* Gridstack Manager for the breakpoints.
*
* @var \Drupal\paragraphs_gridstack\GridstackBreakpointsManagerInterface
*/
protected GridstackBreakpointsManagerInterface $gridstackBreakpointsManager;
/**
* Construct the ParagraphsGridstackFormBase.
*
* For simple entity forms, there's no need for a constructor. Our form
* base, however, requires an entity query factory to be injected into it
* from the container. We later use this query factory to build an entity
* query for the exists() method.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
* An entity query factory for the ParagraphsGridstack entity type.
*/
public function __construct(EntityStorageInterface $entity_storage, GridstackBreakpointsManagerInterface $gridstack_breakpoints_manager) {
$this->entityStorage = $entity_storage;
$this->gridstackBreakpointsManager = $gridstack_breakpoints_manager;
}
/**
* Factory method for ParagraphsGridstackFormBase.
*
* When Drupal builds this class it does not call the constructor directly.
* Instead, it relies on this method to build the new object. Why? The class
* constructor may take multiple arguments that are unknown to Drupal. The
* create() method always takes one parameter -- the container. The purpose
* of the create() method is twofold: It provides a standard way for Drupal
* to construct the object, meanwhile it provides you a place to get needed
* constructor parameters from the container.
*
* In this case, we ask the container for an entity query factory. We then
* pass the factory to our class as a constructor parameter.
*/
public static function create(ContainerInterface $container) {
$form = new static(
$container->get('entity_type.manager')->getStorage('paragraphs_gridstack'),
$container->get('paragraphs_gridstack.breakpoints_manager'),
);
$form->setMessenger($container->get('messenger'));
return $form;
}
/**
* Overrides Drupal\Core\Entity\EntityFormController::form().
*
* Builds the entity manage styles form.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* An associative array containing the current state of the form.
*
* @return array
* An associative array containing the ParagraphsGridstack manage styles form.
*/
function buildForm(array $form, FormStateInterface $form_state) {
// Build the form.
$form['classes'] = [
'#type' => 'textfield',
'#title' => $this->t('Css classes'),
'#maxlength' => 255,
'#size' => 100,
'#description' => $this->t('Place your css class, if you need multiple styles use: (.d-flex .flex-column)'),
];
//@todo Create correct #options.
$options= [];
$form['options'] = [
'#type' => 'select',
'#title' => $this->t('Choose style options'),
'#options' => $options,
'#description' => $this->t('What options you choose?'),
];
// Return the form.
return $form;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment