} $percentages_and_css_classes[$key] = array("percentage" => $percentage, 'css_class' => $css_class); } $index++; } print '<div class="node-diagram"><dl>'; foreach ($statistical_metadata as $key => $value) { print '<dt>' . $statistical_metadata_labels[$key] . '</dt>'; print '<dd style="width:' . $percentages_and_css_classes[$key]['percentage'] . '% !important" class="' . $percentages_and_css_classes[$key]['css_class'] . '">' . $value . '</dd>'; } print '</dl></div>'; } ?> <?php $group_info = field_group_info_groups("node", $node->type, "full"); $group_markup = array(); foreach ($group_info as $key => $value) { $group_markup[$key] = eige_administrative_data_get_group_markup($value); } ?> <div id="eige-additional-data" class="section"> <?php $group = isset($content['group_additional_data']) ? $content['group_additional_data'] : array(); ?> <?php print $group_markup['group_additional_data']['#prefix']; ?> <?php
/** * Test the accordion formatter. */ function testAccordion() { $data = array('label' => 'Accordion item 1', 'weight' => '1', 'children' => array(0 => 'field_test'), 'format_type' => 'accordion-item', 'format_settings' => array('label' => 'Accordion item 1', 'instance_settings' => array('classes' => 'test-class'), 'formatter' => 'closed')); $first_item = $this->createGroup('default', $data); $first_item_id = 'node_article_full_' . $first_item->group_name; $data = array('label' => 'Accordion item 2', 'weight' => '1', 'children' => array(0 => 'field_test_2'), 'format_type' => 'accordion-item', 'format_settings' => array('label' => 'Tab 2', 'instance_settings' => array('classes' => 'test-class-2'), 'formatter' => 'open')); $second_item = $this->createGroup('default', $data); $second_item_id = 'node_article_full_' . $second_item->group_name; $data = array('label' => 'Accordion', 'weight' => '1', 'children' => array(0 => $first_item->group_name, 1 => $second_item->group_name), 'format_type' => 'accordion', 'format_settings' => array('label' => 'Tab 1', 'instance_settings' => array('classes' => 'test-class-wrapper', 'effect' => 'bounceslide'))); $accordion = $this->createGroup('default', $data); $groups = field_group_info_groups('node', 'article', 'default', TRUE); $this->drupalGet('node/' . $this->node->nid); // Test properties. $this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]", NULL, t('Test class set on tabs wrapper')); $this->assertFieldByXPath("//div[contains(@class, 'effect-bounceslide')]", NULL, t('Correct effect is set on the accordion')); $this->assertFieldByXPath("//div[contains(@class, 'test-class')]", NULL, t('Accordion item with test-class is shown')); $this->assertFieldByXPath("//div[contains(@class, 'test-class-2')]", NULL, t('Accordion item with test-class-2 is shown')); $this->assertFieldByXPath("//h3[contains(@class, 'field-group-accordion-active')]", NULL, t('Accordion item 2 was set active')); // Test if correctly nested $this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//div[contains(@class, 'test-class')]", NULL, 'First item is displayed as child of the wrapper.'); $this->assertFieldByXPath("//div[contains(@class, 'test-class-wrapper')]//div[contains(@class, 'test-class-2')]", NULL, 'Second item is displayed as child of the wrapper.'); }
/** * {@inheritdoc} */ public function render() { $rows = array(); // If the Data Entity row plugin is used, this will be an array of entities // which will pass through Serializer to one of the registered Normalizers, // which will transform it to arrays/scalars. If the Data field row plugin // is used, $rows will not contain objects and will pass directly to the // Encoder. foreach ($this->view->result as $row) { $tmpArrRender = $this->view->rowPlugin->render($row); /** * @var $entity \Drupal\node\Entity\Node * @var $fieldData \Drupal\Core\Field\FieldItemList|\Drupal\Core\Field\EntityReferenceFieldItemList * @var $imageData \Drupal\image\Plugin\Field\FieldType\ImageItem|\Drupal\Core\Entity\Plugin\DataType\EntityReference * @var $imageEntity \Drupal\Core\Entity\Plugin\DataType\EntityReference|\Drupal\file\Entity\File */ $fields = array(); $fieldGroup = array(); $entity = $row->_entity; //could there be groups? if (function_exists('field_group_load_field_group')) { $groupingData = field_group_info_groups($entity->getEntityTypeId(), $entity->bundle(), 'view', 'api_structure'); if (is_array($groupingData) && count($groupingData) > 0) { foreach ($groupingData as $groupName => $group) { $parent = $group->parent_name; if (empty($parent)) { //if we're a base group add us to fields $fields[$groupName] = array(); } else { //if we have a parent find it and add ourselves $this->add_array_recursive($fields, $parent, $groupName); } //store group names foreach ($group->children as $childName) { if (substr($childName, 0, 6) !== "group_") { $fieldGroup[$childName] = $groupName; } } } } } foreach ($entity->getFields() as $fieldID => $fieldData) { $val = null; // if of type image if ($fieldData->getFieldDefinition()->getType() === "image") { if (array_key_exists($fieldID, $tmpArrRender)) { $val = array(); foreach ($fieldData as $imageData) { $imageEntity = $imageData->getProperties(true)['entity']->getValue(); $val[] = array("alt" => $imageData->getValue()['alt'], "file" => str_replace(array("http:", "https:"), "", file_create_url(file_build_uri($imageEntity->getFilename()))), "type" => $imageEntity->getMimeType(), "size" => $imageEntity->getSize()); } } } // if of type entity_reference if ($fieldData->getFieldDefinition()->getType() === "entity_reference") { if (array_key_exists($fieldID, $tmpArrRender)) { $val = $tmpArrRender[$fieldID]; $valDecode = json_decode($val, TRUE); if ($fieldID == "field_technologies") { $val = array(); foreach ($fieldData->getValue() as $referencedTechnology) { $node = node_load($referencedTechnology['target_id']); $title = $node->getFields()['title']->getValue()[0]['value']; if (array_key_exists(0, $node->getFields()['field_marketing_url']->getValue())) { $url = $node->getFields()['field_marketing_url']->getValue()[0]['value']; } else { $url = ""; } $val[] = array("title" => $title, "field_marketing_url" => $url); } } else { if ($valDecode !== NULL && is_array($valDecode)) { $val = $valDecode; array_walk_recursive($val, function (&$item) { if (!is_array($item)) { $item = htmlspecialchars_decode(html_entity_decode(urldecode($item), ENT_QUOTES)); } }); } } } } //make boolean a literal bool rather than string if ($fieldData->getFieldDefinition()->getType() === "boolean") { if (array_key_exists($fieldID, $tmpArrRender)) { $val = $tmpArrRender[$fieldID]; if ($val) { $val = true; } else { $val = false; } } } //clean everything we get from json theme if ($val === null && array_key_exists($fieldID, $tmpArrRender)) { $decodedData = json_decode($tmpArrRender[$fieldID], true); if ($decodedData !== null && is_array($decodedData)) { array_walk_recursive($decodedData, function (&$item) { if (!is_array($item)) { $item = htmlspecialchars_decode(html_entity_decode(urldecode($item), ENT_QUOTES)); } }); $val = $decodedData; } else { $val = htmlspecialchars_decode(html_entity_decode(urldecode($tmpArrRender[$fieldID]), ENT_QUOTES)); } } if ($val !== null and !empty($val)) { // Create leaf $leaf = array("type" => $fieldData->getFieldDefinition()->getType(), "value" => $val); if (isset($fieldGroup[$fieldID])) { $groupName = $fieldGroup[$fieldID]; $this->add_array_recursive($fields, $groupName, $fieldID, $leaf); } else { $fields[$fieldID] = $leaf; } } } $tmpArr = array("type" => $entity->getType(), "changed" => date("c", $entity->getChangedTime()), "fields" => $fields); //assign to working array $rows[] = $tmpArr; } // Get the content type configured in the display or fallback to the // default. if (empty($this->view->live_preview)) { $content_type = $this->displayHandler->getContentType(); } else { $content_type = !empty($this->options['formats']) ? reset($this->options['formats']) : 'json'; } return $this->serializer->serialize($rows, $content_type); }