class FlexiformManager in Flexiform 8
Provides the Flexiform manager.
Hierarchy
- class \Drupal\flexiform\FlexiformManager
Expanded class hierarchy of FlexiformManager
2 files declare their use of FlexiformManager
- EntityForm.php in src/
Plugin/ Block/ EntityForm.php - FlexiformController.php in src/
Controller/ FlexiformController.php
1 string reference to 'FlexiformManager'
1 service uses FlexiformManager
File
- src/
FlexiformManager.php, line 13
Namespace
Drupal\flexiformView source
class FlexiformManager {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The class resolver object.
*
* @var \Drupal\Core\DependencyInjection\ClassResolverInterface
*/
protected $classResolver;
/**
* The string translation service.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected $stringTranslation;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Construct a flexiform manager object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
* The class resolver.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* The translation service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, ClassResolverInterface $class_resolver, TranslationInterface $translation, ModuleHandlerInterface $module_handler) {
$this->entityTypeManager = $entity_type_manager;
$this->classResolver = $class_resolver;
$this->stringTranslation = $translation;
$this->moduleHandler = $module_handler;
}
/**
* Get a form object from an entity form display.
*
* @param \Drupal\flexiform\FlexiformEntityFormDisplayInterface $form_display
* The form display.
* @param \Drupal\Core\Entity\EntityInterface[] $provided_entities
* The entities provided by for form.
*
* @return \Drupal\Core\Form\FormInterface
* The form object.
*/
public function getFormObject(FlexiformEntityFormDisplayInterface $form_display, array $provided_entities = []) {
if ($entity_type_id = $form_display
->getTargetEntityTypeId()) {
$bundle = $form_display
->getTargetBundle();
$mode = $form_display
->getMode();
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
// @todo: Consider how best to behaver here. Do we fall back to default?
// Or ContentEntityForm?
$class = $entity_type
->getFormClass($mode);
if (!$class) {
$class = $entity_type
->getFormClass('default');
}
if (!$class) {
$class = '\\Drupal\\Core\\Entity\\ContentEntityForm';
}
$form_object = $this->classResolver
->getInstanceFromDefinition($class);
$form_object
->setStringTranslation($this->stringTranslation)
->setModuleHandler($this->moduleHandler)
->setEntityTypeManager($this->entityTypeManager)
->setOperation($mode)
->setEntityManager(\Drupal::entityManager());
if (!empty($provided_entities[$form_display
->getBaseEntityNamespace()])) {
$form_object
->setEntity($provided_entities[$form_display
->getBaseEntityNamespace()]);
}
return $form_object;
}
else {
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FlexiformManager:: |
protected | property | The class resolver object. | |
FlexiformManager:: |
protected | property | The entity type manager. | |
FlexiformManager:: |
protected | property | The module handler. | |
FlexiformManager:: |
protected | property | The string translation service. | |
FlexiformManager:: |
public | function | Get a form object from an entity form display. | |
FlexiformManager:: |
public | function | Construct a flexiform manager object. |