protected function getTemplateParameters() { $entity = $this->getPayload('subject'); $group_parts = (array) $this->getOption('group_parts', []); $parent_attribute = $entity->getType()->getParentAttribute(); $params = parent::getTemplateParameters(); $params['has_parent_attribute'] = $parent_attribute !== null; $params['grouped_base_path'] = ArrayToolkit::flattenToArrayPath($group_parts); $params['resource'] = $entity->toArray(); $params['entity_type'] = $entity->getType()->getPrefix(); $params['is_embed_template'] = $this->getOption('is_embed_template', false); $params['is_new'] = !$entity->hasValue('identifier'); // when entity is part of a list (embed or reference) $params['add_item_to_parent_list_allowed'] = $this->getOption('add_item_to_parent_list_allowed', true); // custom title+decription per-embedded-item in an EntityList attribute if (!$entity->getType()->isRoot()) { $params['embed_item_title'] = $this->getOption('entity_title', 'entity_title'); $params['embed_item_description'] = $this->getOption('entity_description', 'entity_description'); } $params = array_replace_recursive($this->lookupViewTemplate(), $params); $params['rendered_fields'] = $this->getRenderedFields($entity, $params['view_template']); if ($entity instanceof ProjectionInterface && $entity->getWorkflowState()) { $params['rendered_resource_activities'] = $this->getResourceActivities($entity); } return $params; }
protected function getTemplateParameters() { $params = parent::getDefaultTemplateParameters(); $resource = $this->getPayload('subject'); $parent_attribute = $resource->getType()->getParentAttribute(); $group_parts = (array) $this->getOption('group_parts', []); $params['grouped_base_path'] = ArrayToolkit::flattenToArrayPath($group_parts); $params['is_embed_template'] = $this->getOption('is_embed_template', false); $params['has_parent_attribute'] = $parent_attribute !== null; $params['html_attributes'] = $this->getOption('html_attributes', []); $params['image_disabled'] = $this->getOption('image_disabled', false); $params['resource'] = $resource->toNative(); $params['is_new'] = !$resource->hasValue('identifier'); $params['css'] = $this->getOption('css', ''); $params = array_replace_recursive($this->lookupViewTemplate(), $params); if ($this->hasOption('view_template_name')) { // use view_template $params['rendered_fields'] = $this->getRenderedFields($resource, $params['view_template']); $params['css'] .= $params['is_new'] ? ' hb-glance--empty' : null; } else { // get default values if (!$params['image_disabled']) { $image = $this->getGlanceImage($resource, $params['view_template']); $params['image_width'] = $this->getOption('image_width', $image['width']); $params['image_height'] = $this->getOption('image_height', $image['height']); $params['image_url'] = $image['location']; } $params['title'] = $this->getGlanceTitle($resource, $params['view_template']); $params['description'] = $this->getGlanceDescription($resource, $params['view_template']); } return $params; }
protected function getPayloadPath($attribute_value_path) { $path_parts = explode('.', $attribute_value_path); if ($base = (string) $this->getBase()) { array_unshift($path_parts, $base); } return ArrayToolkit::flattenToArrayPath($path_parts); }
protected function getGroupedInputFieldName() { $entity_type = $this->attribute->getType(); $group_parts = $this->getOption('group_parts', []); if ($group_parts instanceof SettingsInterface) { $group_parts = $group_parts->toArray(); } elseif (!is_array($group_parts)) { throw new RuntimeError('Invalid value type given for "group_parts" option. Only arrays are supported here.'); } $value_path = $this->getOption('attribute_value_path'); $field_specific_group_parts = explode('.', $this->attribute->getPath()); if (!empty($value_path)) { $value_path_group_parts = explode('.', $value_path); $calc_index = 1; foreach ($value_path_group_parts as $actual_idx => $value_path_group_part) { if ($calc_index % 2 === 0) { if (preg_match('/[\\w\\*]+\\[(\\d+)\\]/', $value_path_group_part, $matches)) { $group_parts[] = $matches[1]; } else { throw new RuntimeError(sprintf('Invalid attribute_value_path "%s" given to renderer "%s" for field "%s".' . ' Missing expected embed index within path specification.', $value_path, static::CLASS, $this->attribute->getPath())); } } else { $group_parts[] = $value_path_group_part; } $calc_index++; } } else { if ($this->attribute->getType()->isRoot()) { $group_parts = array_merge($group_parts, explode('.', $this->attribute->getPath())); } else { $group_parts[] = $this->attribute->getName(); } } return ArrayToolkit::flattenToArrayPath($group_parts); }