Exemple #1
0
 /**
  * Validate the form
  *
  * @param  array $data
  * @return boolean
  */
 public function isValid($data)
 {
     if (!parent::isValid($data)) {
         return false;
     }
     $hasErrors = false;
     $missingLabel = false;
     $missingURI = false;
     $duplicateURI = false;
     $uids = array();
     if ($pageLinks = $this->getValue(self::HIDDEN_ELEMENT_ID)) {
         if ($pageLinks = json_decode($pageLinks, true)) {
             foreach ($pageLinks as $pageLink) {
                 if (!$missingLabel && trim($pageLink['label']) == '') {
                     $this->addError('All navigation links must have both labels.');
                     $hasErrors = true;
                     $missingLabel = true;
                 }
                 if (!$missingURI && trim($pageLink['uri']) == '') {
                     $this->addError(__('All navigation links must have URIs.'));
                     $hasErrors = true;
                     $missingURI = true;
                 }
                 if (trim($pageLink['uri']) != '') {
                     try {
                         $page = new Omeka_Navigation_Page_Uri();
                         $page->setHref($pageLink['uri']);
                         $uid = $this->_nav->createPageUid($page->getHref());
                         if (!in_array($uid, $uids)) {
                             $uids[] = $uid;
                         } else {
                             if (!$duplicateURI) {
                                 $this->addError(__('All navigation links must have different URIs.'));
                                 $duplicateURI = true;
                                 $hasErrors = true;
                             }
                         }
                     } catch (Omeka_Navigation_Page_Uri_Exception $e) {
                         $this->addError(__('Invalid URI for "%s" navigation link:  "%s"', $pageLink['label'], $pageLink['uri']));
                         $hasErrors = true;
                     }
                 }
             }
         }
     }
     $hasErrors = $hasErrors || $this->_postHasDeletedUndeletablePage();
     return !$hasErrors;
 }