/**
  * @param $type \PortlandLabs\Concrete5\MigrationTool\Entity\Import\PageType\PageType
  *
  * @return MessageCollection
  */
 public function validate($type)
 {
     $collection = new MessageCollection();
     // Validate the composer form controls
     foreach ($type->getLayoutSets() as $set) {
         foreach ($set->getControls() as $control) {
             $validator = $control->getRecordValidator($this->getBatch());
             if (is_object($validator)) {
                 $messages = $validator->validate($control);
                 $collection->addMessages($messages);
             }
         }
     }
     // Validate the page publish targets
     $target = $type->getPublishTarget();
     $validator = $target->getRecordValidator($this->getBatch());
     $messages = $validator->validate($target);
     $collection->addMessages($messages);
     // Validate the page templates
     $templates = array();
     if ($template = $type->getDefaultTemplate()) {
         $templates[] = $template;
     }
     if ($type->getAllowedTemplates() == 'C') {
         foreach ($type->getTemplates() as $template) {
             if (!in_array($template, $templates)) {
                 $templates[] = $template;
             }
         }
     }
     $validator = new PageTemplateItemValidator();
     foreach ($templates as $template) {
         $item = new PageTemplateItem($template);
         if (!$validator->itemExists($item, $this->getBatch())) {
             $validator->addMissingItemMessage($item, $collection);
         }
     }
     // Validate the page type defaults
     $defaultPages = $type->getDefaultPageCollection();
     $pageValidator = $defaultPages->getRecordValidator($this->getBatch());
     foreach ($defaultPages->getPages() as $page) {
         $pageMessages = $pageValidator->validate($page);
         if (is_object($pageMessages)) {
             $collection->addMessages($pageMessages);
         }
     }
     return $collection;
 }
 /**
  * @param $key AttributeKey
  *
  * @return MessageCollection
  */
 public function validate($key)
 {
     $messages = new MessageCollection();
     if ($key instanceof UnknownAttributeKey) {
         $messages->add(new Message(t('Attribute key is of an unknown type. It may not be imported properly.')));
     }
     $validator = $key->getRecordValidator($this->getBatch());
     if (is_object($validator)) {
         $r = $validator->validate($key);
         $messages->addMessages($r);
     }
     return $messages;
 }