Provide options for default selection.

@param GetOptionsEvent $event The event.

@return void

@SuppressWarnings(PHPMD.Superglobals)
@SuppressWarnings(PHPMD.CamelCaseVariableName)
4996
public function getOptions(GetOptionsEvent $event)
    {
        // Check the context.
        $allowedProperties = array('lookupservice', 'second_attr_id', 'single_attr_id');
        if (!$this->isAllowedProperty($event, 'tl_metamodel_filtersetting', $allowedProperties)
            || 'lookupservice' !== $event->getSubPropertyName()
        ) {
            return;
        }

        $resolveClass = (array) $GLOBALS['METAMODELS']['filters']['perimetersearch']['resolve_class'];

        $domain  = 'tl_metamodel_filtersetting';
        $options = [];
        foreach (\array_keys($resolveClass) as $name) {
            $options[$name] = $this->translator->trans($domain . '.perimetersearch.' . $name, [], 'contao_' . $domain);
        }

        $event->setOptions($options);
    }
775562
public function checkOptions(PersistEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticlePageDocument) {
            return;
        }

        $autoRename = $event->getOption('auto_rename');

        if (false !== $autoRename) {
            throw new \InvalidArgumentException('Persist "ArticlePageDocument" only with option "auto_rename" set to "false" allowed');
        }
    }
721411
public function getPluginCalendars(Event $event, array $options = []): void
    {
        $content = $result = [];

        /** @var \Qobo\Calendar\Model\Table\CalendarsTable $table */
        $table = TableRegistry::get('Qobo/Calendar.Calendars');

        if (!empty($event->result)) {
            $result = $event->result;
        }

        // locally created calendars don't have source_id (external link).
        $options = array_merge($options, [
            'conditions' => [
                'source LIKE' => 'Plugin__%',
            ]
        ]);

        $calendars = $table->getCalendars($options);

        if (empty($calendars)) {
            return;
        }

        foreach ($calendars as $k => $calendar) {
            unset($calendar->calendar_events);

            $encoded = (string)json_encode($calendar);
            if (json_last_error() !== JSON_ERROR_NONE) {
                throw new \RuntimeException(json_last_error_msg());
            }

            $content[$k]['calendar'] = json_decode($encoded, true);
        }

        if (!empty($content)) {
            $result = array_merge($result, $content);
        }

        $event->result = $result;
    }
578345
public function getPropertyOptions(GetPropertyOptionsEvent $event)
    {
        if (!$this->scopeMatcher->currentScopeIsFrontend()) {
            return;
        }

        $model = $event->getModel();
        if (!($model instanceof Model)) {
            return;
        }

        $attribute = $model->getItem()->getAttribute($event->getPropertyName());

        // Check if we have a checkbox.
        if (!($attribute instanceof Checkbox)) {
            return;
        }

        // Reset the options we didn't need them for checkbox.
        $event->setOptions(null);
        $event->stopPropagation();
    }
