class QuickEditController extends ControllerBase (View source)

Returns responses for Quick Edit module routes.

Traits

Wrapper methods for the logger factory service.

Provides a trait for the messenger service.

Wrapper methods for the Redirect Destination.

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Properties

protected LoggerChannelFactoryInterface $loggerFactory

The logger channel factory service.

from  LoggerChannelTrait
protected MessengerInterface $messenger

The messenger.

from  MessengerTrait
protected RedirectDestinationInterface $redirectDestination

The redirect destination service.

from  RedirectDestinationTrait
protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

from  ControllerBase
protected EntityFormBuilderInterface $entityFormBuilder

The entity form builder.

from  ControllerBase
protected LanguageManagerInterface $languageManager

The language manager.

from  ControllerBase
protected ConfigFactoryInterface $configFactory

The configuration factory.

from  ControllerBase
protected KeyValueStoreInterface $keyValue

The key-value storage.

from  ControllerBase
protected AccountInterface $currentUser

The current user service.

from  ControllerBase
protected StateInterface $stateService

The state service.

from  ControllerBase
protected ModuleHandlerInterface $moduleHandler

The module handler.

from  ControllerBase
protected FormBuilderInterface $formBuilder

The form builder.

from  ControllerBase
protected PrivateTempStoreFactory $tempStoreFactory

The PrivateTempStore factory.

protected MetadataGeneratorInterface $metadataGenerator

The in-place editing metadata generator.

protected EditorSelectorInterface $editorSelector

The in-place editor selector.

protected RendererInterface $renderer

The renderer.

protected EntityDisplayRepositoryInterface $entityDisplayRepository

The entity display repository service.

protected EntityRepositoryInterface $entityRepository

The entity repository.

Methods

LoggerInterface
getLogger(string $channel)

Gets the logger for a specific channel.

$this
setLoggerFactory(LoggerChannelFactoryInterface $logger_factory)

Injects the logger channel factory.

setMessenger(MessengerInterface $messenger)

Sets the messenger.

messenger()

Gets the messenger.

array
getDestinationArray()

Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.

getRedirectDestination()

Returns the redirect destination service.

$this
setRedirectDestination(RedirectDestinationInterface $redirect_destination)

Sets the redirect destination service.

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

entityTypeManager()

Retrieves the entity type manager.

entityFormBuilder()

Retrieves the entity form builder.

cache(string $bin = 'default')

Returns the requested cache bin.

config(string $name)

Retrieves a configuration object.

keyValue(string $collection)

Returns a key/value storage collection.

state()

Returns the state storage service.

moduleHandler()

Returns the module handler.

formBuilder()

Returns the form builder service.

currentUser()

Returns the current user.

languageManager()

Returns the language manager service.

RedirectResponse
redirect(string $route_name, array $route_parameters = [], array $options = [], int $status = 302)

Returns a redirect response object for the specified route.

__construct(PrivateTempStoreFactory $temp_store_factory, MetadataGeneratorInterface $metadata_generator, EditorSelectorInterface $editor_selector, RendererInterface $renderer, EntityDisplayRepositoryInterface $entity_display_repository, EntityRepositoryInterface $entity_repository)

Constructs a new QuickEditController.

JsonResponse
metadata(Request $request)

Returns the metadata for a set of fields.

attachments(Request $request)

Returns AJAX commands to load in-place editors' attachments.

fieldForm(EntityInterface $entity, string $field_name, string $langcode, string $view_mode_id, Request $request)

Returns a single field edit form as an Ajax response.

renderField(EntityInterface $entity, string $field_name, string $langcode, string $view_mode_id)

Renders a field.

entitySave(EntityInterface $entity)

Saves an entity into the database, from PrivateTempStore.

Details

protected LoggerInterface getLogger(string $channel)

Gets the logger for a specific channel.

Require the use of injected services: https://www.drupal.org/node/2733703

Parameters

string $channel

The name of the channel. Can be any string, but the general practice is to use the name of the subsystem calling this.

Return Value

LoggerInterface

The logger for the given channel.

$this setLoggerFactory(LoggerChannelFactoryInterface $logger_factory)

Injects the logger channel factory.

Parameters

LoggerChannelFactoryInterface $logger_factory

The logger channel factory service.

Return Value

$this

setMessenger(MessengerInterface $messenger)

Sets the messenger.

Parameters

MessengerInterface $messenger

The messenger.

MessengerInterface messenger()

Gets the messenger.

Return Value

MessengerInterface

The messenger.

protected array getDestinationArray()

Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.

Return Value

array

An associative array containing the key:

  • destination: The value of the current request's 'destination' query parameter, if present. This can be either a relative or absolute URL. However, for security, redirection to external URLs is not performed. If the query parameter isn't present, then the URL of the current request is returned.

See also

RedirectDestinationInterface::getAsArray

protected RedirectDestinationInterface getRedirectDestination()

Returns the redirect destination service.

Return Value

RedirectDestinationInterface

The redirect destination helper.

$this setRedirectDestination(RedirectDestinationInterface $redirect_destination)

Sets the redirect destination service.

Parameters

RedirectDestinationInterface $redirect_destination

The redirect destination service.

Return Value

$this

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

