Get the setting values from the database and make them available
in the forum.

@param PrepareApiAttributes $event
15769
public function prepareApiAttributes(PrepareApiAttributes $event)
    {
        if ($event->isSerializer(ForumSerializer::class)) {
            foreach ($this->fieldsToGet as $field) {
                $event->attributes[$this->packagePrefix . $field] = $this->settings->get($this->packagePrefix . $field);
            }
        }
    }
152261
protected function resolveAttributeGetter($event)
    {
        foreach ($this->getAuditEvents() as $key => $value) {
            $auditableEvent = is_int($key) ? $value : $key;

            $auditableEventRegex = sprintf('/%s/', preg_replace('/\*+/', '.*', $auditableEvent));

            if (preg_match($auditableEventRegex, $event)) {
                return is_int($key) ? sprintf('get%sEventAttributes', ucfirst($event)) : $value;
            }
        }
    }
263233
public static function beforeActionAccess($event)
    {
        $controller = $event->sender;
        $permissionName = AuthItem::createPermissionName([$controller->module->id, $controller->id, $controller->action->id]);
        if (!AuthItem::checkAccess($permissionName, Yii::$app->user)) {
            throw new HttpException(403, Yii::t('modules/rbac', 'Access denied'));
        }
    }
1141906
public static function getPropertyOptions(GetPropertyOptionsEvent $event)
    {
        if ($event->getOptions() !== null) {
            return;
        }

        $model = $event->getModel();

        if (!($model instanceof Model)) {
            return;
        }
        $attribute = $model->getItem()->getAttribute($event->getPropertyName());

        if (!($attribute instanceof AbstractSelect)) {
            return;
        }

        try {
            $options = $attribute->getFilterOptionsForDcGeneral();
        } catch (\Exception $exception) {
            $options = ['Error: ' . $exception->getMessage()];
        }

        $event->setOptions($options);
    }
1138897
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $attributes = $request->attributes;
        if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
            return;
        }

        if (!$attributes->has('itemType')) {
            return;
        }

        $config = $this->loadConfig($attributes->get('itemType'));

        $customParams = $request->query->get('customParams', []);
        if (!is_array($customParams)) {
            throw new RuntimeException(
                sprintf(
                    'Invalid custom parameters specification for "%s" item type.',
                    $attributes->get('itemType')
                )
            );
        }

        $config->addParameters($customParams);

        $configLoadEvent = new ConfigLoadEvent($config);

        Kernel::VERSION_ID >= 40300 ?
            $this->eventDispatcher->dispatch($configLoadEvent, ContentBrowserEvents::CONFIG_LOAD) :
            $this->eventDispatcher->dispatch(ContentBrowserEvents::CONFIG_LOAD, $configLoadEvent);

        $this->container->set('netgen_content_browser.current_config', $config);
    }
