class YamlFormSubmissionViewBuilder in YAML Form 8
Render controller for form submissions.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityViewBuilder implements EntityHandlerInterface, EntityViewBuilderInterface, TrustedCallbackInterface uses DeprecatedServicePropertyTrait
- class \Drupal\yamlform\YamlFormSubmissionViewBuilder implements YamlFormSubmissionViewBuilderInterface
- class \Drupal\Core\Entity\EntityViewBuilder implements EntityHandlerInterface, EntityViewBuilderInterface, TrustedCallbackInterface uses DeprecatedServicePropertyTrait
Expanded class hierarchy of YamlFormSubmissionViewBuilder
File
- src/
YamlFormSubmissionViewBuilder.php, line 18
Namespace
Drupal\yamlformView source
class YamlFormSubmissionViewBuilder extends EntityViewBuilder implements YamlFormSubmissionViewBuilderInterface {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The token handler.
*
* @var \Drupal\Core\Utility\Token
*/
protected $token;
/**
* Form request handler.
*
* @var \Drupal\yamlform\YamlFormRequestInterface
*/
protected $requestManager;
/**
* The form handler manager service.
*
* @var \Drupal\yamlform\YamlFormHandlerManagerInterface
*/
protected $handlerManager;
/**
* The form element manager service.
*
* @var \Drupal\yamlform\YamlFormElementManagerInterface
*/
protected $elementManager;
/**
* Constructs a new YamlFormSubmissionViewBuilder.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Utility\Token $token
* The token handler.
* @param \Drupal\yamlform\YamlFormRequestInterface $yamlform_request
* The form request handler.
* @param \Drupal\yamlform\YamlFormHandlerManagerInterface $handler_manager
* The form handler manager service.
* @param \Drupal\yamlform\YamlFormElementManagerInterface $element_manager
* The form element manager service.
*/
public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory, Token $token, YamlFormRequestInterface $yamlform_request, YamlFormHandlerManagerInterface $handler_manager, YamlFormElementManagerInterface $element_manager) {
parent::__construct($entity_type, $entity_manager, $language_manager);
$this->configFactory = $config_factory;
$this->token = $token;
$this->requestManager = $yamlform_request;
$this->handlerManager = $handler_manager;
$this->elementManager = $element_manager;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity.manager'), $container
->get('language_manager'), $container
->get('config.factory'), $container
->get('token'), $container
->get('yamlform.request'), $container
->get('plugin.manager.yamlform.handler'), $container
->get('plugin.manager.yamlform.element'));
}
/**
* {@inheritdoc}
*/
public function buildComponents(array &$build, array $entities, array $displays, $view_mode) {
/** @var \Drupal\yamlform\YamlFormSubmissionInterface[] $entities */
/** @var \Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission */
if (empty($entities)) {
return;
}
$source_entity = $this->requestManager
->getCurrentSourceEntity('yamlform_submission');
parent::buildComponents($build, $entities, $displays, $view_mode);
// If the view mode is default then display the HTML version.
if ($view_mode == 'default') {
$view_mode = 'html';
}
// Build submission display.
foreach ($entities as $id => $yamlform_submission) {
$build[$id]['submission'] = [
'#theme' => 'yamlform_submission_' . $view_mode,
'#yamlform_submission' => $yamlform_submission,
'#source_entity' => $source_entity,
];
}
}
/**
* {@inheritdoc}
*/
public function buildElements(array $elements, array $data, array $options = [], $format = 'html') {
$build_method = 'build' . ucfirst($format);
$build = [];
foreach ($elements as $key => $element) {
if (!is_array($element) || Element::property($key) || !$this
->isVisibleElement($element) || isset($options['excluded_elements'][$key])) {
continue;
}
$plugin_id = $this->elementManager
->getElementPluginId($element);
/** @var \Drupal\yamlform\YamlFormElementInterface $yamlform_element */
$yamlform_element = $this->elementManager
->createInstance($plugin_id);
// Check element view access.
if (!$yamlform_element
->checkAccessRules('view', $element)) {
continue;
}
if ($yamlform_element
->isContainer($element)) {
$children = $this
->buildElements($element, $data, $options, $format);
if ($children) {
// Add #first and #last property to $children.
// This is used to remove return from #last with multiple lines of
// text.
// @see yamlform-element-base-text.html.twig
reset($children);
$first_key = key($children);
if (isset($children[$first_key]['#options'])) {
$children[$first_key]['#options']['first'] = TRUE;
}
end($children);
$last_key = key($children);
if (isset($children[$last_key]['#options'])) {
$children[$last_key]['#options']['last'] = TRUE;
}
}
// Build the container but make sure it is not empty. Containers
// (ie details, fieldsets, etc...) without children will be empty
// but markup should always be rendered.
if ($build_container = $yamlform_element
->{$build_method}($element, $children, $options)) {
$build[$key] = $build_container;
}
}
else {
$value = isset($data[$key]) ? $data[$key] : NULL;
if ($build_element = $yamlform_element
->{$build_method}($element, $value, $options)) {
$build[$key] = $build_element;
}
}
}
return $build;
}
/**
* {@inheritdoc}
*/
public function buildTable(array $elements, array $data, array $options = []) {
$rows = [];
foreach ($elements as $key => $element) {
if (isset($options['excluded_elements'][$key])) {
continue;
}
$plugin_id = $this->elementManager
->getElementPluginId($element);
/** @var \Drupal\yamlform\YamlFormElementInterface $yamlform_element */
$yamlform_element = $this->elementManager
->createInstance($plugin_id);
// Check element view access.
if (!$yamlform_element
->checkAccessRules('view', $element)) {
continue;
}
$title = $element['#admin_title'] ?: $element['#title'] ?: '(' . $key . ')';
$value = isset($data[$key]) ? $yamlform_element
->formatHtml($element, $data[$key], $options) : '';
$rows[] = [
[
'header' => TRUE,
'data' => $title,
],
[
'data' => is_string($value) ? [
'#markup' => $value,
] : $value,
],
];
}
return [
'#type' => 'table',
'#rows' => $rows,
'#attributes' => [
'class' => [
'yamlform-submission__table',
],
],
];
}
/**
* Determines if an element is visible.
*
* Copied from: \Drupal\Core\Render\Element::isVisibleElement
* but does not hide hidden or value elements.
*
* @param array $element
* The element to check for visibility.
*
* @return bool
* TRUE if the element is visible, otherwise FALSE.
*/
protected function isVisibleElement(array $element) {
return !isset($element['#access']) || ($element['#access'] instanceof AccessResultInterface && $element['#access']
->isAllowed() || $element['#access'] === TRUE);
}
}
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 | |
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
EntityHandlerBase:: |
protected | property | The module handler to invoke hooks on. | 2 |
EntityHandlerBase:: |
protected | function | Gets the module handler. | 2 |
EntityHandlerBase:: |
public | function | Sets the module handler for this handler. | |
EntityViewBuilder:: |
protected | property | The cache bin used to store the render cache. | |
EntityViewBuilder:: |
protected | property | ||
EntityViewBuilder:: |
protected | property | The entity display repository. | |
EntityViewBuilder:: |
protected | property | The entity repository service. | |
EntityViewBuilder:: |
protected | property | Information about the entity type. | |
EntityViewBuilder:: |
protected | property | The type of entities for which this view builder is instantiated. | |
EntityViewBuilder:: |
protected | property | The language manager. | |
EntityViewBuilder:: |
protected | property | The EntityViewDisplay objects created for individual field rendering. | |
EntityViewBuilder:: |
protected | property | The theme registry. | |
EntityViewBuilder:: |
protected | function | Add contextual links. | |
EntityViewBuilder:: |
protected | function | Specific per-entity building. | 1 |
EntityViewBuilder:: |
public | function | Builds an entity's view; augments entity defaults. | |
EntityViewBuilder:: |
public | function | Builds multiple entities' views; augments entity defaults. | |
EntityViewBuilder:: |
protected | function | Provides entity-specific defaults to the build process. | 4 |
EntityViewBuilder:: |
public | function |
The cache tag associated with this entity view builder. Overrides EntityViewBuilderInterface:: |
|
EntityViewBuilder:: |
protected | function | Gets an EntityViewDisplay for rendering an individual field. | |
EntityViewBuilder:: |
protected | function | Determines whether the view mode is cacheable. | |
EntityViewBuilder:: |
public | function |
Resets the entity render cache. Overrides EntityViewBuilderInterface:: |
|
EntityViewBuilder:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
2 |
EntityViewBuilder:: |
public | function |
Builds the render array for the provided entity. Overrides EntityViewBuilderInterface:: |
4 |
EntityViewBuilder:: |
public | function |
Builds a renderable array for the value of a single field in an entity. Overrides EntityViewBuilderInterface:: |
|
EntityViewBuilder:: |
public | function |
Builds a renderable array for a single field item. Overrides EntityViewBuilderInterface:: |
|
EntityViewBuilder:: |
public | function |
Builds the render array for the provided entities. Overrides EntityViewBuilderInterface:: |
4 |
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. | |
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. | ||
YamlFormSubmissionViewBuilder:: |
protected | property | The config factory. | |
YamlFormSubmissionViewBuilder:: |
protected | property | The form element manager service. | |
YamlFormSubmissionViewBuilder:: |
protected | property | The form handler manager service. | |
YamlFormSubmissionViewBuilder:: |
protected | property | Form request handler. | |
YamlFormSubmissionViewBuilder:: |
protected | property | The token handler. | |
YamlFormSubmissionViewBuilder:: |
public | function |
Builds the component fields and properties of a set of entities. Overrides EntityViewBuilder:: |
|
YamlFormSubmissionViewBuilder:: |
public | function |
Build element display items from elements and submitted data. Overrides YamlFormSubmissionViewBuilderInterface:: |
|
YamlFormSubmissionViewBuilder:: |
public | function |
Build table display from elements and submitted data. Overrides YamlFormSubmissionViewBuilderInterface:: |
|
YamlFormSubmissionViewBuilder:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityViewBuilder:: |
|
YamlFormSubmissionViewBuilder:: |
protected | function | Determines if an element is visible. | |
YamlFormSubmissionViewBuilder:: |
public | function |
Constructs a new YamlFormSubmissionViewBuilder. Overrides EntityViewBuilder:: |