MetaModels\DcGeneral\Events\Table\RenderSetting\Subscriber::getAttributeOptions PHP Method

getAttributeOptions() public method

Retrieve the options for the attributes.
public getAttributeOptions ( ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent $event ) : void
$event ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent The event.
return void
    public function getAttributeOptions(GetPropertyOptionsEvent $event)
    {
        if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_rendersetting' || $event->getPropertyName() !== 'attr_id') {
            return;
        }
        $database = $this->getDatabase();
        $model = $event->getModel();
        $metaModel = $this->getMetaModel($model);
        if (!$metaModel) {
            return;
        }
        $arrResult = array();
        // Fetch all attributes that exist in other settings.
        $alreadyTaken = $database->prepare('
            SELECT
                attr_id
            FROM
                ' . $model->getProviderName() . '
            WHERE
                attr_id<>?
                AND pid=?')->execute($model->getProperty('attr_id'), $model->getProperty('pid'))->fetchEach('attr_id');
        foreach ($metaModel->getAttributes() as $attribute) {
            if (in_array($attribute->get('id'), $alreadyTaken)) {
                continue;
            }
            $arrResult[$attribute->get('id')] = sprintf('%s [%s]', $attribute->getName(), $attribute->get('type'));
        }
        $event->setOptions($arrResult);
    }