/**
  * Returns a readonly span containing the correct value.
  *
  * @param array $properties
  *
  * @return string
  */
 public function Field($properties = array())
 {
     $source = ArrayLib::flatten($this->getSource());
     $values = $this->getValueArray();
     // Get selected values
     $mapped = array();
     foreach ($values as $value) {
         if (isset($source[$value])) {
             $mapped[] = $source[$value];
         }
     }
     // Don't check if string arguments are matching against the source,
     // as they might be generated HTML diff views instead of the actual values
     if ($this->value && is_string($this->value) && empty($mapped)) {
         $mapped = array(trim($this->value));
         $values = array();
     }
     if ($mapped) {
         $attrValue = implode(', ', array_values($mapped));
         if (!$this->dontEscape) {
             $attrValue = Convert::raw2xml($attrValue);
         }
         $inputValue = implode(', ', array_values($values));
     } else {
         $attrValue = '<i>(' . _t('FormField.NONE', 'none') . ')</i>';
         $inputValue = '';
     }
     $properties = array_merge($properties, array('AttrValue' => $attrValue, 'InputValue' => $inputValue));
     return parent::Field($properties);
 }
    /**
     * Setup the fields that are visible ONLY when the item exists already.
     * @param News $owner
     * @param SiteConfig $siteConfig
     */
    private function existingItem(News $owner, SiteConfig $siteConfig)
    {
        if (!$owner->ID) {
            $member = Member::currentUser();
            $this->field_list['Root.Main'][13] = ReadonlyField::create('Tags', $owner->fieldLabel('Tags'), _t('News.TAGAFTERID', 'Tags can be added after the item has been saved'));
            $owner->Type = 'news';
            $owner->Author = $member->FirstName . ' ' . $member->Surname;
        } else {
            if (class_exists('MultiSelectField')) {
                /** I like multiselectfield and needed a reason to commit something */
                $this->field_list['Root.Main'][13] = MultiSelectField::create('Tags', $owner->fieldLabel('Tags'), $this->owner);
            } else {
                $this->field_list['Root.Main'][13] = CheckboxSetField::create('Tags', $owner->fieldLabel('Tags'), Tag::get()->map('ID', 'Title'));
            }
            $this->field_list['Root.Main'][2] = LiteralField::create('Dummy', '<div id="Dummy" class="field readonly">
	<label class="left" for="Form_ItemEditForm_Dummy">Link</label>
	<div class="middleColumn">
	<span id="Form_ItemEditForm_Dummy" class="readonly">
		<a href="' . $owner->AbsoluteLink() . '" target="_blank">' . $owner->AbsoluteLink() . '</a>
	</span>
	</div>
	</div>');
            if ($siteConfig->EnableSlideshow) {
                /** @var GridFieldConfig_RecordEditor $gridFieldConfig */
                $gridFieldConfig = GridFieldConfig_RecordEditor::create();
                $gridFieldConfig->addComponent(new GridFieldBulkUpload());
                $gridFieldConfig->addComponent(new GridFieldOrderableRows('SortOrder'));
                $gridFieldConfig->getComponentByType('GridFieldBulkUpload')->setUfSetup('setFolderName', $this->getRootFolderName($siteConfig));
                if (class_exists('GridFieldGalleryTheme')) {
                    $gridFieldConfig->addComponent(new GridFieldGalleryTheme('Image'));
                    /**
                     * as gallery theme breaks sorting with GridFieldOrderableRows
                     * let's use SortableRows as a fallback when installed
                     *
                     * @todo remove later this when gridfield extension works with gallery theme
                     */
                    if (class_exists('GridFieldSortableRows')) {
                        $gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
                        $gridFieldConfig->removeComponentsByType('GridFieldOrderableRows');
                    }
                }
                $this->field_list['Root'][] = Tab::create('SlideshowImages', $owner->fieldLabel('SlideshowImages'), GridField::create('SlideshowImage', _t('News.IMAGES', 'Slideshow images'), $owner->SlideshowImages()->sort('SortOrder'), $gridFieldConfig));
            }
        }
    }
 public function getAttributes()
 {
     return array_merge(parent::getAttributes(), array('multiple' => 'true', 'size' => $this->getSize(), 'name' => $this->getName() . '[]'));
 }
 /**
  * Test functionality with unwritten items
  * @return void
  */
 public function testWithUnsavedRelationList()
 {
     $department = new MultiSelectFieldTest_Department();
     $field = MultiSelectField::create('StaffMembers', '', $department);
     $staff = $this->objFromFixture('MultiSelectFieldTest_StaffMember', 'staffmember2');
     $field->setValue(array($staff->ID));
     $field->saveInto($department);
     $department->write();
     $staffMembers = $department->StaffMembers()->map('ID', 'Name')->toArray();
     $this->assertArrayHasKey($staff->ID, $staffMembers);
     $this->assertEquals('Phil McCreviss', $staffMembers[$staff->ID]);
 }