protected function isValid(CategoryInterface $category)
 {
     if (!$category instanceof StandardSearchIndexerInterface) {
         throw new \Exception(t('Category %s must implement StandardSearchIndexerInterface.'), $category->getCategoryEntity()->getAttributeCategoryHandle());
     }
     return true;
 }
 /**
  * @param StandardSearchIndexerInterface $category
  * @param Value $value
  * @param mixed $subject
  */
 public function indexEntry(CategoryInterface $category, AttributeValueInterface $value, $subject)
 {
     $columns = $this->connection->getSchemaManager()->listTableColumns($category->getIndexedSearchTable());
     $attributeValue = $value->getSearchIndexValue();
     $details = $category->getSearchIndexFieldDefinition();
     $primary = $details['primary'][0];
     $primaryValue = $category->getIndexedSearchPrimaryKeyValue($subject);
     $columnValues = array();
     /**
      * @var $exists Statement
      */
     $exists = $this->connection->query("select count({$primary}) from {$category->getIndexedSearchTable()} where {$primary} = {$primaryValue}")->fetchColumn();
     if (is_array($attributeValue)) {
         foreach ($attributeValue as $valueKey => $valueValue) {
             $col = $this->getIndexEntryColumn($value->getAttributeKey(), $valueKey);
             if (isset($columns[strtolower($col)])) {
                 $columnValues[$col] = $valueValue;
             }
         }
     } else {
         $col = $this->getIndexEntryColumn($value->getAttributeKey());
         if (isset($columns[strtolower($col)])) {
             $columnValues[$col] = $attributeValue;
         }
     }
     if (count($columnValues)) {
         $primaries = array($primary => $primaryValue);
         if ($exists) {
             $this->connection->update($category->getIndexedSearchTable(), $columnValues, $primaries);
         } else {
             $this->connection->insert($category->getIndexedSearchTable(), $primaries + $columnValues);
         }
     }
 }
 protected function validate(CategoryInterface $category, Controller $controller, Request $request, Key $key = null)
 {
     /** @var \Concrete\Core\Form\Service\Validation $val */
     $val = $this->application->make('helper/validation/form');
     /** @var \Concrete\Core\Validation\CSRF\Token $valt */
     $valt = $this->application->make('helper/validation/token');
     $val->setData($request->request->all());
     $val->addRequired("akHandle", t("Handle required."));
     $val->addRequired("akName", t('Name required.'));
     $val->addRequired("atID", t('Type required.'));
     $val->test();
     $error = $val->getError();
     if (!$valt->validate('add_or_update_attribute')) {
         $error->add($valt->getErrorMessage());
     }
     /** @var \Concrete\Core\Utility\Service\Validation\Strings $stringValidator */
     $stringValidator = $this->application->make('helper/validation/strings');
     if (!$stringValidator->handle($request->request->get('akHandle'))) {
         $error->add(t('Attribute handles may only contain letters, numbers and underscore "_" characters'));
     }
     $existing = $category->getAttributeKeyByHandle($request->request->get('akHandle'));
     if (is_object($existing)) {
         if (is_object($key)) {
             if ($key->getAttributeKeyID() != $existing->getAttributeKeyID()) {
                 $error->add(t("An attribute with the handle %s already exists.", $request->request->get('akHandle')));
             }
         } else {
             $error->add(t("An attribute with the handle %s already exists.", $request->request->get('akHandle')));
         }
     }
     $controllerResponse = $controller->validateKey($request->request->all());
     if ($controllerResponse instanceof ErrorList) {
         $error->add($controllerResponse);
     }
     $response = new Response();
     if ($error->has()) {
         $response->setIsValid(false);
         $response->setErrorObject($error);
     }
     return $response;
 }