static create(ContainerInterface $container)

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this instance should use.

protected EntityTypeManagerInterface entityTypeManager()

Retrieves the entity type manager.

Return Value

EntityTypeManagerInterface

The entity type manager.

protected EntityFormBuilderInterface entityFormBuilder()

Retrieves the entity form builder.

Return Value

EntityFormBuilderInterface

The entity form builder.

protected CacheBackendInterface cache(string $bin = 'default')

Returns the requested cache bin.

Parameters

string $bin

(optional) The cache bin for which the cache object should be returned, defaults to 'default'.

Return Value

CacheBackendInterface

The cache object associated with the specified bin.

protected Config config(string $name)

Retrieves a configuration object.

This is the main entry point to the configuration API. Calling

Parameters

string $name

The name of the configuration object to retrieve. The name corresponds to a configuration file. For @code \Drupal::config('book.admin') @endcode, the config object returned will contain the contents of book.admin configuration file.

Return Value

Config

A configuration object.

protected KeyValueStoreInterface keyValue(string $collection)

Returns a key/value storage collection.

Parameters

string $collection

Name of the key/value collection to return.

Return Value

KeyValueStoreInterface

protected StateInterface state()

Returns the state storage service.

Use this to store machine-generated data, local to a specific environment that does not need deploying and does not need human editing; for example, the last time cron was run. Data which needs to be edited by humans and needs to be the same across development, production, etc. environments (for example, the system maintenance message) should use config() instead.

Return Value

StateInterface

protected ModuleHandlerInterface moduleHandler()

Returns the module handler.

Return Value

ModuleHandlerInterface

protected FormBuilderInterface formBuilder()

Returns the form builder service.

Return Value

FormBuilderInterface

protected AccountInterface currentUser()

Returns the current user.

Return Value

AccountInterface

The current user.

protected LanguageManagerInterface languageManager()

Returns the language manager service.

Return Value

LanguageManagerInterface

The language manager.

protected RedirectResponse redirect(string $route_name, array $route_parameters = [], array $options = [], int $status = 302)

Returns a redirect response object for the specified route.

Parameters

string $route_name

The name of the route to which to redirect.

array $route_parameters

(optional) Parameters for the route.

array $options

(optional) An associative array of additional options.

int $status

(optional) The HTTP redirect status code for the redirect. The default is 302 Found.

Return Value

RedirectResponse

A redirect response object that may be returned by the controller.

__construct(PrivateTempStoreFactory $temp_store_factory, MetadataGeneratorInterface $metadata_generator, EditorSelectorInterface $editor_selector, RendererInterface $renderer, EntityDisplayRepositoryInterface $entity_display_repository, EntityRepositoryInterface $entity_repository)

Constructs a new QuickEditController.

Parameters

PrivateTempStoreFactory $temp_store_factory

The PrivateTempStore factory.

MetadataGeneratorInterface $metadata_generator

The in-place editing metadata generator.

EditorSelectorInterface $editor_selector

The in-place editor selector.

RendererInterface $renderer

The renderer.

EntityDisplayRepositoryInterface $entity_display_repository

The entity display repository service.

EntityRepositoryInterface $entity_repository

The entity repository.

JsonResponse metadata(Request $request)

Returns the metadata for a set of fields.

Given a list of field quick edit IDs as POST parameters, run access checks on the entity and field level to determine whether the current user may edit them. Also retrieves other metadata.

Parameters

Request $request

Return Value

JsonResponse

The JSON response.

AjaxResponse attachments(Request $request)

Returns AJAX commands to load in-place editors' attachments.

Given a list of in-place editor IDs as POST parameters, render AJAX commands to load those in-place editors.

Parameters

Request $request

Return Value

AjaxResponse

The Ajax response.

AjaxResponse fieldForm(EntityInterface $entity, string $field_name, string $langcode, string $view_mode_id, Request $request)

Returns a single field edit form as an Ajax response.

Parameters

EntityInterface $entity

The entity being edited.

string $field_name

The name of the field that is being edited.

string $langcode

The name of the language for which the field is being edited.

string $view_mode_id

The view mode the field should be rerendered in.

Request $request

The current request object containing the search string.

Return Value

AjaxResponse

The Ajax response.

protected MarkupInterface renderField(EntityInterface $entity, string $field_name, string $langcode, string $view_mode_id)

Renders a field.

If the view mode ID is not an Entity Display view mode ID, then the field was rendered using a custom render pipeline (not the Entity/Field API render pipeline).

An example could be Views' render pipeline. In that case, the view mode ID would probably contain the View's ID, display and the row index.

Parameters

EntityInterface $entity

The entity being edited.

string $field_name

The name of the field that is being edited.

string $langcode

The name of the language for which the field is being edited.

string $view_mode_id

The view mode the field should be rerendered in. Either an Entity Display view mode ID, or a custom one. See hook_quickedit_render_field().

Return Value

MarkupInterface

Rendered HTML.

See also

hook_quickedit_render_field()

AjaxResponse entitySave(EntityInterface $entity)

Saves an entity into the database, from PrivateTempStore.

Parameters

EntityInterface $entity

The entity being edited.

Return Value

AjaxResponse

The Ajax response.