public function ConfigPagesController::classInit in Config Pages 8.3
Same name and namespace in other branches
- 8 src/Controller/ConfigPagesController.php \Drupal\config_pages\Controller\ConfigPagesController::classInit()
- 8.2 src/Controller/ConfigPagesController.php \Drupal\config_pages\Controller\ConfigPagesController::classInit()
Presents the config page creation/edit form.
Parameters
\Drupal\config_pages\ConfigPagesTypeInterface $config_pages_type: The config page type to add.
Return value
array A form array as expected by drupal_render().
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 string reference to 'ConfigPagesController::classInit'
File
- src/
Controller/ ConfigPagesController.php, line 125
Class
- ConfigPagesController
- Class ConfigPagesController.
Namespace
Drupal\config_pages\ControllerCode
public function classInit(ConfigPagesTypeInterface $config_pages_type = NULL) {
$cp_type = $config_pages_type
->id();
$typeEntity = ConfigPagesType::load($cp_type);
if (empty($typeEntity)) {
throw new NotFoundHttpException();
}
$contextData = $typeEntity
->getContextData();
$config_page_ids = $this->entityTypeManager
->getStorage('config_pages')
->getQuery()
->condition('type', $cp_type)
->condition('context', $contextData)
->execute();
if (!empty($config_page_ids)) {
$config_page_id = array_shift($config_page_ids);
$entityStorage = $this->entityTypeManager
->getStorage('config_pages');
$config_page = $entityStorage
->load($config_page_id);
}
else {
$config_page = $this->ConfigPagesStorage
->create([
'type' => $cp_type,
]);
}
return $this
->entityFormBuilder()
->getForm($config_page);
}