669597
public function getFilters(GetPropertyOptionsEvent $event)
    {
        if (!$this->scopeMatcher->currentScopeIsBackend()) {
            return;
        }

        if (($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute')
            || ($event->getPropertyName() !== 'select_filter')
        ) {
            return;
        }

        $model     = $event->getModel();
        $metaModel = $this->factory->getMetaModel($model->getProperty('select_table'));

        if ($metaModel) {
            $statement = $this->connection
                ->prepare('SELECT id,name FROM tl_metamodel_filter WHERE pid=:pid ORDER BY name');

            $statement->execute(['pid' => $metaModel->get('id')]);

            $result = [];
            while ($row = $statement->fetch(\PDO::FETCH_OBJ)) {
                /** @noinspection PhpUndefinedFieldInspection */
                $result[$row->id] = $row->name;
            }

            $event->setOptions($result);
        }
    }
1113542
public function getColumnNames(GetPropertyOptionsEvent $event)
    {
        if (!$this->isBackendOptionRequestFor($event, ['tag_column', 'tag_alias', 'tag_sorting'])) {
            return;
        }

        $result = $this->getColumnNamesFrom($event->getModel()->getProperty('tag_table'));

        if (!empty($result)) {
            \asort($result);
            $event->setOptions($result);
        }
    }
1242828
public function beforeFieldRender($event)
    {
        $clientOptions = $this->getFieldClientOptions($event->getTarget());
        if (!empty($clientOptions)) {
            $this->attributes[] = $clientOptions;
        }
    }
1085052
public function handle(GetGlobalButtonEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        if ('button_new' !== $event->getKey()) {
            return;
        }

        $environment     = $event->getEnvironment();
        $basicDefinition = $environment->getDataDefinition()->getBasicDefinition();
        $mode            = $basicDefinition->getMode();

        if (!$basicDefinition->isCreatable()) {
            $event->setHtml('');
            return;
        }

        if ((BasicDefinitionInterface::MODE_PARENTEDLIST === $mode)
            || (BasicDefinitionInterface::MODE_HIERARCHICAL === $mode)
        ) {
            $filter = new Filter();
            $filter->andModelIsFromProvider($basicDefinition->getDataProvider());
            if ($parentDataProviderName = $basicDefinition->getParentDataProvider()) {
                $filter->andParentIsFromProvider($parentDataProviderName);
            } else {
                $filter->andHasNoParent();
            }

            if ($environment->getClipboard()->isNotEmpty($filter)) {
                $event->setHtml('');
                return;
            }
        }

        $url = UrlBuilder::fromUrl($event->getHref());
        if ($serializedPid = $environment->getInputProvider()->getParameter('pid')) {
            $url->setQueryParameter('pid', ModelId::fromSerialized($serializedPid)->getSerialized());
        }

        $event->setHref($url->getUrl());
    }
112681
public function dispatch($event, $options)
    {
        $listeners = $this->eventDispatcher->getListeners($event);

        foreach ($listeners as $listener) {
            call_user_func($listener, $options);
        }
    }
1292609
public function getOption($name, $default = null)
    {
        return array_key_exists($name, $this->_options) ?
            $this->_options[$name] :
            $default;
    }
881800
protected function setDefaultOptions() : void
    {
        $type = $this->getType();
        if (! empty($this->defaultOptions[$type])) {
            $this->options = $this->defaultOptions[$type];
        }
    }
1122846
public function getFilters(GetPropertyOptionsEvent $event)
    {
        if (!$this->isBackendOptionRequestFor($event, ['tag_filter'])) {
            return;
        }

        $model = $event->getModel();
        if (null === $metaModel = $this->factory->getMetaModel($model->getProperty('tag_table'))) {
            return;
        }
        $filters = $this->connection->createQueryBuilder()
            ->select('id', 'name')
            ->from('tl_metamodel_filter')
            ->where('pid=:pid')
            ->setParameter('pid', $metaModel->get('id'))
            ->orderBy('name')
            ->execute();

        $result = [];
        foreach ($filters->fetchAll(\PDO::FETCH_ASSOC) as $filter) {
            $result[$filter['id']] = $filter['name'];
        }

        $event->setOptions($result);
    }
748186
public final function getOption( string $name, $defaultValue = false )
   {

      if ( ! $this->hasOption( $name ) )
      {
         return $defaultValue;
      }

      return $this->_options[ $name ];

   }
85211
public function setEvent($event)
  {
    if ($event === '?' || $event === '') {
      $this->event = null;
    } else {
      $event = Util::foreignLettersToEnglishLetters($event);
      $event = Util::titleCaseIfCurrentlyAllCaps($event);
      $this->event = $event === '?' ? null : $event;
    }
  }
983281
protected function setOptions($options)
    {
        if (is_null($this->options)) {
            $this->preloadDefaults(true);
        }
        
        foreach ($options as $k => $v) {
            if (!isset($this->options[$k])) {
                throw new \Exception("Option $k not allowed.");
            }
            $this->options[$k] = $v;
        }
    }
308110
public function defaultSelectizeOptions()
    {
        $metadata = $this->metadata();
        $options = [];

        if (isset($metadata['data']['selectize_options'])) {
            $options = $metadata['data']['selectize_options'];
            $options = $this->parseSelectizeOptions($options);
        }

        if ($this->property() instanceof ObjectProperty) {
            if (isset($options['options'])) {
                $options['options'] = array_merge($options['options'], $this->selectizeVal());
            } else {
                $options['options'] = $this->selectizeVal();
            }
        }

        return $options;
    }
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);
    }