192318
public function getOptions(GetOptionsEvent $event)
    {
        if (($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute')
            || ($event->getPropertyName() !== 'combinedvalues_fields')
            || ($event->getSubPropertyName() !== 'field_attribute')
        ) {
            return;
        }

        $model     = $event->getModel();
        $metaModel = $this->getMetaModelById($model->getProperty('pid'));

        if (!$metaModel) {
            return;
        }

        $result = [];
        // Add meta fields.
        $result['meta'] = self::getMetaModelsSystemColumns();

        // Fetch all attributes except for the current attribute.
        foreach ($metaModel->getAttributes() as $attribute) {
            if ($attribute->get('id') === $model->getId()) {
                continue;
            }

            $type = $event
                ->getEnvironment()
                ->getTranslator()
                ->translate('typeOptions.'.$attribute->get('type'), 'tl_metamodel_attribute');

            if ($type == 'typeOptions.'.$attribute->get('type')) {
                $type = $attribute->get('type');
            }

            $result['attributes'][$attribute->getColName()] = \sprintf(
                '%s [%s]',
                $attribute->getName(),
                $type
            );
        }

        $event->setOptions($result);
    }
857607
public function evaluateAttributes($event)
    {
        if (!empty($this->attributes[$event->name])) {
            $attributes = (array)$this->attributes[$event->name];
            if (strpos($event->name, 'after') !== false) {
                foreach ($attributes as $attribute) {
                    if (is_int($this->owner->$attribute)) {
                        $this->owner->$attribute = $this->owner->$attribute ? date($this->format, $this->owner->$attribute) : '';
                    }
                }
            } else if (strpos($event->name, 'before') !== false) {
                foreach ($attributes as $attribute) {
                    if (!is_numeric($this->owner->$attribute)) {
                        $date = \DateTime::createFromFormat($this->format, $this->owner->$attribute);
                        $this->owner->$attribute = $date ? $date->getTimestamp() : 0;
                    }
                }
            }
        }
    }
182878
protected function getValue($event)
    {
        if (!empty($this->owner->{$this->attribute})) {
            return $this->owner->{$this->attribute};
        }
        if ($this->value === null) {
            $uuid = $this->generateUUID();
        } else {
            $uuid = parent::getValue($event);
        }
        return $this->ensureUnique ? $this->makeUnique($uuid) : $uuid;
    }
485411
public function getAttributeValuesAction(/** @noinspection PhpUnusedParameterInspection */ $productId, $attributeId)
    {
        $result = array();

        // Get attribute for this product
        $attribute = AttributeQuery::create()->findPk($attributeId);

        if ($attribute !== null) {
            $values = AttributeAvQuery::create()
                ->joinWithI18n($this->getCurrentEditionLocale())
                ->filterByAttribute($attribute)
                ->find();
            ;

            if ($values !== null) {
                /** @var AttributeAv $value */
                foreach ($values as $value) {
                    $result[] = array('id' => $value->getId(), 'title' => $value->getTitle());
                }
            }
        }

        return $this->jsonResponse(json_encode($result));
    }
65842
protected function prepareAttributes()
    {

        // prepare the date format for the created at/updated at dates
        $createdAt = $this->getValue(ColumnKeys::CREATED_AT, date('Y-m-d H:i:s'), array($this, 'formatDate'));
        $updatedAt = $this->getValue(ColumnKeys::UPDATED_AT, date('Y-m-d H:i:s'), array($this, 'formatDate'));

        // load the product's attribute set ID
        $attributeSet = $this->getAttributeSetByAttributeSetName($this->getValue(ColumnKeys::ATTRIBUTE_SET_CODE));
        $attributeSetId = $attributeSet[MemberNames::ATTRIBUTE_SET_ID];
        $this->setAttributeSet($attributeSet);

        // initialize parent ID (the parent array entry)
        $parentId = $this->categoryIds[sizeof($this->categoryIds) - 1];

        // initialize the level
        $level = sizeof($this->categoryIds);

        // load the position, if available
        $position = $this->getValue(ColumnKeys::POSITION, 0);

        // return the prepared product
        return $this->initializeEntity(
            array(
                MemberNames::CREATED_AT       => $createdAt,
                MemberNames::UPDATED_AT       => $updatedAt,
                MemberNames::ATTRIBUTE_SET_ID => $attributeSetId,
                MemberNames::PATH             => '',
                MemberNames::PARENT_ID        => $parentId,
                MemberNames::POSITION         => $position,
                MemberNames::LEVEL            => $level,
                MemberNames::CHILDREN_COUNT   => 0
            )
        );
    }
20935
protected function prepareAttributes()
    {

        // load the product bundle option name
        $name = $this->getValue(ColumnKeys::BUNDLE_VALUE_NAME);

        // load the actual option ID
        $optionId = $this->getLastOptionId();

        try {
            // load and map the parent SKU
            $parentProductId = $this->mapSku($this->getValue(ColumnKeys::BUNDLE_PARENT_SKU));
        } catch (\Exception $e) {
            throw $this->wrapException(array(ColumnKeys::BUNDLE_PARENT_SKU), $e);
        }

        // load the store/website ID
        $store = $this->getStoreByStoreCode($this->getStoreViewCode(StoreViewCodes::ADMIN));
        $storeId = $store[MemberNames::STORE_ID];

        // return the prepared product
        return $this->initializeEntity(
            array(
                MemberNames::OPTION_ID         => $optionId,
                MemberNames::PARENT_PRODUCT_ID => $parentProductId,
                MemberNames::STORE_ID          => $storeId,
                MemberNames::TITLE             => $name
            )
        );
    }
1193596
protected function prepareAttributes()
    {

        // reset the position counter for the bundle selection
        $this->resetPositionCounter();

        try {
            // load and map the parent SKU
            $parentId = $this->mapSku($this->getValue(ColumnKeys::BUNDLE_PARENT_SKU));
        } catch (\Exception $e) {
            throw $this->wrapException(array(ColumnKeys::BUNDLE_PARENT_SKU), $e);
        }

        // extract the parent/child ID as well as type and position
        $required = $this->getValue(ColumnKeys::BUNDLE_VALUE_REQUIRED);
        $type = $this->getValue(ColumnKeys::BUNDLE_VALUE_TYPE);
        $position = 1;

        // return the prepared product
        return $this->initializeEntity(
            array(
                MemberNames::PARENT_ID => $parentId,
                MemberNames::REQUIRED  => $required,
                MemberNames::POSITION  => $position,
                MemberNames::TYPE      => $type
            )
        );
    }
454770
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $theme = $this->activeTheme->getName();
        $controllers = $request->attributes->get(static::ATTRIBUTE_KEY);
        if (isset($controllers[$theme])) {
            $request->attributes->set('_controller', $controllers[$theme]);
        }

        // Get rid of the attribute in the request to avoid it showing up in generated URLs
        $request->attributes->remove(static::ATTRIBUTE_KEY);
        $routeParams = $request->attributes->get('_route_params');
        if (null !== $routeParams) {
            unset($routeParams[static::ATTRIBUTE_KEY]);
            $request->attributes->set('_route_params', $routeParams);
        }
    }
