setType() public method

public setType ( string $type )
$type string
Beispiel #1
0
 /**
  * Gets the item from the administration entry points defined in the config.json, by the given code.
  *
  * @param string  $code <bundleName>/news/foo/bar/edit
  *
  * @return EntryPoint
  */
 public function getEntryPoint($code)
 {
     if ('/' === $code) {
         return null;
     }
     $path = $code;
     if (substr($code, 0, 1) == '/') {
         $code = substr($code, 1);
     }
     if (false === strpos($code, '/')) {
         $path = '';
     }
     $bundleName = $code;
     if (false !== strpos($code, '/')) {
         $bundleName = substr($code, 0, strpos($code, '/'));
         $path = substr($code, strpos($code, '/') + 1);
     }
     //$bundleName = ucfirst($bundleName) . 'Bundle';
     $config = $this->jarves->getConfig($bundleName);
     if (!$path && $config) {
         //root
         $entryPoint = new EntryPoint();
         $entryPoint->setType(0);
         $entryPoint->setPath($code);
         $entryPoint->setChildren($config->getEntryPoints());
         $entryPoint->setBundle($config);
         return $entryPoint;
     }
     $entryPoint = null;
     if ($config) {
         while (!($entryPoint = $config->getEntryPoint($path))) {
             if (false === strpos($path, '/')) {
                 break;
             }
             $path = substr($path, 0, strrpos($path, '/'));
         }
     }
     return $entryPoint;
 }
Beispiel #2
0
 /**
  * Setup AutoCrud
  *
  * @param \Jarves\Configuration\Bundle[] $bundleConfigs
  */
 protected function setupObjects(array $bundleConfigs)
 {
     $objectsEntryPoint = $bundleConfigs['jarves']->getEntryPoint('object');
     foreach ($bundleConfigs as $bundleConfig) {
         /** @var EntryPoint[][] $objectEntryPoints */
         $objectEntryPoints = [];
         //read all entry points for each object
         if ($bundleConfig->getAllEntryPoints()) {
             foreach ($bundleConfig->getAllEntryPoints() as $entryPoint) {
                 if ($entryPoint->getObject()) {
                     $objectEntryPoints[$entryPoint->getObject()][$entryPoint->getType()] = $entryPoint;
                 }
             }
         }
         $entryPointsForThisBundle = [];
         if ($bundleConfig->getObjects()) {
             foreach ($bundleConfig->getObjects() as $object) {
                 if (!isset($objectEntryPoints[$object->getKey()])) {
                     //this object does not have any entry point to manage.
                     if (!$object->getAutoCrud()) {
                         //jarves should not autobuild entry points
                         continue;
                     }
                     $entryPoint = new EntryPoint();
                     $entryPoint->setPath(lcfirst($object->getId()));
                     $entryPoint->setType('combine');
                     $entryPoint->setObject($object->getKey());
                     $entryPoint->setLink(true);
                     $entryPoint->setIcon('#' . ($object->isNested() ? 'icon-list-nested' : 'icon-list'));
                     $entryPoint->setLabel($object->getLabel() ?: $object->getKey());
                     $entryPointsForThisBundle[] = $entryPoint;
                     $objectEntryPoints[$entryPoint->getObject()][$entryPoint->getType()] = $entryPoint;
                 }
             }
         }
         if ($entryPointsForThisBundle) {
             //we added some autoCrud entry points
             $bundleObjectContainerEntryPoint = new EntryPoint();
             $bundleObjectContainerEntryPoint->setPath($bundleConfig->getName());
             $bundleObjectContainerEntryPoint->setLink(true);
             $bundleObjectContainerEntryPoint->setLabel($bundleConfig->getLabel() ?: $bundleConfig->getBundleName());
             $objectsEntryPoint->addChildren($bundleObjectContainerEntryPoint);
             foreach ($entryPointsForThisBundle as $entryPoint) {
                 $bundleObjectContainerEntryPoint->addChildren($entryPoint);
             }
         }
         if ($bundleConfig->getObjects()) {
             foreach ($bundleConfig->getObjects() as $object) {
                 //setup addEntrypoint, editEntrypoint, listEntrypoint if not set already
                 if (isset($objectEntryPoints[$object->getKey()]['combine'])) {
                     if (!$object->getAddEntryPoint()) {
                         $object->setAddEntryPoint($objectEntryPoints[$object->getKey()]['combine']->getFullPath());
                     }
                     if (!$object->getEditEntryPoint()) {
                         $object->setEditEntryPoint($objectEntryPoints[$object->getKey()]['combine']->getFullPath());
                     }
                     if (!$object->getListEntryPoint()) {
                         $object->setListEntryPoint($objectEntryPoints[$object->getKey()]['combine']->getFullPath());
                     }
                 }
                 if ($object->getAddEntryPoint() && isset($objectEntryPoints[$object->getKey()]['add'])) {
                     $object->setAddEntryPoint($objectEntryPoints[$object->getKey()]['add']->getFullPath());
                 }
                 if ($object->getEditEntryPoint() && isset($objectEntryPoints[$object->getKey()]['edit'])) {
                     $object->setEditEntryPoint($objectEntryPoints[$object->getKey()]['edit']->getFullPath());
                 }
                 if ($object->getListEntryPoint() && isset($objectEntryPoints[$object->getKey()]['list'])) {
                     $object->setListEntryPoint($objectEntryPoints[$object->getKey()]['list']->getFullPath());
                 }
             }
         }
     }
 }