/**
  * Check if the select_where value is valid by firing a test query.
  *
  * @param EncodePropertyValueFromWidgetEvent $event The event.
  *
  * @return void
  *
  * @throws \RuntimeException When the where condition is invalid.
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function checkQuery(EncodePropertyValueFromWidgetEvent $event)
 {
     if ($event->getEnvironment()->getDataDefinition()->getName() !== 'tl_metamodel_attribute' || $event->getProperty() !== 'tag_where') {
         return;
     }
     $where = $event->getValue();
     $values = $event->getPropertyValueBag();
     if ($where) {
         $objDB = \Database::getInstance();
         $strTableName = $values->getPropertyValue('tag_table');
         $strColNameId = $values->getPropertyValue('tag_id');
         $strSortColumn = $values->getPropertyValue('tag_sorting') ?: $strColNameId;
         $query = sprintf('SELECT %1$s.*
             FROM %1$s%2$s
             ORDER BY %1$s.%3$s', $strTableName, $where ? ' WHERE (' . $where . ')' : false, $strSortColumn);
         try {
             $objDB->prepare($query)->execute();
         } catch (\Exception $e) {
             throw new \RuntimeException(sprintf('%s %s', $GLOBALS['TL_LANG']['tl_metamodel_attribute']['sql_error'], $e->getMessage()));
         }
     }
 }