Skip to content
Snippets Groups Projects

Can't document menus resolved.

2 unresolved threads
Files
2
@@ -7,6 +7,7 @@ use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Database;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
/**
* Service providing information on the Documentable entities.
@@ -36,6 +37,13 @@ class DocumentableEntityProvider extends ServiceProviderBase {
*/
protected $entityFieldManager;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* An array of fieldmap.
*
@@ -52,11 +60,15 @@ class DocumentableEntityProvider extends ServiceProviderBase {
* The documentable modules service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
* The time service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(ConfigFactoryInterface $configFactory, DocumentableModules $documentableModules, EntityFieldManagerInterface $entityFieldManager) {
public function __construct(ConfigFactoryInterface $configFactory, DocumentableModules $documentableModules, EntityFieldManagerInterface $entityFieldManager, EntityTypeManagerInterface $entityTypeManager) {
$this->config = $configFactory->get('content_model_documentation.settings');
$this->entityFieldManager = $entityFieldManager;
$this->entityTypeManager = $entityTypeManager;
$this->fieldMap = $this->entityFieldManager->getFieldMap();
$this->fieldMap = $this->addMenusToFieldMap($this->fieldMap);
$this->documentableModules = $documentableModules;
    • I think we should optionally inject the menus into $this->fieldMap if they are not there. (see explanation of why below)

Please register or sign in to reply
}
@@ -218,9 +230,43 @@ class DocumentableEntityProvider extends ServiceProviderBase {
}
}
}
}
return $documentable_entities;
}
/**
* Optionally add menus to fieldMap if they are not there.
*
* @param array $field_map
* The fieldMap containing field-able entities.
*
* @return array
* Field map possibly with menus added.
*/
protected function addMenusToFieldMap(array $field_map): array {
// Determine if menus need to be added.
// If menus are field-able (example menu_item_extras is in use), then the
// menu entities will already be in the field map.
if (empty($field_map['menu_link_content']['uuid']['bundles']) || !empty($field_map['menu_link_content']['uuid']['bundles']['menu_link_content'])) {
// Menus are not in the field map so we need to add them.
$menu_storage = $this->entityTypeManager->getStorage('menu');
$menus = $menu_storage->loadMultiple();
$bundles = [];
$field_map['menu_link_content']['uuid']['bundles'] = [];
foreach ($menus as $menu) {
$bundles[$menu->id()] = $menu->id();
}
$field_map['menu_link_content']['uuid']['bundles'] = $bundles;
// Also populate any fields
foreach ($field_map['menu_link_content'] as $element_name => $element) {
if ($this->isField($element_name)) {
// It is a field so add in the bundles.
$field_map['menu_link_content'][$element_name]['bundles'] = $bundles;
}
}
}
return $field_map;
}
}
Loading