/** * @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 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); } }
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(); }