getTemplatefields() public method

public getTemplatefields ( )
コード例 #1
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);
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
ファイル: RecordModifier.php プロジェクト: edvardio/bolt
 /**
  * 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);
 }