public function checkQuery(EncodePropertyValueFromWidgetEvent $event)
    {
        if (!$this->scopeMatcher->currentScopeIsBackend()) {
            return;
        }

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

        $where  = $event->getValue();
        $values = $event->getPropertyValueBag();

        if ($where) {
            $query = $this->connection->createQueryBuilder()
                ->select($values->getPropertyValue('tag_table') . '.*')
                ->from($values->getPropertyValue('tag_table'))
                ->where($where)
                ->orderBy($values->getPropertyValue('tag_sorting') ?: $values->getPropertyValue('tag_id'));

            try {
                $query->execute();
            } catch (\Exception $e) {
                throw new \RuntimeException(
                    \sprintf(
                        '%s %s',
                        $this->translator->trans('sql_error', [], 'contao_tl_metamodel_attribute'),
                        $e->getMessage()
                    )
                );
            }
        }
    }