kanweb/c5-helpers

ConcreteCMS 辅助工具套件

v2.1 2021-11-23 10:37 UTC

This package is auto-updated.

Last update: 2024-09-23 16:42:01 UTC


README

Latest Version on Packagist Software License

ConcreteCMS 有用辅助工具集合

  • in_array_all 验证所有针都在草堆数组中。
  • in_array_any 验证至少有一个针在草堆数组中。
  • strip_spaces 从给定字符串中删除所有空格。
  • current_locale 获取当前页面区域设置。
  • current_language 获取当前页面语言。
  • active_locale 是 \Localization::activeLocale() 的别名。
  • active_language 是 \Localization::activeLanguage() 的别名。
  • theme_path 获取站点主题路径
  • c5_date_format 是 \Concrete\Core\Localization\Service\Date::formatDate() 的别名。
  • c5_date_format_custom 是 \Concrete\Core\Localization\Service\Date::formatCustom() 的别名。
  • Xanweb\Helper\Page::getBlockXanweb\Helper\Page::getBlocks 用于从页面获取块

安装

将库包含到 composer.json 中

composer require xanweb/c5-helpers

Xanweb\Helper\Page 的用法

    use Xanweb\Helper\Page as PageHelper;

    $ph = new PageHelper(
        $page, // Page Object
        ['Header', 'Footer'], // Optional argument to exclude some areas from fetching
        ['Main'] // Optional argument to include some areas in fetching
    );
    
    // Get the first valid instance of required block
    $contentBlockController = $ph->getBlock(
        'content', // Block Type Handle 
        function (BlockController $bController) { // Optional callable to test for valid block
            return !empty($bController->getContent());
        }
    );

    // Get the first valid instances of required blocks
    $blocksControllers = $ph->getBlocks(
        ['image', 'content'], // Block Types Handle 
        function (BlockController $bController) { // Optional callable to test for valid block
            if ($bController instanceof \Concrete\Block\Image\Controller) {
                return is_object($this->getFileObject());
            }

            if ($bController instanceof \Concrete\Block\Content\Controller) {
                return !empty($bController->getContent());
            }

            return false;
        }
    );

    /**
     *  - $blocksControllers array is indexed by btHandle: ['image' => $bController, 'content' => $bController]
     *  - If no block is found $blocksControllers will be an empty array 
     */