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;
 }