* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 */ declare(strict_types=1); namespace PrestaShop\Module\Mbo\Addons; use PrestaShop\Module\Mbo\Controller\Admin\ModuleCatalogController; use PrestaShop\Module\Mbo\Security\PermissionCheckerInterface; use PrestaShopBundle\Security\Voter\PageVoter; use Symfony\Contracts\Translation\TranslatorInterface; if (!defined('_PS_VERSION_')) { exit; } /** * This service returns descriptions for the buttons to add into the Module configure toolbar * (like addons connect, update module CTA, ...) */ class Toolbar { public function __construct( private readonly PermissionCheckerInterface $permissionChecker, private readonly TranslatorInterface $translator, ) { } /** * Common method for all module related controller for getting the header buttons. * * @return array */ public function getToolbarButtons(): array { if (!in_array( $this->permissionChecker->getAuthorizationLevel(ModuleCatalogController::CONTROLLER_NAME), [ PageVoter::LEVEL_READ, PageVoter::LEVEL_UPDATE, ] )) { return $this->getAddModuleToolbar(); } return []; } /** * Get the Add Module button definition for the toolbar * * @return array[] */ public function getAddModuleToolbar(): array { return [ 'add_module' => [ 'href' => '#', 'desc' => $this->translator->trans( 'Upload a module', [], 'Modules.Mbo.Modulescatalog', $this->translator->getLocale() ), 'icon' => 'cloud_upload', 'help' => $this->translator->trans( 'Upload a module', [], 'Modules.Mbo.Modulescatalog', $this->translator->getLocale() ), ], ]; } }