Inheritance: extends Model
Example #1
0
 public function bootRunTime(Object $object, Configs $configs)
 {
     if (!$object->hasRelation($this->getFieldDefinition()->getId())) {
         $relation = new RelationDefinition();
         $relation->setName($this->getFieldDefinition()->getId());
         $relation->setType(AbstractStorage::ONE_TO_MANY);
         $relation->setForeignObjectKey('jarves/content');
         $relation->setRefName($object->getId());
         $object->addRelation($relation);
         $configs->addReboot('Added auto relation because of PageContents type.');
     }
     if (!$object->hasField('layout')) {
         $field = new Field();
         $field->setId('layout');
         $field->setType('text');
         $object->addField($field);
         $configs->addReboot('PageContents needs `layout` field.');
     }
     if (!$object->hasField('theme')) {
         $field = new Field();
         $field->setId('theme');
         $field->setType('text');
         $object->addField($field);
         $configs->addReboot('PageContents needs `theme field.');
     }
 }
Example #2
0
 public function testPluginConfigPhp()
 {
     $plugin = new Plugin();
     $plugin->setId('listing');
     $plugin->setLabel('News Listing');
     $plugin->setController('Publication\\Controller\\Plugin\\News:listing');
     $route1 = new Route();
     $route1->setPattern('{page}');
     $route1->addDefault(new RouteDefault(['key' => 'page', 'value' => 1]));
     $route1->addRequirement(new RouteRequirement(['key' => 'page', 'value' => '\\d']));
     $plugin->addRoute($route1);
     $route2 = new Route(null, $this->getJarves());
     $route2->setPattern('{slug}');
     $route2->addRequirement(new RouteRequirement(['key' => 'page', 'value' => '[^/]+']));
     $plugin->addRoute($route2);
     $field1 = new Field(null, $this->getJarves());
     $field1->setId('template');
     $field1->setType('view');
     $field1->setLabel('Template');
     $field1->setOption('directory', '@PublicationBundle/news/list/');
     $field2 = new Field(null, $this->getJarves());
     $field2->setId('itemsPerPage');
     $field2->setType('number');
     $field2->setLabel('Items per page');
     $field2->setDefault(10);
     $field3 = new Field(null, $this->getJarves());
     $field3->setId('detailPage');
     $field3->setType('object');
     $field3->setLabel('Detail page');
     $field3->setObject('JarvesBundle:Node');
     $plugin->addOption($field1);
     $plugin->addOption($field2);
     $plugin->addOption($field3);
     $this->valueTest($plugin);
 }
Example #3
0
 /**
  * @param Field $field
  */
 public function addField(Field $field)
 {
     $field->setForm($this);
     $this->fields[] = $field;
 }
Example #4
0
 /**
  * @param Field $field
  */
 public function addField(Field $field)
 {
     $field->setObjectDefinition($this);
     $this->fields[$field->getColumnName()] = $field;
 }
Example #5
0
 /**
  * @param \Jarves\Configuration\Object $objectDefinition
  * @param Configs $configs
  * @return bool
  */
 protected function defineCrossObject(Object $objectDefinition, Configs $configs)
 {
     $changed = false;
     $bundle = $objectDefinition->getBundle();
     $foreignObjectDefinition = $configs->getObject($this->getFieldDefinition()->getObject());
     $possibleObjectName = ucfirst($objectDefinition->getId()) . ucfirst($foreignObjectDefinition->getId());
     $possibleObjectKey = $bundle->getName() . '/' . $possibleObjectName;
     if (!($crossObjectKey = $this->getFieldDefinition()->getObjectRelationCrossObjectKey())) {
         $crossObjectKey = $possibleObjectKey;
     }
     $crossObject = $configs->getObject($crossObjectKey);
     if (!$crossObject) {
         if (!($crossObject = $configs->getObject($possibleObjectKey))) {
             $crossObject = new Object(null, $objectDefinition->getJarves());
             $crossObject->setId($possibleObjectName);
             $crossObject->setSearchable(false);
             $crossObject->setAutoCrud(false);
             $crossObject->setExcludeFromREST(true);
             $crossObject->setTable($objectDefinition->getTable() . '_' . Tools::camelcase2Underscore($foreignObjectDefinition->getId()));
             $changed = true;
         }
     }
     if (!$crossObject->isCrossRef()) {
         $crossObject->setCrossRef(true);
         $changed = true;
     }
     $leftFieldName = $this->getFieldDefinition()->getObjectRefRelationName() ?: $objectDefinition->getId();
     if (!$crossObject->getField($leftFieldName)) {
         $leftObjectField = new Field(null, $objectDefinition->getJarves());
         $leftObjectField->setId($leftFieldName);
         $leftObjectField->setType('object');
         $leftObjectField->setObject($objectDefinition->getKey());
         $leftObjectField->setObjectRelation(AbstractStorage::ONE_TO_ONE);
         $leftObjectField->setPrimaryKey(true);
         $crossObject->addField($leftObjectField);
         $changed = true;
     }
     if (!$crossObject->getField($this->getFieldDefinition()->getId())) {
         $rightObjectField = new Field(null, $objectDefinition->getJarves());
         $rightObjectField->setId($this->getFieldDefinition()->getId());
         $rightObjectField->setType('object');
         $rightObjectField->setObject($foreignObjectDefinition->getKey());
         $rightObjectField->setObjectRelation(AbstractStorage::ONE_TO_ONE);
         $rightObjectField->setPrimaryKey(true);
         $crossObject->addField($rightObjectField);
         $changed = true;
     }
     if (!$crossObject->getBundle()) {
         //we created a new object
         $bundle->addObject($crossObject);
     }
     return $changed;
 }
