identifier, FormPersistenceManagerInterface::FORM_DEFINITION_FILE_EXTENSION); } public function addItems(array $items): array { $this->initialize(); return $this->purgeItems($items); } /** * Purges items that are not allowed for according command. * According canBeEdited, canBeRenamed, ... commands will always return * false in order to remove those form file items. * * Using the canRender() approach avoid adding hardcoded index name * lookup. Thus, it's streamlined with the rest of the provides, but * actually purges items instead of adding them. * * @param array $items */ protected function purgeItems(array $items): array { foreach ($items as $name => $item) { $type = $item['type']; if ($type === 'submenu' && !empty($item['childItems'])) { $item['childItems'] = $this->purgeItems($item['childItems']); } elseif (!$this->canRender($name, $type)) { unset($items[$name]); } } return $items; } protected function canBeEdited(): bool { return false; } protected function canBeRenamed(): bool { return false; } }