XF 2.3 Does XFMG have a category options renderer?

Matt C.

Well-known member
I'm looking for an options renderer similar to the forums for XFMG categories?

Code:
\XF\Option\Forum::renderSelectMultiple

Does one like that exist? I couldn't find it.
 
Doesn't exist, but shouldn't be terribly difficult to implement (untested, just copy, paste, replace)

PHP:
<?php

namespace MattC\Whatever\Option;

use XF\Entity\Option;
use XF\Option\AbstractOption;
use XFMG\Repository\Category as CategoryRepository;

class Category extends AbstractOption
{
    public static function renderSelectMultiple(Option $option, array $htmlParams)
    {
        $data = static::getSelectData($option, $htmlParams);
        $data['controlOptions']['multiple'] = true;
        $data['controlOptions']['size'] = 8;

        return static::getTemplater()->formSelectRow(
            $data['controlOptions'],
            $data['choices'],
            $data['rowOptions']
        );
    }

    protected static function getSelectData(Option $option, array $htmlParams)
    {
        $categoryRepo = \XF::repository(CategoryRepository::class);

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

        return [
            'choices' => $choices,
            'controlOptions' => static::getControlOptions($option, $htmlParams),
            'rowOptions' => static::getRowOptions($option, $htmlParams),
        ];
    }
}
 
Last edited:
Doesn't exist, but shouldn't be terribly difficult to implement (untested, just copy, paste, replace)

PHP:
<?php

namespace MattC\Whatever\Option;

use XF\Entity\Option;
use XF\Option\AbstractOption;
use XFMG\Repository\Category;

class Forum extends AbstractOption
{
    public static function renderSelectMultiple(Option $option, array $htmlParams)
    {
        $data = static::getSelectData($option, $htmlParams);
        $data['controlOptions']['multiple'] = true;
        $data['controlOptions']['size'] = 8;

        return static::getTemplater()->formSelectRow(
            $data['controlOptions'],
            $data['choices'],
            $data['rowOptions']
        );
    }

    protected static function getSelectData(Option $option, array $htmlParams)
    {
        $categoryRepo = \XF::repository(Category::class);

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

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

Thank you @Kirby. Was able to get this to work.
 
@Kirby Is there a way to disable an option if another option is not selected. I know this is available on style properties, but didn't see this for Admin CP options.

Maybe a code solution?

EDIT: For anyone wondering, I was able to do it with this in my PHP option callback:

PHP:
$enabled = \XF::options()->mc_ct_enableMedia;

$row = static::getRowOptions($option, $htmlParams);
if (!$enabled)
{
      $row['explain'] = \XF::phrase('mc_ct_enable_media_tracker_to_configure_media_per_page');
}
 
Last edited:
Back
Top Bottom