579997
public function prepareAttributeValue($mapping, $value)
    {
        if ($value === null) {
            return Type::getNull();
        }

        $type = $mapping !== null ? $mapping->getType() : TypeFactory::getTypeFromPHPVariable($value);

        if (is_array($value)) {
            $value = array_map(
                function ($v) {
                    $this->prepareAttributeValue(null, $v);
                },
                $value
            );
        }

        return $type->convertToDatabaseValue($value);
    }
229201
public function decodeValue(DecodePropertyValueForWidgetEvent $event)
    {
        if (('attr_id' !== $event->getProperty())
            || ('tl_metamodel_filtersetting' !== $event->getEnvironment()->getDataDefinition()->getName())
        ) {
            return;
        }

        $model     = $event->getModel();
        $metaModel = $this->filterFactory->createCollection($model->getProperty('fid'))->getMetaModel();
        $value     = $event->getValue();

        if (!($metaModel && $value)) {
            return;
        }

        $attribute = $metaModel->getAttributeById($value);
        if ($attribute) {
            $event->setValue($metaModel->getTableName() .'_' . $attribute->getColName());
        }
    }
453667
public function beforeApiRequestSend($event)
    {
        $request = $event->request;
        $data = $request->getData();
        $data['openid'] = $this->getOpenid();
        $request->setData($data);

        parent::beforeApiRequestSend($event);
    }
758315
protected function prepareAttributes()
    {

        // initialize the values that has to be updated
        $updatedAt = date('Y-m-d H:i:s');
        $path = $this->getValue(ColumnKeys::PATH);

        // prepare and return the array with the updated values
        return array(
            MemberNames::PATH           => $path,
            MemberNames::UPDATED_AT     => $updatedAt
        );
    }