clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
<?php
namespace Drupal\entity_browser\Controllers;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\AlertCommand;
use Drupal\Core\Ajax\CloseDialogCommand;
use Drupal\Core\Ajax\OpenDialogCommand;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormState;
use Drupal\entity_browser\Ajax\ValueUpdatedCommand;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
/**
* Returns responses for entity browser routes.
*/
class EntityBrowserController extends ControllerBase {
/**
* Return an Ajax dialog command for editing a referenced entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* An entity being edited.
* @param \Symfony\Component\HttpFoundation\Request $request
* The currently processing request.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An Ajax response with a command for opening or closing the dialog
* containing the edit form.
*/
public function entityBrowserEdit(EntityInterface $entity, Request $request) {
$trigger_name = $request->request->get('_triggering_element_name');
$edit_button = (strpos($trigger_name, 'edit_button') !== FALSE);
if ($edit_button) {
// Remove posted values from original form to prevent
// data leakage into this form when the form is of the same bundle.
$original_request = $request->request;
$request->request = new InputBag();
}
// Use edit form class if it exists, otherwise use default form class.
$entity_type = $entity->getEntityType();
if ($entity_type->getFormClass('edit')) {
$operation = 'edit';
}
elseif ($entity_type->getFormClass('default')) {
$operation = 'default';
}
if (!empty($operation)) {
// Build the entity edit form.
$form_object = $this->entityTypeManager()->getFormObject($entity->getEntityTypeId(), $operation);
$form_object->setEntity($entity);
$form_state = (new FormState())
->setFormObject($form_object)
->disableRedirect();
// Building the form also submits.
$form = $this->formBuilder()->buildForm($form_object, $form_state);
}
// Restore original request now that the edit form is built.
// This fixes a bug where closing modal and re-opening it would
// cause two modals to open.
if ($edit_button) {
$request->request = $original_request;
}
// Return a response, depending on whether it's successfully submitted.
if ($operation && $form_state && !$form_state->isExecuted()) {
// Return the form as a modal dialog.
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$title = $this->t('Edit @entity', ['@entity' => $entity->label()]);
$response = (new AjaxResponse())->addCommand(new OpenDialogCommand('#' . $entity->getEntityTypeId() . '-' . $entity->id() . '-edit-dialog', $title, $form, ['modal' => TRUE, 'width' => '92%', 'dialogClass' => 'entity-browser-modal']));
return $response;
}
else {
// Return command for closing the modal.
$response = (new AjaxResponse())->addCommand(new CloseDialogCommand('#' . $entity->getEntityTypeId() . '-' . $entity->id() . '-edit-dialog'));
// Also refresh the widget if "details_id" is provided.
$details_id = $request->query->get('details_id');
if (!empty($details_id)) {
$response->addCommand(new ValueUpdatedCommand($details_id));
if (empty($operation)) {
$response->addCommand(new AlertCommand($this->t("An edit form couldn't be found.")));
}
}
return $response;
}
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace Drupal\entity_browser\Controllers;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\HtmlFormController;
use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
/**
* Standalone entity browser page.
*/
class EntityBrowserFormController extends HtmlFormController implements ContainerInjectionInterface {
/**
* Current route match service.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $currentRouteMatch;
/**
* The browser storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $browserStorage;
/**
* Current request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* Constructs Entity browser form controller.
*
* @param \Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface $argument_resolver
* The argument resolver.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
* @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
* The class resolver.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* Current route match service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager service.
* @param \Symfony\Component\HttpFoundation\Request $request
* Current request.
*/
public function __construct(ArgumentResolverInterface $argument_resolver, FormBuilderInterface $form_builder, ClassResolverInterface $class_resolver, RouteMatchInterface $route_match, EntityTypeManagerInterface $entity_type_manager, Request $request) {
parent::__construct($argument_resolver, $form_builder, $class_resolver);
$this->currentRouteMatch = $route_match;
$this->browserStorage = $entity_type_manager->getStorage('entity_browser');
$this->request = $request;
$this->formBuilder = $form_builder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('http_kernel.controller.argument_resolver'),
$container->get('form_builder'),
$container->get('class_resolver'),
$container->get('current_route_match'),
$container->get('entity_type.manager'),
$container->get('request_stack')->getCurrentRequest()
);
}
/**
* {@inheritdoc}
*/
protected function getFormObject(RouteMatchInterface $route_match, $form_arg) {
$browser = $this->loadBrowser();
if ($original_path = $this->request->get('original_path')) {
$browser->addAdditionalWidgetParameters(['path_parts' => explode('/', $original_path)]);
}
return $browser->getFormObject();
}
/**
* Standalone entity browser title callback.
*/
public function title() {
$browser = $this->loadBrowser();
return Xss::filter($browser->label());
}
/**
* Loads entity browser object for this page.
*
* @return \Drupal\entity_browser\EntityBrowserInterface
* Loads the entity browser object
*/
protected function loadBrowser() {
/* @var $route \Symfony\Component\Routing\Route */
$route = $this->currentRouteMatch->getRouteObject();
/* @var $browser \Drupal\entity_browser\EntityBrowserInterface */
return $this->browserStorage->load($route->getDefault('entity_browser_id'));
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Drupal\entity_browser\Controllers;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
/**
* Provides a list controller for entity browser.
*
* @ingroup entity_browser
*/
class EntityBrowserListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
*
* Building the header and content lines for the entity browser list.
*
* Calling the parent::buildHeader() adds a column for the possible actions
* and inserts the 'edit' and 'delete' links as defined for the entity type.
*/
public function buildHeader() {
$header['id'] = $this->t('ID');
$header['name'] = $this->t('Name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\entity_browser\Entity\EntityBrowser */
$row['id'] = $entity->id();
$row['name'] = $entity->label();
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
protected function getDefaultOperations(EntityInterface $entity) {
if ($entity->access('update')) {
$operations['edit'] = [
'title' => $this->t('Edit'),
'url' => $entity->toUrl('edit-form'),
];
}
$operations['edit-widgets'] = [
'title' => $this->t('Edit Widgets'),
'url' => $entity->toUrl('edit-widgets'),
];
if ($entity->access('delete')) {
$operations['delete'] = [
'title' => $this->t('Delete'),
'url' => $entity->toUrl('delete-form'),
'weight' => 100,
];
}
return $operations;
}
}