![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Soon/CsBlock/Model/ |
<?php /** * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @author Hervé Guétin <[email protected]> <@herveguetin> * @copyright Copyright (c) 2017 Agence Soon (http://www.agence-soon.fr) */ namespace Soon\CsBlock\Model; use Magento\Framework\App\Config\ScopeConfigInterface; class BlockType implements BlockTypeInterface { const DEFAULT_FIELD_TYPE = 'text'; /** * @var ScopeConfigInterface */ private $config; public function __construct( ScopeConfigInterface $config ) { $this->config = $config; } /** * Get fields from content types * * @return array */ public function getFields(): array { $fields = []; $types = $this->all(); foreach ($types as $code => $config) { if (isset($config['fields'])) { foreach ($config['fields'] as $fieldCode => $field) { $fields['soon_csblock__' . $code . '__' . $fieldCode] = $this->configure($field); } } } return $fields; } /** * @return array */ private function all() { $blockTypes = $this->config->getValue('soon_csblock/block_types'); foreach ($blockTypes as $k => $type) { if (!$type['active']) { unset($blockTypes[$k]); } } return $blockTypes; } /** * @param array $field * @return mixed */ private function configure($field) { $field['field_type'] = isset($field['field_type']) ? $field['field_type'] : self::DEFAULT_FIELD_TYPE; return $field; } /** * @return array */ public function getLabels(): array { $options = []; foreach ($this->all() as $code => $config) { $options[$code] = $config['label']; } return $options; } /** * @param string $typeCode * @return array */ public function getTypeConfig(string $typeCode): array { return $this->config->getValue("soon_csblock/block_types/{$typeCode}") ?? []; } }