public function displayPublishPanel(SymphonyDOMElement $wrapper, MessageStack $errors, Entry $entry = null, $data = null) { $joined = null; $document = $wrapper->ownerDocument; $xpath = new DOMXPath($document); $driver = Extension::load('field_join'); $driver->addPublishHeaders($document); $sortorder = $this->{'sortorder'}; $element_name = $this->{'element-name'}; $wrapper->setAttribute('data-label', $this->{'publish-label'}); $wrapper->setAttribute('data-show-header', $this->{'show-header'}); if ($this->{'required'} != 'yes') { $wrapper->setAttribute('data-optional', __('Choose a section...')); } //var_dump($data); exit; if (isset($data->joined_id)) { $joined = Entry::loadFromId($data->joined_id); } // Use existing entry: if ($joined instanceof Entry) { $section = Section::loadFromHandle($joined->section); $context = $document->createElement('div'); $context->setAttribute('data-handle', $section->handle); $context->setAttribute('data-name', $section->name); $context->addClass('context'); $fields = array(); foreach ($section->fields as $index => $instance) { $fields[$instance->{'element-name'}] = $instance; } $this->displayJoinedPublishPanel($context, $section, $fields, $errors, $joined); // Replace field names: foreach ($xpath->query('.//*[starts-with(@name, "fields[")]', $context) as $node) { $name = $node->getAttribute('name'); $name = sprintf('fields[%s][%s]%s', $this->{'element-name'}, $joined->id, preg_replace('%^fields%', null, $name)); $node->setAttribute('name', $name); } $wrapper->appendChild($context); } else { foreach ($this->{'joinable-sections'} as $handle) { try { $section = Section::loadFromHandle($handle); } catch (Exception $e) { continue; } $context = $document->createElement('div'); $context->setAttribute('data-handle', $section->handle); $context->setAttribute('data-name', $section->name); $context->addClass('context'); $fields = $values = array(); $joined = new Entry(); //var_dump($data); if (isset($data[$section->handle])) { $values = $data[$section->handle]; } foreach ($section->fields as $index => $instance) { $handle = $instance->{'element-name'}; $fields[$handle] = $instance; if (isset($values[$handle])) { $joined->data()->{$handle} = $values[$handle]; } } $this->displayJoinedPublishPanel($context, $section, $fields, $errors, $joined); // Replace field names: foreach ($xpath->query('.//*[starts-with(@name, "fields[")]', $context) as $node) { $name = $node->getAttribute('name'); $name = sprintf('fields[%s][%s]%s', $this->{'element-name'}, $section->handle, preg_replace('%^fields%', null, $name)); $node->setAttribute('name', $name); } $wrapper->appendChild($context); } } }