Inheritance: extends Bolt\Storage\Entity\Entity, use trait ContentRouteTrait, use trait Bolt\Storage\Mapping\ContentTypeTitleTrait
示例#1
0
 public function testCaseTransform()
 {
     $entity = new Content();
     $underscore = 'bolt_field_example';
     $camel = 'boltFieldExample';
     $camel2 = 'BoltFieldExample';
     $this->assertEquals('BoltFieldExample', $entity->camelize($underscore));
     $this->assertEquals('bolt_field_example', $entity->underscore($camel));
     $this->assertEquals('bolt_field_example', $entity->underscore($camel2));
 }
示例#2
0
 /**
  * Dispatch the update event.
  *
  * @param Content $content
  * @param string  $type
  * @param string  $legacyType
  */
 private function dispatch(Content $content, $type, $legacyType)
 {
     $event = new StorageEvent($content, ['contenttype' => $content->getContenttype(), 'create' => false]);
     try {
         $this->dispatcher->dispatch("timed.{$type}", $event);
     } catch (\Exception $e) {
         $this->systemLogger->critical(sprintf('Dispatch handling failed for %s.', $content->getContenttype()), ['event' => 'exception', 'exception' => $e]);
     }
     try {
         /** @deprecated Deprecated since 3.1, to be removed in 4.0. */
         $this->dispatcher->dispatch("timed.{$legacyType}", $event);
     } catch (\Exception $e) {
         $this->systemLogger->critical(sprintf('Dispatch handling failed for %s.', $content->getContenttype()), ['event' => 'exception', 'exception' => $e]);
     }
 }
 /**
  * Generate tab groups.
  * Changed to include $content and $incomingNotInverted which we need for
  * templatefields and relations respectivley.
  *
  * @param array   $contentType
  * @param array   $has
  * @param Content $content
  * @param array   $incomingNotInverted
  *
  * @return array
  */
 private function createGroupTabs(array $contentType, array $has, Content $content, $incomingNotInverted)
 {
     $groups = [];
     $groupIds = [];
     $addGroup = function ($group, $label) use(&$groups, &$groupIds) {
         $nr = count($groups) + 1;
         $id = rtrim('tab-' . Slugify::create()->slugify($group), '-');
         if (isset($groupIds[$id]) || $id === 'tab') {
             $id .= '-' . $nr;
         }
         $groups[$group] = ['label' => $label, 'id' => $id, 'is_active' => $nr === 1, 'fields' => []];
         $groupIds[$id] = 1;
     };
     foreach ($contentType['groups'] ? $contentType['groups'] : ['ungrouped'] as $group) {
         $default = ['DEFAULT' => ucfirst($group)];
         $key = ['contenttypes', $contentType['slug'], 'group', $group];
         $addGroup($group, Trans::__($key, $default));
     }
     /*
      * Create groups for templatefields
      */
     if ($content->getTemplatefields()) {
         $currentGroup = 'template';
         foreach ($content->getTemplatefields()->getContenttype()['fields'] as $fieldName => $field) {
             $group = $field['group'] === 'ungrouped' ? $currentGroup : $field['group'];
             if (!array_key_exists($group, $groups)) {
                 $default = ['DEFAULT' => ucfirst($group)];
                 $key = ['contenttypes', $contentType['slug'], 'group', $group];
                 $addGroup($group, Trans::__($key, $default));
             }
             $groups[$group]['fields'][] = 'templatefield_' . $fieldName;
         }
     }
     /*
      * Create groups for relations
      */
     $currentGroup = 'relations';
     foreach ($contentType['relations'] as $relationName => $relation) {
         if (!array_key_exists($relationName, $incomingNotInverted)) {
             $group = isset($relation['group']) ? $relation['group'] : $currentGroup;
             if (!array_key_exists($group, $groups)) {
                 $default = ['DEFAULT' => ucfirst($group)];
                 $key = ['contenttypes', $contentType['slug'], 'group', $group];
                 $addGroup($group, Trans::__($key, $default));
             }
             $groups[$group]['fields'][] = 'relation_' . $relationName;
         }
     }
     /*
      * Create groups for taxonomy
      */
     $currentGroup = 'taxonomy';
     foreach ($contentType['taxonomy'] as $taxonomy) {
         $taxonomyConfig = $this->config->get('taxonomy')[$taxonomy];
         $group = isset($taxonomyConfig['group']) ? $taxonomyConfig['group'] : $currentGroup;
         if (!array_key_exists($group, $groups)) {
             $default = ['DEFAULT' => ucfirst($group)];
             $key = ['contenttypes', $contentType['slug'], 'group', $group];
             $addGroup($group, Trans::__($key, $default));
         }
         $groups[$group]['fields'][] = 'taxonomy_' . $taxonomy;
     }
     $addGroup('meta', Trans::__('contenttypes.generic.group.meta'));
     $groups['meta']['fields'][] = '*meta';
     // References fields in tab group data.
     foreach ($contentType['fields'] as $fieldName => $field) {
         $groups[$field['group']]['fields'][] = $fieldName;
     }
     return $groups;
 }
