Spamworldpro Mini Shell
Spamworldpro


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/vendor/fooman/pdfcore-m2/src/Model/Config/Backend/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/fooman/pdfcore-m2/src/Model/Config/Backend/Columns.php
<?php
/**
 * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz)
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Fooman\PdfCore\Model\Config\Backend;

use Magento\Framework\App\Config\Data\ProcessorInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;

class Columns extends \Magento\Framework\App\Config\Value implements ProcessorInterface
{
    public function beforeSave()
    {
        $values = $this->getValue();
        if ($values) {
            if (!is_array($values)) {
                $values = json_decode($values, true);
            }
            $check = [];
            foreach ($values as $value) {
                if (isset($value['columntype'])) {
                    if (isset($check[$value['columntype']])) {
                        throw new \Magento\Framework\Exception\LocalizedException(
                            __('Each column type can only appear once.')
                        );
                    } else {
                        $check[$value['columntype']] = true;
                    }
                }
            }
        }
        if (is_array($values)) {
            unset($values['__empty']);
            $this->setValue(json_encode($values));
        }

        return parent::beforeSave();
    }

    // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- Magento 2 Core use
    protected function _afterLoad()
    {
        $values = $this->getValue();
        if (!is_array($values)) {
            $values = json_decode($values, true);
            foreach ($values as $key => $value) {
                if (!isset($values[$key]['title'])) {
                    $values[$key]['title'] = null;
                }
                if (!isset($values[$key]['align'])) {
                    $values[$key]['align'] = null;
                }
            }
            $this->setValue(empty($values) ? false : $values);
        }
        return parent::_afterLoad();
    }

    public function getOldValue()
    {
        return $this->_config->getValue(
            $this->getPath(),
            $this->getScope() ?: ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
            $this->getScopeCode()
        );
    }

    public function processValue($value)
    {
        if (!empty($value) && !is_array($value) && is_string($value)) {
            $values = json_decode($value, true);
            if ($values) {
                foreach ($values as $key => $val) {
                    if (!isset($values[$key]['title'])) {
                        $values[$key]['title'] = null;
                    }
                    if (!isset($values[$key]['align'])) {
                        $values[$key]['align'] = null;
                    }
                }
                return $values;
            }
        }
        return $value;
    }
}

Spamworldpro Mini