/** * 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; }