示例#4
0
文件: Edit.php 项目: bolt/bolt
 /**
  * Create a list of fields types used in regular, template and virtual fields.
  *
  * @param ContentType $contentType
  * @param Content     $content
  * @param array       $has
  *
  * @return array
  */
 private function getUsedFieldtypes(ContentType $contentType, Content $content, array $has)
 {
     $fieldtypes = ['meta' => true];
     if ($content->getTemplatefields() instanceof TemplateFields) {
         $templateFields = $content->getTemplatefields()->getContenttype()->getFields() ?: [];
     } else {
         $templateFields = [];
     }
     foreach ([$contentType['fields'], $templateFields] as $fields) {
         foreach ($fields as $field) {
             $fieldtypes[$field['type']] = true;
         }
         if ($field['type'] === 'repeater') {
             foreach ($field['fields'] as $rfield) {
                 $fieldtypes[$rfield['type']] = true;
             }
         }
     }
     if ($has['relations'] || $has['incoming_relations']) {
         $fieldtypes['relationship'] = true;
     }
     if ($has['taxonomy'] || is_array($contentType['groups']) && in_array('taxonomy', $contentType['groups'])) {
         $fieldtypes['taxonomy'] = true;
     }
     if ($has['templatefields'] || is_array($contentType['groups']) && in_array('template', $contentType['groups'])) {
         $fieldtypes['template'] = true;
     }
     return array_keys($fieldtypes);
 }
示例#5
0
 /**
  * Create a list of fields types used in regular, template and virtual fields.
  *
  * @param array   $contenttype
  * @param Content $content
  * @param array   $has
  *
  * @return array
  */
 private function getUsedFieldtypes(array $contenttype, Content $content, array $has)
 {
     $fieldtypes = ['meta' => true];
     foreach ([$contenttype['fields'], $content->getTemplatefields() ?: []] as $fields) {
         foreach ($fields as $field) {
             $fieldtypes[$field['type']] = true;
         }
     }
     if ($has['relations'] || $has['incoming_relations']) {
         $fieldtypes['relationship'] = true;
     }
     if ($has['taxonomy'] || is_array($contenttype['groups']) && in_array('taxonomy', $contenttype['groups'])) {
         $fieldtypes['taxonomy'] = true;
     }
     if ($has['templatefields'] || is_array($contenttype['groups']) && in_array('template', $contenttype['groups'])) {
         $fieldtypes['template'] = true;
     }
     return array_keys($fieldtypes);
 }
示例#6
0
 /**
  * Transition a record's owner if permitted.
  *
  * @param Content $entity
  * @param integer $ownerId
  */
 protected function transistionRecordOwner(Content $entity, $ownerId)
 {
     $recordId = $entity->getId();
     $contentTypeName = (string) $entity->getContenttype();
     $canChangeOwner = $this->users->isAllowed("contenttype:{$contentTypeName}:change-ownership:{$recordId}");
     if (!$canChangeOwner) {
         $this->loggerFlash->error(Trans::__('general.access-denied.content-not-modified', ['%title%' => $entity->getTitle()]));
         return;
     }
     $entity->setOwnerid($ownerId);
     $entity->_modified = true;
 }
示例#7
0
文件: Save.php 项目: Twiebie/bolt
 /**
  * Add a change log entry to track the change.
  *
  * @param string              $contentType
  * @param integer             $contentId
  * @param Entity\Content      $newContent
  * @param Entity\Content|null $oldContent
  * @param string|null         $comment
  */
 private function logChange($contentType, $contentId, $newContent = null, $oldContent = null, $comment = null)
 {
     $type = $oldContent ? 'Update' : 'Insert';
     $this->loggerChange->info($type . ' record', ['action' => strtoupper($type), 'contenttype' => $contentType, 'id' => $contentId, 'new' => $newContent ? $newContent->toArray() : null, 'old' => $oldContent ? $oldContent->toArray() : null, 'comment' => $comment]);
 }
示例#8
0
文件: Relations.php 项目: bolt/bolt
 /**
  * Identifies which relations are incoming to the given entity
  *
  * @param Entity\Content $entity
  *
  * @return mixed
  */
 public function incoming(Entity\Content $entity)
 {
     return $this->filter(function ($el) use($entity) {
         /** @var Entity\Relations $el */
         return $el->getToContenttype() == (string) $entity->getContenttype() && $el->getToId() === $entity->getId();
     });
 }