XF\Option\Page callback file

DragonByte Tech

Well-known member
There's currently a XF\Option\Forum callback file that lets you easily create a forum drop-down in the options. I'd like a similar file, but for Pages.

Below is the proposed code:

PHP:
<?php

namespace XF\Option;

/**
 * Class Page
 *
 * @package XF\Option
 */
class Page extends AbstractOption
{
    /**
     * @param \XF\Entity\Option $option
     * @param array $htmlParams
     *
     * @return string
     */
    public static function renderSelect(\XF\Entity\Option $option, array $htmlParams)
    {
        $data = self::getSelectData($option, $htmlParams);

        return self::getTemplater()->formSelectRow(
            $data['controlOptions'], $data['choices'], $data['rowOptions']
        );
    }
    
    /**
     * @param \XF\Entity\Option $option
     * @param array $htmlParams
     *
     * @return string
     */
    public static function renderSelectMultiple(\XF\Entity\Option $option, array $htmlParams)
    {
        $data = self::getSelectData($option, $htmlParams);
        $data['controlOptions']['multiple'] = true;
        $data['controlOptions']['size'] = 8;

        return self::getTemplater()->formSelectRow(
            $data['controlOptions'], $data['choices'], $data['rowOptions']
        );
    }
    
    /**
     * @param \XF\Entity\Option $option
     * @param array $htmlParams
     *
     * @return array
     */
    protected static function getSelectData(\XF\Entity\Option $option, array $htmlParams)
    {
        /** @var \XF\Repository\Node $nodeRepo */
        $nodeRepo = \XF::repository('XF:Node');

        $choices = $nodeRepo->getNodeOptionsData(true, 'Page', 'option');
        $choices = array_map(function($v) {
            $v['label'] = \XF::escapeString($v['label']);
            return $v;
        }, $choices);

        return [
            'choices' => $choices,
            'controlOptions' => self::getControlOptions($option, $htmlParams),
            'rowOptions' => self::getRowOptions($option, $htmlParams)
        ];
    }
}

Fillip
 

XDinc

Well-known member
@DragonByte Tech ,

First of all thanks for proposed code.
I used it and now I can callbacks pages. But how we can use conditionals for pages with xf.options?

Like this;
Code:
<xf:if is="$xf.options.exampleaddon_enable && !in_array($page.page_id, $xf.options.example_selectPage)">
I'm not sure $page.page_id is it correct or not.
Thanks in advance Fillip.
 
Top