protected function appendFilter(Duplicator $duplicator, $handle, $name, $value = NULL) { $document = $duplicator->ownerDocument; if (is_null($value)) { $item = $duplicator->createTemplate($name); } else { $item = $duplicator->createInstance($name); } $group = $document->createElement('div'); $group->setAttribute('class', 'group double'); // Value $label = $document->createElement('label', __('Value')); $input = Widget::Input('fields[filters][' . $handle . ']'); if (!is_null($value)) { $input->setAttribute("value", $value); } $label->appendChild($input); $group->appendChild($label); $group->appendChild($label); $item->appendChild($group); }
protected function appendDuplicator(SymphonyDOMElement $wrapper, Section $section, array $items = null) { $document = $wrapper->ownerDocument; $duplicator = new Duplicator(__('Add Item')); $duplicator->addClass('context context-' . $section->handle); $item = $duplicator->createTemplate(__('Override')); $label = Widget::Label(__('Field')); $options = array(array('system:id', false, 'System ID')); foreach ($section->fields as $f) { $options[] = array(General::sanitize($f->{'element-name'}), false, General::sanitize($f->{'publish-label'})); } $label->appendChild(Widget::Select('fields[overrides][field][]', $options)); $item->appendChild($label); $label = Widget::Label(__('Replacement')); $label->appendChild(Widget::Input('fields[overrides][replacement][]')); $item->appendChild($label); $item = $duplicator->createTemplate(__('Default Value')); $label = Widget::Label(__('Field')); $options = array(array('system:id', false, 'System ID')); foreach ($section->fields as $f) { $options[] = array(General::sanitize($f->{'element-name'}), false, General::sanitize($f->{'publish-label'})); } $label->appendChild(Widget::Select('fields[defaults][field][]', $options)); $item->appendChild($label); $label = Widget::Label(__('Replacement')); $label->appendChild(Widget::Input('fields[defaults][replacement][]')); $item->appendChild($label); if (is_array($items['overrides'])) { foreach ($items['overrides'] as $field_name => $replacement) { $item = $duplicator->createInstance(__('Override')); $label = Widget::Label(__('Field')); $options = array(array('system:id', false, __('System ID'))); foreach ($section->fields as $f) { $options[] = array(General::sanitize($f->{'element-name'}), $f->{'element-name'} == $field_name, General::sanitize($f->{'publish-label'})); } $label->appendChild(Widget::Select('fields[overrides][field][]', $options)); $item->appendChild($label); $label = Widget::Label(__('Replacement')); $label->appendChild(Widget::Input('fields[overrides][replacement][]', General::sanitize($replacement))); $item->appendChild($label); } } if (is_array($items['defaults'])) { foreach ($items['defaults'] as $field_name => $replacement) { $item = $duplicator->createInstance(__('Default Value')); $label = Widget::Label(__('Field')); $options = array(array('system:id', false, __('System ID'))); foreach ($section->fields as $f) { $options[] = array(General::sanitize($f->{'element-name'}), $f->{'element-name'} == $field_name, General::sanitize($f->{'publish-label'})); } $label->appendChild(Widget::Select('fields[defaults][field][]', $options)); $item->appendChild($label); $label = Widget::Label(__('Replacement')); $label->appendChild(Widget::Input('fields[defaults][replacement][]', General::sanitize($replacement))); $item->appendChild($label); } } $duplicator->appendTo($wrapper); }
private function __form(Section $existing = null) { // Status message: $callback = Administration::instance()->getPageCallback(); if (isset($callback['flag']) && !is_null($callback['flag'])) { switch ($callback['flag']) { case 'saved': $this->alerts()->append(__('Section updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/sections/new/', ADMIN_URL . '/blueprints/sections/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('Section created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/sections/new/', ADMIN_URL . '/blueprints/sections/')), AlertStack::SUCCESS); break; } } if (!$this->alerts()->valid() and $existing instanceof Section) { $this->appendSyncAlert(); } $layout = new Layout(); $left = $layout->createColumn(Layout::SMALL); $right = $layout->createColumn(Layout::LARGE); $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), __('Sections')))); $this->appendSubheading($existing instanceof Section ? $existing->name : __('New Section')); if ($existing instanceof Section) { $this->appendViewOptions(); } // Essentials: $fieldset = $this->createElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild($this->createElement('h3', __('Essentials'))); $label = Widget::Label('Name'); $label->appendChild(Widget::Input('essentials[name]', $this->section->name)); $fieldset->appendChild(isset($this->errors->name) ? Widget::wrapFormElementWithError($label, $this->errors->name) : $label); $label = Widget::Label(__('Navigation Group')); $label->appendChild($this->createElement('em', __('Created if does not exist'))); $label->appendChild(Widget::Input('essentials[navigation-group]', $this->section->{"navigation-group"})); $fieldset->appendChild(isset($this->errors->{'navigation-group'}) ? Widget::wrapFormElementWithError($label, $this->errors->{'navigation-group'}) : $label); $navigation_groups = Section::fetchUsedNavigationGroups(); if (is_array($navigation_groups) && !empty($navigation_groups)) { $ul = $this->createElement('ul', NULL, array('class' => 'tags singular')); foreach ($navigation_groups as $g) { $ul->appendChild($this->createElement('li', $g)); } $fieldset->appendChild($ul); } $input = Widget::Input('essentials[hidden-from-publish-menu]', 'yes', 'checkbox', $this->section->{'hidden-from-publish-menu'} == 'yes' ? array('checked' => 'checked') : array()); $label = Widget::Label(__('Hide this section from the Publish menu')); $label->prependChild($input); $fieldset->appendChild($label); $left->appendChild($fieldset); // Fields $fieldset = $this->createElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild($this->createElement('h3', __('Fields'))); $div = $this->createElement('div'); $h3 = $this->createElement('h3', __('Fields')); $h3->setAttribute('class', 'label'); $div->appendChild($h3); $duplicator = new Duplicator(__('Add Field')); $duplicator->setAttribute('id', 'section-duplicator'); $fields = $this->section->fields; $types = array(); foreach (new FieldIterator() as $pathname) { $type = preg_replace(array('/^field\\./', '/\\.php$/'), NULL, basename($pathname)); $types[$type] = Field::load($pathname); } // To Do: Sort this list based on how many times a field has been used across the system uasort($types, create_function('$a, $b', 'return strnatcasecmp($a->name(), $b->name());')); if (is_array($types)) { foreach ($types as $type => $field) { $defaults = array(); $field->findDefaultSettings($defaults); $field->section = $this->section->handle; foreach ($defaults as $key => $value) { $field->{$key} = $value; } $item = $duplicator->createTemplate($field->name()); $field->displaySettingsPanel($item, new MessageStack()); } } if (is_array($fields)) { foreach ($fields as $position => $field) { $field->sortorder = $position; if ($this->errors->{"field::{$position}"}) { $messages = $this->errors->{"field::{$position}"}; } else { $messages = new MessageStack(); } $item = $duplicator->createInstance($field->name, $field->name()); $field->displaySettingsPanel($item, $messages); } } $duplicator->appendTo($fieldset); $right->appendChild($fieldset); $layout->appendTo($this->Form); $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : 'Create Section', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $div->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this section')))); } $this->Form->appendChild($div); }
protected function appendCondition(Duplicator $duplicator, $condition = array()) { $document = $duplicator->ownerDocument; if (empty($condition)) { $item = $duplicator->createTemplate(__('Don\'t Execute When')); } else { $item = $duplicator->createInstance(__('Don\'t Execute When')); } if (!isset($condition['parameter'])) { $condition['parameter'] = null; } if (!isset($condition['logic'])) { $condition['logic'] = 'empty'; } $group = $document->createElement('div'); $group->setAttribute('class', 'group double'); // Parameter $label = $document->createElement('label', __('Parameter')); $label->appendChild(Widget::input('fields[conditions][parameter][]', $condition['parameter'])); $group->appendChild($label); // Logic $label = $document->createElement('label', __('Logic')); $label->appendChild(Widget::select('fields[conditions][logic][]', array(array('empty', $condition['logic'] == 'empty', __('is empty')), array('set', $condition['logic'] == 'set', __('is set'))), array('class' => 'filtered'))); $group->appendChild($label); $group->appendChild($label); $item->appendChild($group); }
protected function appendNamespace(Duplicator $duplicator, array $namespace = NULL) { $document = $duplicator->ownerDocument; if (is_null($namespace)) { $item = $duplicator->createTemplate(__('Namespace')); } else { $item = $duplicator->createInstance(__('Namespace')); } $group = $document->createElement('div'); $group->setAttribute('class', 'group double'); // Name $label = Widget::Label(__('Name')); $input = Widget::Input('fields[namespaces][name][]', $namespace['name']); if (!is_null($namespace) && isset($namespace['name'])) { $input->setAttribute("value", $namespace['name']); } $label->appendChild($input); $group->appendChild($label); // URI $label = Widget::Label(__('URI')); $input = Widget::Input('fields[namespaces][uri][]'); if (!is_null($namespace) && isset($namespace['uri'])) { $input->setAttribute("value", $namespace['uri']); } $label->appendChild($input); $group->appendChild($label); $item->appendChild($group); }