protected function getAssociatedEntryFromRequest(Control $control, Request $request)
 {
     /**
      * @var $control AssociationControl
      */
     $r = $this->entityManager->getRepository('Concrete\\Core\\Entity\\Express\\Entry');
     $entryID = $request->request->get('express_association_' . $control->getId());
     $associatedEntry = $r->findOneById($entryID);
     return $associatedEntry;
 }
 public function saveFromRequest(Control $control, Entry $entry, Request $request)
 {
     $target = $control->getAssociation()->getTargetEntity();
     $associatedEntry = $this->getAssociatedEntryFromRequest($control, $request);
     if (is_object($associatedEntry) && $associatedEntry->getEntity()->getID() == $target->getID()) {
         $this->applier->associateOneToOne($control->getAssociation(), $entry, $associatedEntry);
     } else {
         $this->applier->removeAssociation($control->getAssociation(), $entry);
     }
 }
 /**
  * @param AssociationControl $control
  * @return string
  */
 protected function getFormFieldElement(Control $control)
 {
     $class = get_class($control->getAssociation());
     $class = strtolower(str_replace(array('Concrete\\Core\\Entity\\Express\\', 'Association'), '', $class));
     if (substr($class, -4) == 'many') {
         return 'select_multiple';
     } else {
         return 'select';
     }
 }
 public function render(Control $control, $template)
 {
     extract($this->scopeItems);
     $view = $this;
     $form = $this->context->getApplication()->make('helper/form');
     $label = $control->getDisplayLabel();
     $renderer = $this->context->getFormRenderer();
     ob_start();
     include $template;
     return ob_get_clean();
 }
 public function validateRequest(Control $control, Request $request)
 {
     $key = $control->getAttributeKey();
     $controller = $key->getController();
     $validator = $controller->getValidator();
     $response = $validator->validateSaveValueRequest($controller, $request, $control->isRequired());
     if (!$response->isValid()) {
         $error = $response->getErrorObject();
         return $error;
     }
     return true;
 }
 /**
  * @param ContextInterface $context
  * @param AttributeKeyControl $control
  * @return string
  */
 public function render(ContextInterface $context, Control $control, Entry $entry = null)
 {
     $ak = $control->getAttributeKey();
     if (is_object($ak)) {
         $template = new Template('attribute_key');
         $av = null;
         if (is_object($entry)) {
             $av = $entry->getAttributeValueObject($ak);
         }
         $view = new EntityPropertyControlView($context);
         $view->addScopeItem('key', $ak);
         $view->addScopeItem('value', $av);
         return $view->render($control, $context->getTemplateLocator($template)->getFile());
     }
 }
 protected function getAssociatedEntriesFromRequest(Control $control, Request $request)
 {
     $r = $this->entityManager->getRepository('Concrete\\Core\\Entity\\Express\\Entry');
     $entryIDs = $request->request->get('express_association_' . $control->getId());
     $associatedEntries = array();
     if (is_array($entryIDs)) {
         foreach ($entryIDs as $entryID) {
             $associatedEntry = $r->findOneById($entryID);
             $target = $control->getAssociation()->getTargetEntity();
             if (is_object($associatedEntry) && $associatedEntry->getEntity()->getID() == $target->getID()) {
                 $associatedEntries[] = $associatedEntry;
             }
         }
     }
     return $associatedEntries;
 }
 /**
  * @param ContextInterface $context
  * @param AssociationControl $control
  * @param Entry|null $entry
  * @return string
  */
 public function render(ContextInterface $context, Control $control, Entry $entry = null)
 {
     $template = new Template('association');
     $association = $control->getAssociation();
     /*
      * @var $association \Concrete\Core\Entity\Express\Association
      */
     $related = $entry->getAssociations();
     $view = new EntityPropertyControlView($context);
     foreach ($related as $relatedAssociation) {
         if ($relatedAssociation->getAssociation()->getID() == $association->getID()) {
             $view->addScopeItem('entities', $relatedAssociation->getSelectedEntries());
         }
     }
     $view->addScopeItem('control', $control);
     $view->addScopeItem('formatter', $association->getFormatter());
     return $view->render($control, $context->getTemplateLocator($template)->getFile());
 }
 public function getSaveHandler(Control $control)
 {
     return $control->getAssociation()->getSaveHandler();
 }
 public function saveFromRequest(Control $control, Request $request)
 {
     $control->setIsRequired((bool) $request->request("isRequired"));
     $control->setCustomLabel($request->request("customLabel"));
     return $control;
 }
 public function jsonSerialize()
 {
     $data = parent::jsonSerialize();
     $data['attributeType'] = $this->getAttributeKey()->getAttributeTypeHandle();
     return $data;
 }