/**
  *	Display the appropriate CMS media page fields and respective media type attributes.
  */
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     // Display the media type as read only.
     $fields->addFieldToTab('Root.Main', ReadonlyField::create('Type', 'Type', $this->MediaType()->Title), 'Title');
     // Display a notification that the parent holder contains mixed children.
     $parent = $this->getParent();
     if ($parent && $parent->getMediaHolderChildren()->exists()) {
         Requirements::css(MEDIAWESOME_PATH . '/css/mediawesome.css');
         $fields->addFieldToTab('Root.Main', LiteralField::create('MediaNotification', "<p class='mediawesome notification'><strong>Mixed {$this->MediaType()->Title} Holder</strong></p>"), 'Type');
     }
     // Display the remaining media page fields.
     $fields->addFieldToTab('Root.Main', TextField::create('ExternalLink')->setRightTitle('An <strong>optional</strong> redirect URL to the media source'), 'URLSegment');
     $fields->addFieldToTab('Root.Main', $date = DatetimeField::create('Date'), 'Content');
     $date->getDateField()->setConfig('showcalendar', true);
     // Allow customisation of categories and tags respective to the current page.
     $tags = MediaTag::get()->map()->toArray();
     $fields->findOrMakeTab('Root.CategoriesTags', 'Categories and Tags');
     $fields->addFieldToTab('Root.CategoriesTags', $categoriesList = ListboxField::create('Categories', 'Categories', $tags)->setMultiple(true));
     $fields->addFieldToTab('Root.CategoriesTags', $tagsList = ListboxField::create('Tags', 'Tags', $tags)->setMultiple(true));
     if (!$tags) {
         $categoriesList->setAttribute('disabled', 'true');
         $tagsList->setAttribute('disabled', 'true');
     }
     // Allow customisation of media type attribute content respective to the current page.
     if ($this->MediaAttributes()->exists()) {
         foreach ($this->MediaAttributes() as $attribute) {
             if (strripos($attribute->Title, 'Time') || strripos($attribute->Title, 'Date') || stripos($attribute->Title, 'When')) {
                 // Display an attribute as a date time field where appropriate.
                 $fields->addFieldToTab('Root.Main', $custom = DatetimeField::create("{$attribute->ID}_MediaAttribute", $attribute->Title, $attribute->Content), 'Content');
                 $custom->getDateField()->setConfig('showcalendar', true);
             } else {
                 $fields->addFieldToTab('Root.Main', $custom = TextField::create("{$attribute->ID}_MediaAttribute", $attribute->Title, $attribute->Content), 'Content');
             }
             $custom->setRightTitle('Custom <strong>' . strtolower($this->MediaType()->Title) . '</strong> attribute');
         }
     }
     // Display an abstract field for content summarisation.
     $fields->addfieldToTab('Root.Main', $abstract = TextareaField::create('Abstract'), 'Content');
     $abstract->setRightTitle('A concise summary of the content');
     $abstract->setRows(6);
     // Allow customisation of images and attachments.
     $type = strtolower($this->MediaType()->Title);
     $fields->findOrMakeTab('Root.ImagesAttachments', 'Images and Attachments');
     $fields->addFieldToTab('Root.ImagesAttachments', $images = UploadField::create('Images'));
     $images->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif', 'bmp'));
     $images->setFolderName("media-{$type}/{$this->ID}/images");
     $fields->addFieldToTab('Root.ImagesAttachments', $attachments = UploadField::create('Attachments'));
     $attachments->setFolderName("media-{$type}/{$this->ID}/attachments");
     // Allow extension customisation.
     $this->extend('updateMediaPageCMSFields', $fields);
     return $fields;
 }
Ejemplo n.º 2
0
 /**
  *	Confirm that the current tag is valid.
  */
 public function validate()
 {
     $result = parent::validate();
     // Confirm that the current tag has been given a title and doesn't already exist.
     $this->Title = strtolower($this->Title);
     if ($result->valid() && !$this->Title) {
         $result->error('"Title" required!');
     } else {
         if ($result->valid() && MediaTag::get_one('MediaTag', array('ID != ?' => $this->ID, 'Title = ?' => $this->Title))) {
             $result->error('Tag already exists!');
         }
     }
     // Allow extension customisation.
     $this->extend('validateMediaTag', $result);
     return $result;
 }
 /**
  *	Allow selection and customisation of CMS media types/tags.
  */
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     // Display the media type as read only if media page children exist.
     $this->AllChildren()->where("ClassName != 'MediaHolder'")->exists() && $this->MediaType()->exists() ? $fields->addFieldToTab('Root.Main', ReadonlyField::create('Media', 'Media Type', $this->MediaType()->Title), 'Title') : $fields->addFieldToTab('Root.Main', DropdownField::create('MediaTypeID', 'Media Type', array_merge(array(0 => ''), MediaType::get()->map()->toArray())), 'Title');
     // Allow customisation of the media URL format.
     $formats = array('Y/m/d/' => 'year/month/day/media', 'Y/m/' => 'year/month/media', 'Y/' => 'year/media', '-' => 'media');
     $fields->insertBefore(DropdownField::create('URLFormatting', 'URL Formatting', $formats)->setRightTitle('The <strong>media</strong> URL format'), 'Content');
     // Allow customisation of media types, depending on the current CMS user permissions.
     $fields->findOrMakeTab('Root.ManageMedia.TypesAttributes', 'Types and Attributes');
     $fields->findOrMakeTab('Root.ManageMedia')->setTitle('Manage ALL Media');
     $fields->addFieldToTab('Root.ManageMedia.TypesAttributes', GridField::create('TypesAttributes', 'Types and Attributes', MediaType::get(), GridFieldConfig_RecordEditor::create()->removeComponentsByType('GridFieldDeleteAction'))->setModelClass('MediaType'));
     // Allow customisation of media categories and tags.
     $fields->findOrMakeTab('Root.ManageMedia.CategoriesTags', 'Categories and Tags');
     $fields->addFieldToTab('Root.ManageMedia.CategoriesTags', GridField::create('CategoriesTags', 'Categories and Tags', MediaTag::get(), GridFieldConfig_RecordEditor::create()->removeComponentsByType('GridFieldDeleteAction'))->setModelClass('MediaTag'));
     // Allow extension customisation.
     $this->extend('updateMediaHolderCMSFields', $fields);
     return $fields;
 }