Example #6
0
    public function testObjectBrowserColumns()
    {
        $xml = '<object id="View">
  <label>Template View</label>
  <desc>Template views</desc>
  <storageService>\\Admin\\ObjectView</storageService>
  <labelField>name</labelField>
  <nested>true</nested>
  <fields>
    <field id="path" type="text" primaryKey="true">
      <label>Path</label>
    </field>
    <field id="name" type="text">
      <label>File name</label>
    </field>
  </fields>
  <browserColumns>
    <field id="path" type="text">
      <label>Path</label>
    </field>
    <field id="name" type="text">
      <label>File name</label>
    </field>
  </browserColumns>
</object>';
        $object = new Object(null, $this->getJarves());
        $object->setId('View');
        $object->setLabel('Template View');
        $object->setDesc('Template views');
        $object->setLabelField('name');
        $object->setNested(true);
        $object->setStorageService('\\Admin\\ObjectView');
        $field1 = new Field(null, $this->getJarves());
        $field1->setId('path');
        $field1->setPrimaryKey(true);
        $field1->setLabel('Path');
        $field1->setType('text');
        $field2 = new Field(null, $this->getJarves());
        $field2->setId('name');
        $field2->setLabel('File name');
        $field2->setType('text');
        $object->setFields(array($field1, $field2));
        $field1 = new Field(null, $this->getJarves());
        $field1->setId('path');
        $field1->setLabel('Path');
        $field1->setType('text');
        $field2 = new Field(null, $this->getJarves());
        $field2->setId('name');
        $field2->setLabel('File name');
        $field2->setType('text');
        $object->setBrowserColumns(array($field1, $field2));
        $reverse = new Object($xml, $this->getJarves());
        $this->assertEquals($xml, $object->toXml());
        $this->assertEquals($xml, $reverse->toXml());
    }
Example #7
0
 /**
  * Makes sure $this->_fields has a language field when multiLanguage=true
  */
 protected function ensureLanguageField()
 {
     if ($this->getMultiLanguage() && !isset($this->_fields['lang'])) {
         $langField = new Field(null, $this->jarves);
         $langField->setId('lang');
         $langField->setType('text');
         $langField->setRequired(true);
         $this->_fields['lang'] = $langField;
     }
 }
Example #8
0
 public function setupRoutes(Bundle $config, $controller, $pattern, $objectSection, Object $object, Object $relationObject = null, Field $relationField = null)
 {
     /** @var $importedRoutes \Symfony\Component\Routing\RouteCollection */
     $importedRoutes = $this->import($controller, 'rest');
     /** @var $route \Symfony\Component\Routing\Route */
     foreach ($importedRoutes as $name => $route) {
         $method = explode(':', $route->getDefault('_controller'))[1];
         $routePattern = $route->getPath();
         $route->setPath($pattern);
         if ($relationObject) {
             $this->setupObjectRouteRequirements($route, $relationObject, true);
         }
         $path = $route->getPath() . $routePattern;
         $path = str_replace('.{_format}', '', $path);
         $route->setPath($path);
         $route->setDefault('_jarves_object_requirePk', !!strpos($routePattern, '{pk}'));
         $this->setupObjectRouteRequirements($route, $object);
         $route->setDefault('_jarves_object', $object->getKey());
         $route->setDefault('_jarves_crud_definition', $object->getApiControllerDefinition());
         $route->setDefault('_jarves_object_section', $objectSection);
         $route->setDefault('_jarves_object_relation', $relationField ? $relationField->getId() : false);
         $name = str_replace('/', '_', $pattern . $routePattern) . '_' . $method;
         $name = str_replace(['{', '}'], '', $name);
         $name = str_replace('%jarves_admin_prefix%_', 'jarves_', $name);
         $this->routes->add($name, $route);
     }
 }