GeysirControllerBase.php in Geysir 8
File
src/Controller/GeysirControllerBase.php
View source
<?php
namespace Drupal\geysir\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityFieldManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class GeysirControllerBase extends ControllerBase {
protected $entityFieldManager;
protected $entityTypeManager;
public function __construct(EntityFieldManager $entityFieldManager, EntityTypeManagerInterface $entityTypeManager) {
$this->entityFieldManager = $entityFieldManager;
$this->entityTypeManager = $entityTypeManager;
}
public static function create(ContainerInterface $container) {
$entityFieldManager = $container
->get('entity_field.manager');
$entityTypeManager = $container
->get('entity_type.manager');
return new static($entityFieldManager, $entityTypeManager);
}
protected function getParagraphTitle($parent_entity_type, $parent_entity_bundle, $field) {
$form_mode = 'default';
$parent_field_settings = $this->entityTypeManager
->getStorage('entity_form_display')
->load($parent_entity_type . '.' . $parent_entity_bundle . '.' . $form_mode)
->getComponent($field);
$paragraph_title = isset($parent_field_settings['settings']['title']) ? $parent_field_settings['settings']['title'] : $this
->t('Paragraph');
return strtolower($paragraph_title);
}
protected function getParentRevisionOrParent($parent_entity_type, $parent_entity_revision) {
$entity_storage = $this->entityTypeManager
->getStorage($parent_entity_type);
if ($this->entityTypeManager
->getDefinition($parent_entity_type)
->isRevisionable()) {
return $entity_storage
->loadRevision($parent_entity_revision);
}
else {
return $entity_storage
->load($parent_entity_revision);
}
}
}