/**
  * @param FieldSet $actions
  * @parma SiteTree $page
  */
 public static function update_cms_actions(&$actions, $page)
 {
     $openRequest = $page->OpenWorkflowRequest();
     // if user doesn't have publish rights
     if (!$page->canPublish() || $openRequest) {
         // authors shouldn't be able to revert, as this republishes the page.
         // they should rather change the page and re-request publication
         $actions->removeByName('action_revert');
     }
     // Remove the one click publish if they are not an admin/workflow admin.
     if (self::$force_publishers_to_use_workflow && !Permission::checkMember(Member::currentUser(), 'IS_WORKFLOW_ADMIN')) {
         $actions->removeByName('action_publish');
     }
     // Remove the save & publish button if you don't have edit rights
     if (!$page->canEdit()) {
         $actions->removeByName('action_publish');
     }
     $liveVersion = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree_Live\".\"ID\" = {$page->ID}");
     if ($liveVersion && $liveVersion->ExpiryDate != null && $liveVersion->ExpiryDate != '0000-00-00 00:00:00') {
         if ($page->canApprove()) {
             $actions->push(new FormAction('cms_cancelexpiry', _t('WorkflowPublicationRequest.BUTTONCANCELEXPIRY', 'Cancel expiry')));
         }
     }
     // Optional method
     $isPublishable = $page->hasMethod('isPublishable') ? $page->isPublishable() : true;
     if (!$openRequest && $page->canEdit() && $isPublishable && $page->stagesDiffer('Stage', 'Live') && ($page->Version > 1 || $page->Title != "New Page") && !$page->IsDeletedFromStage && (!$page->canPublish() || self::$publisher_can_create_wf_requests)) {
         $actions->push($requestPublicationAction = new FormAction('cms_requestpublication', _t('SiteTreeCMSWorkflow.BUTTONREQUESTPUBLICATION', 'Request Publication')));
         // don't allow creation of a second request by another author
         if (!self::can_create(null, $page)) {
             $actions->makeFieldReadonly($requestPublicationAction->Name());
         }
     }
 }
 function getCMSFields()
 {
     $fields = new FieldSet(new TextField('SearchPhrase', 'Search For'), new TextField('SearchTitle', 'Title'), new TextField('SearchSubject', 'Subject'));
     $fields->merge(parent::getCMSFields());
     $fields->removeByName('TwitterUser');
     return $fields;
 }
 function updateCMSFields(FieldSet &$fields)
 {
     if ($this->owner->ID && $this->owner->Code == strtolower(self::$main_group)) {
         $newMerchants = new ComplexTableField(Controller::has_curr() ? Controller::curr() : new Controller(), 'NewMembers', 'Member');
         $newMerchants->setCustomSourceItems(self::get_new_merchants());
         $fields->addFieldToTab('Root', new Tab(_t('MerchantGroupDOD.NEWMERCHANTS', 'New Merchants'), $newMerchants), 'Members');
         $fields->findOrMakeTab('Root.Members')->setTitle(_t('MerchantGroupDOD.ALLMERCHANTS', 'All Merchants'));
         $fields->removeByName('Title');
     }
 }
 /**
  * Fields to display this {@link Payment} in the CMS, removed some of the 
  * unnecessary fields.
  * 
  * @see DataObjectDecorator::updateCMSFields()
  * @return FieldSet
  */
 function updateCMSFields(FieldSet &$fields)
 {
     $toBeRemoved = array('IP', 'ProxyIP', 'PaidForID', 'PaidForClass', 'PaymentDate', 'ExceptionError', 'Token', 'PayerID', 'RecurringPaymentID');
     foreach ($toBeRemoved as $field) {
         $fields->removeByName($field);
     }
     $toBeReadOnly = array('TransactionID', 'PaidByID');
     foreach ($toBeReadOnly as $field) {
         if ($fields->fieldByName($field)) {
             $fields->makeFieldReadonly($field);
         }
     }
     return $fields;
 }
 /**
  * @param FieldSet $actions
  * @parma SiteTree $page
  */
 public static function update_cms_actions(&$actions, $page)
 {
     $openRequest = $page->OpenWorkflowRequest();
     // if user doesn't have publish rights, exchange the behavior from
     // "publish" to "request publish" etc.
     if (!$page->canDeleteFromLive() || $openRequest) {
         // "request removal"
         $actions->removeByName('action_deletefromlive');
     }
     if (!$openRequest && $page->canEdit() && (!$page->canPublish() || self::$publisher_can_create_wf_requests) && $page->IsDeletedFromStage) {
         if ($page->ExistsOnLive) {
             $actions->push($requestDeletionAction = new FormAction('cms_requestdeletefromlive', _t('SiteTreeCMSWorkflow.BUTTONREQUESTREMOVAL', 'Request Removal')));
         }
         // don't allow creation of a second request by another author
         if (!self::can_create(null, $page)) {
             $actions->makeFieldReadonly($requestDeletionAction->Name());
         }
     }
     // @todo deny deletion
 }
Ejemplo n.º 6
0
 /**
  * Returns a FieldSet with which to create the CMS editing form.
  *
  * You can override this in your child classes to add extra fields - first
  * get the parent fields using parent::getCMSFields(), then use
  * addFieldToTab() on the FieldSet.
  *
  * @return FieldSet The fields to be displayed in the CMS.
  */
 function getCMSFields()
 {
     require_once "forms/Form.php";
     Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js");
     Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
     Requirements::javascript(CMS_DIR . "/javascript/SitetreeAccess.js");
     Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
     Requirements::javascript(SAPPHIRE_DIR . '/javascript/UpdateURL.js');
     // Status / message
     // Create a status message for multiple parents
     if ($this->ID && is_numeric($this->ID)) {
         $linkedPages = $this->VirtualPages();
     }
     $parentPageLinks = array();
     if (isset($linkedPages)) {
         foreach ($linkedPages as $linkedPage) {
             $parentPage = $linkedPage->Parent;
             if ($parentPage) {
                 if ($parentPage->ID) {
                     $parentPageLinks[] = "<a class=\"cmsEditlink\" href=\"admin/show/{$linkedPage->ID}\">{$parentPage->Title}</a>";
                 } else {
                     $parentPageLinks[] = "<a class=\"cmsEditlink\" href=\"admin/show/{$linkedPage->ID}\">" . _t('SiteTree.TOPLEVEL', 'Site Content (Top Level)') . "</a>";
                 }
             }
         }
         $lastParent = array_pop($parentPageLinks);
         $parentList = "'{$lastParent}'";
         if (count($parentPageLinks) > 0) {
             $parentList = "'" . implode("', '", $parentPageLinks) . "' and " . $parentList;
         }
         $statusMessage[] = sprintf(_t('SiteTree.APPEARSVIRTUALPAGES', "This content also appears on the virtual pages in the %s sections."), $parentList);
     }
     if ($this->HasBrokenLink || $this->HasBrokenFile) {
         $statusMessage[] = _t('SiteTree.HASBROKENLINKS', "This page has broken links.");
     }
     $message = "STATUS: {$this->Status}<br />";
     if (isset($statusMessage)) {
         $message .= "NOTE: " . implode("<br />", $statusMessage);
     }
     $dependentNote = '';
     $dependentTable = new LiteralField('DependentNote', '<p></p>');
     // Create a table for showing pages linked to this one
     $dependentPagesCount = $this->DependentPagesCount();
     if ($dependentPagesCount) {
         $dependentColumns = array('Title' => $this->fieldLabel('Title'), 'AbsoluteLink' => _t('SiteTree.DependtPageColumnURL', 'URL'), 'DependentLinkType' => _t('SiteTree.DependtPageColumnLinkType', 'Link type'));
         if (class_exists('Subsite')) {
             $dependentColumns['Subsite.Title'] = singleton('Subsite')->i18n_singular_name();
         }
         $dependentNote = new LiteralField('DependentNote', '<p>' . _t('SiteTree.DEPENDENT_NOTE', 'The following pages depend on this page. This includes virtual pages, redirector pages, and pages with content links.') . '</p>');
         $dependentTable = new TableListField('DependentPages', 'SiteTree', $dependentColumns);
         $dependentTable->setCustomSourceItems($this->DependentPages());
         $dependentTable->setFieldFormatting(array('Title' => '<a href=\\"admin/show/$ID\\">$Title</a>', 'AbsoluteLink' => '<a href=\\"$value\\">$value</a>'));
         $dependentTable->setPermissions(array('show', 'export'));
     }
     // Lay out the fields
     $fields = new FieldSet($rootTab = new TabSet("Root", $tabContent = new TabSet('Content', $tabMain = new Tab('Main', new TextField("Title", $this->fieldLabel('Title')), new TextField("MenuTitle", $this->fieldLabel('MenuTitle')), new HtmlEditorField("Content", _t('SiteTree.HTMLEDITORTITLE', "Content", PR_MEDIUM, 'HTML editor title'))), $tabMeta = new Tab('Metadata', new FieldGroup(_t('SiteTree.URL', "URL"), new LabelField('BaseUrlLabel', Controller::join_links(Director::absoluteBaseURL(), self::nested_urls() && $this->ParentID ? $this->Parent()->RelativeLink(true) : null)), new UniqueRestrictedTextField("URLSegment", "URLSegment", "SiteTree", _t('SiteTree.VALIDATIONURLSEGMENT1', "Another page is using that URL. URL must be unique for each page"), "[^A-Za-z0-9-]+", "-", _t('SiteTree.VALIDATIONURLSEGMENT2', "URLs can only be made up of letters, digits and hyphens."), "", "", "", 50), new LabelField('TrailingSlashLabel', "/")), new LiteralField('LinkChangeNote', self::nested_urls() && count($this->Children()) ? '<p>' . $this->fieldLabel('LinkChangeNote') . '</p>' : null), new HeaderField('MetaTagsHeader', $this->fieldLabel('MetaTagsHeader')), new TextField("MetaTitle", $this->fieldLabel('MetaTitle')), new TextareaField("MetaKeywords", $this->fieldLabel('MetaKeywords'), 1), new TextareaField("MetaDescription", $this->fieldLabel('MetaDescription')), new TextareaField("ExtraMeta", $this->fieldLabel('ExtraMeta')))), $tabBehaviour = new Tab('Behaviour', new DropdownField("ClassName", $this->fieldLabel('ClassName'), $this->getClassDropdown()), new OptionsetField("ParentType", _t("SiteTree.PAGELOCATION", "Page location"), array("root" => _t("SiteTree.PARENTTYPE_ROOT", "Top-level page"), "subpage" => _t("SiteTree.PARENTTYPE_SUBPAGE", "Sub-page underneath a parent page (choose below)"))), $parentIDField = new TreeDropdownField("ParentID", $this->fieldLabel('ParentID'), 'SiteTree'), new CheckboxField("ShowInMenus", $this->fieldLabel('ShowInMenus')), new CheckboxField("ShowInSearch", $this->fieldLabel('ShowInSearch')), new CheckboxField("ProvideComments", $this->fieldLabel('ProvideComments')), new LiteralField("HomepageForDomainInfo", "<p>" . _t('SiteTree.NOTEUSEASHOMEPAGE', "Use this page as the 'home page' for the following domains: \n\t\t\t\t\t\t\t(separate multiple domains with commas)") . "</p>"), new TextField("HomepageForDomain", _t('SiteTree.HOMEPAGEFORDOMAIN', "Domain(s)", PR_MEDIUM, 'Listing domains that should be used as homepage'))), $tabToDo = new Tab(_t('SiteTree.TABTODO', 'To-do') . ($this->ToDo ? '**' : ''), new LiteralField("ToDoHelp", _t('SiteTree.TODOHELP', "<p>You can use this to keep track of work that needs to be done to the content of your site.  To see all your pages with to do information, open the 'Site Reports' window on the left and select 'To Do'</p>")), new TextareaField("ToDo", "", 10)), $tabDependent = new Tab('Dependent', $dependentNote, $dependentTable), $tabAccess = new Tab('Access', new HeaderField('WhoCanViewHeader', _t('SiteTree.ACCESSHEADER', "Who can view this page?"), 2), $viewersOptionsField = new OptionsetField("CanViewType", ""), $viewerGroupsField = new TreeMultiselectField("ViewerGroups", $this->fieldLabel('ViewerGroups')), new HeaderField('WhoCanEditHeader', _t('SiteTree.EDITHEADER', "Who can edit this page?"), 2), $editorsOptionsField = new OptionsetField("CanEditType", ""), $editorGroupsField = new TreeMultiselectField("EditorGroups", $this->fieldLabel('EditorGroups')))));
     /*
      * This filter ensures that the ParentID dropdown selection does not show this node,
      * or its descendents, as this causes vanishing bugs.
      */
     $parentIDField->setFilterFunction(create_function('$node', "return \$node->ID != {$this->ID};"));
     // Conditional dependent pages tab
     if ($dependentPagesCount) {
         $tabDependent->setTitle(_t('SiteTree.TABDEPENDENT', "Dependent pages") . " ({$dependentPagesCount})");
     } else {
         $fields->removeFieldFromTab('Root', 'Dependent');
     }
     // Make page location fields read-only if the user doesn't have the appropriate permission
     if (!Permission::check("SITETREE_REORGANISE")) {
         $fields->makeFieldReadonly('ParentType');
         if ($this->ParentType == 'root') {
             $fields->removeByName('ParentID');
         } else {
             $fields->makeFieldReadonly('ParentID');
         }
     }
     $viewersOptionsSource = array();
     $viewersOptionsSource["Inherit"] = _t('SiteTree.INHERIT', "Inherit from parent page");
     $viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone");
     $viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users");
     $viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)");
     $viewersOptionsField->setSource($viewersOptionsSource);
     $editorsOptionsSource = array();
     $editorsOptionsSource["Inherit"] = _t('SiteTree.INHERIT', "Inherit from parent page");
     $editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS");
     $editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)");
     $editorsOptionsField->setSource($editorsOptionsSource);
     if (!Permission::check('SITETREE_GRANT_ACCESS')) {
         $fields->makeFieldReadonly($viewersOptionsField);
         if ($this->CanViewType == 'OnlyTheseUsers') {
             $fields->makeFieldReadonly($viewerGroupsField);
         } else {
             $fields->removeByName('ViewerGroups');
         }
         $fields->makeFieldReadonly($editorsOptionsField);
         if ($this->CanEditType == 'OnlyTheseUsers') {
             $fields->makeFieldReadonly($editorGroupsField);
         } else {
             $fields->removeByName('EditorGroups');
         }
     }
     $tabContent->setTitle(_t('SiteTree.TABCONTENT', "Content"));
     $tabMain->setTitle(_t('SiteTree.TABMAIN', "Main"));
     $tabMeta->setTitle(_t('SiteTree.TABMETA', "Metadata"));
     $tabBehaviour->setTitle(_t('SiteTree.TABBEHAVIOUR', "Behavior"));
     $tabAccess->setTitle(_t('SiteTree.TABACCESS', "Access"));
     if (file_exists(BASE_PATH . '/install.php')) {
         $fields->addFieldToTab("Root.Content.Main", new LiteralField("InstallWarningHeader", "<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING", "Warning: You should remove install.php from this SilverStripe install for security reasons.") . "</p>"), "Title");
     }
     if (self::$runCMSFieldsExtensions) {
         $this->extend('updateCMSFields', $fields);
     }
     return $fields;
 }
 /**
  * @param FieldSet $fieldset
  * @return false
  */
 function updateFieldSet(&$fieldset)
 {
     // Remove, in case it was added beforehand
     $fieldset->removeByName($this->getName());
     return false;
 }
Ejemplo n.º 8
0
 function updateCMSFields(FieldSet &$fields)
 {
     $allForums = DataObject::get('Forum');
     $fields->removeByName('ModeratedForums');
     $fields->addFieldToTab('Root.ModeratedForums', new CheckboxSetField('ModeratedForums', _t('ForumRole.MODERATEDFORUMS', 'Moderated forums'), $allForums ? $allForums->map('ID', 'Title') : array()));
     if (Permission::checkMember($this->owner->ID, "ACCESS_FORUM")) {
         $fields->addFieldToTab('Root.Forum', new ImageField("Avatar", _t('ForumRole.UPLOADAVATAR', "Upload avatar")));
         $fields->addFieldToTab('Root.Forum', new DropdownField("ForumRank", _t('ForumRole.FORUMRANK', "User rating"), array("Community Member" => _t('ForumRole.COMMEMBER'), "Administrator" => _t('ForumRole.ADMIN', 'Administrator'), "Moderator" => _t('ForumRole.MOD', 'Moderator'))));
     }
 }
Ejemplo n.º 9
0
 /**
  * Returns fields related to configuration aspects on this record, e.g. access control.
  * See {@link getCMSFields()} for content-related fields.
  * 
  * @return FieldSet
  */
 function getSettingsFields()
 {
     $fields = new FieldSet($rootTab = new TabSet("Root", $tabBehaviour = new Tab('Settings', new DropdownField("ClassName", $this->fieldLabel('ClassName'), $this->getClassDropdown()), new OptionsetField("ParentType", _t("SiteTree.PAGELOCATION", "Page location"), array("root" => _t("SiteTree.PARENTTYPE_ROOT", "Top-level page"), "subpage" => _t("SiteTree.PARENTTYPE_SUBPAGE", "Sub-page underneath a parent page (choose below)"))), $parentIDField = new TreeDropdownField("ParentID", $this->fieldLabel('ParentID'), 'SiteTree', 'ID', 'MenuTitle'), new CheckboxField("ShowInMenus", $this->fieldLabel('ShowInMenus')), new CheckboxField("ShowInSearch", $this->fieldLabel('ShowInSearch')), new LiteralField("HomepageForDomainInfo", "<p>" . _t('SiteTree.NOTEUSEASHOMEPAGE', "Use this page as the 'home page' for the following domains: \n\t\t\t\t\t\t\t(separate multiple domains with commas)") . "</p>"), new TextField("HomepageForDomain", _t('SiteTree.HOMEPAGEFORDOMAIN', "Domain(s)", PR_MEDIUM, 'Listing domains that should be used as homepage'))), $tabAccess = new Tab('Access', $viewersOptionsField = new OptionsetField("CanViewType", _t('SiteTree.ACCESSHEADER', "Who can view this page?")), $viewerGroupsField = new TreeMultiselectField("ViewerGroups", $this->fieldLabel('ViewerGroups')), $editorsOptionsField = new OptionsetField("CanEditType", _t('SiteTree.EDITHEADER', "Who can edit this page?")), $editorGroupsField = new TreeMultiselectField("EditorGroups", $this->fieldLabel('EditorGroups')))));
     /*
      * This filter ensures that the ParentID dropdown selection does not show this node,
      * or its descendents, as this causes vanishing bugs.
      */
     $parentIDField->setFilterFunction(create_function('$node', "return \$node->ID != {$this->ID};"));
     $tabBehaviour->setTitle(_t('SiteTree.TABBEHAVIOUR', "Behavior"));
     $tabAccess->setTitle(_t('SiteTree.TABACCESS', "Access"));
     // Make page location fields read-only if the user doesn't have the appropriate permission
     if (!Permission::check("SITETREE_REORGANISE")) {
         $fields->makeFieldReadonly('ParentType');
         if ($this->ParentType == 'root') {
             $fields->removeByName('ParentID');
         } else {
             $fields->makeFieldReadonly('ParentID');
         }
     }
     $viewersOptionsSource = array();
     $viewersOptionsSource["Inherit"] = _t('SiteTree.INHERIT', "Inherit from parent page");
     $viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone");
     $viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users");
     $viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)");
     $viewersOptionsField->setSource($viewersOptionsSource);
     $editorsOptionsSource = array();
     $editorsOptionsSource["Inherit"] = _t('SiteTree.INHERIT', "Inherit from parent page");
     $editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS");
     $editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)");
     $editorsOptionsField->setSource($editorsOptionsSource);
     if (!Permission::check('SITETREE_GRANT_ACCESS')) {
         $fields->makeFieldReadonly($viewersOptionsField);
         if ($this->CanViewType == 'OnlyTheseUsers') {
             $fields->makeFieldReadonly($viewerGroupsField);
         } else {
             $fields->removeByName('ViewerGroups');
         }
         $fields->makeFieldReadonly($editorsOptionsField);
         if ($this->CanEditType == 'OnlyTheseUsers') {
             $fields->makeFieldReadonly($editorGroupsField);
         } else {
             $fields->removeByName('EditorGroups');
         }
     }
     if (self::$runCMSFieldsExtensions) {
         $this->extend('updateSettingsFields', $fields);
     }
     return $fields;
 }
 public function updateCMSFields(FieldSet $fields)
 {
     $fields->removeByName('Hash');
     $fields->replaceField('ViewedMembers', $members = new TableListField('ViewedMembers', 'Member', array('Name' => 'Name', 'Email' => 'Email'), '"Newsletter_TrackedLinkID" = ' . $this->owner->ID, null, 'LEFT JOIN "Newsletter_TrackedLink_ViewedMembers" ON "MemberID" = "Member"."ID"'));
     $members->setPermissions(array('show'));
 }
 public function removeFilterField($name)
 {
     parent::removeByName($name);
 }
Ejemplo n.º 12
0
 /**
  * Removes an existing formfield instance by its name.
  *
  * @param string $fieldName
  */
 public function removeFieldByName($fieldName)
 {
     $this->fields->removeByName($fieldName);
 }
 function updateCMSFields(FieldSet &$fields)
 {
     $fields->removeByName('GUID');
 }
 /**
  * Update the CMS fields specifically for Member
  * decorated by this NewsletterRole decorator.
  * 
  * @param FieldSet $fields CMS fields to update
  */
 function updateCMSFields($fields)
 {
     $fields->removeByName('UnsubscribedRecords');
     $fields->removeByName('BlacklistedEmail');
 }
	/**
	 * Remove scaffolded fields for pseudo has_many/has_one
	 * relations added by Janitor from the given FieldSet.
	 * 
	 * @param FieldSet $fields
	 */
	private function removePseudoRelationsFromFieldSet(FieldSet& $fields) {
		$dataFields = $fields->dataFields();
		if ($dataFields) foreach ($dataFields as $field) {
			if (preg_match('/^__/', $field->Name()))
				$fields->removeByName($field->Name());
		}
	}
Ejemplo n.º 16
0
 function DetailForm()
 {
     $ID = isset($_REQUEST['ctf']['ID']) ? Convert::raw2xml($_REQUEST['ctf']['ID']) : null;
     $childID = isset($_REQUEST['ctf']['childID']) ? Convert::raw2xml($_REQUEST['ctf']['childID']) : null;
     $childClass = isset($_REQUEST['fieldName']) ? Convert::raw2xml($_REQUEST['fieldName']) : null;
     $methodName = isset($_REQUEST['methodName']) ? $_REQUEST['methodName'] : null;
     if (!$childID) {
         user_error("AssetTableField::DetailForm Please specify a valid ID");
         return null;
     }
     if ($childID) {
         $childData = DataObject::get_by_id("File", $childID);
     }
     if (!$childData) {
         user_error("AssetTableField::DetailForm No record found");
         return null;
     }
     if ($childData->ParentID) {
         $folder = DataObject::get_by_id('File', $childData->ParentID);
     } else {
         $folder = singleton('Folder');
     }
     $urlLink = "<div class='field readonly'>";
     $urlLink .= "<label class='left'>" . _t('AssetTableField.URL', 'URL') . "</label>";
     $urlLink .= "<span class='readonly'><a href='{$childData->Link()}'>{$childData->RelativeLink()}</a></span>";
     $urlLink .= "</div>";
     $detailFormFields = new FieldSet(new TabSet("BottomRoot", new Tab(_t('AssetTableField.MAIN', 'Main'), new TextField("Title", _t('AssetTableField.TITLE', 'Title')), new TextField("Name", _t('AssetTableField.FILENAME', 'Filename')), new LiteralField("AbsoluteURL", $urlLink), new ReadonlyField("FileType", _t('AssetTableField.TYPE', 'Type')), new ReadonlyField("Size", _t('AssetTableField.SIZE', 'Size'), $childData->getSize()), new DropdownField("OwnerID", _t('AssetTableField.OWNER', 'Owner'), Member::mapInCMSGroups($folder->CanEdit())), new DateField_Disabled("Created", _t('AssetTableField.CREATED', 'First uploaded')), new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT', 'Last changed')))));
     if (is_a($childData, 'Image')) {
         $big = $childData->URL;
         $thumbnail = $childData->getFormattedImage('AssetLibraryPreview')->URL;
         // Hmm this required the translated string to be appended to BottomRoot to add this to the Main tab
         $detailFormFields->addFieldToTab("BottomRoot." . _t('AssetTableField.MAIN', 'Main'), new ReadonlyField("Dimensions", _t('AssetTableField.DIM', 'Dimensions')), "Created");
         $detailFormFields->addFieldToTab("BottomRoot", new Tab(_t('AssetTableField.IMAGE', 'Image'), new LiteralField("ImageFull", '<a id="ImageEditorActivator" href="javascript: void(0)">' . "<img id='thumbnailImage' src='{$thumbnail}?r=" . rand(1, 100000) . "' alt='{$childData->Name}' /><p>" . _t('AssetTableField.EDITIMAGE', 'Edit this image') . "</p>" . '</a>' . '<script type="text/javascript" src="cms/javascript/ImageEditor/Activator.js"></script><script type="text/javascript">var imageActivator = new ImageEditor.Activator.initialize();Event.observe("ImageEditorActivator","click",imageActivator.onOpen);</script>')), 'Main');
         if (class_exists('GalleryFile')) {
             $detailFormFields->addFieldToTab("BottomRoot", new Tab(_t('AssetTableField.GALLERYOPTIONS', 'Gallery Options'), new TextField("Content", _t('AssetTableField.CAPTION', 'Caption'))));
         }
     } else {
         if (class_exists('GalleryFile')) {
             if ($childData->Extension == 'swf') {
                 $detailFormFields->addFieldToTab("BottomRoot", new Tab(_t('AssetTableField.GALLERYOPTIONS', 'Gallery Options'), new TextField("Content", _t('AssetTableField.CAPTION', 'Caption')), new TextField('PopupWidth', _t('AssetTableField.POPUPWIDTH', 'Popup Width')), new TextField('PopupHeight', _t('AssetTableField.POPUPHEIGHT', 'Popup Height')), new HeaderField(_t('AssetTableField.SWFFILEOPTIONS', 'SWF File Options')), new CheckboxField('Embed', _t('AssetTableField.ISFLASH', 'Is A Flash Document')), new CheckboxField('LimitDimensions', _t('AssetTableField.DIMLIMT', 'Limit The Dimensions In The Popup Window'))));
             } else {
                 $detailFormFields->addFieldToTab("BottomRoot", new Tab(_t('AssetTableField.GALLERYOPTIONS', 'Gallery Options'), new TextField("Content", _t('AssetTableField.CAPTION', 'Caption')), new TextField('PopupWidth', _t('AssetTableField.POPUPWIDTH', 'Popup Width')), new TextField('PopupHeight', _t('AssetTableField.POPUPHEIGHT', 'Popup Height'))));
             }
         }
     }
     if ($childData && $childData->hasMethod('BackLinkTracking')) {
         $links = $childData->BackLinkTracking();
         if ($links->exists()) {
             foreach ($links as $link) {
                 $backlinks[] = "<li><a href=\"admin/show/{$link->ID}\">" . $link->Breadcrumbs(null, true) . "</a></li>";
             }
             $backlinks = "<div style=\"clear:left\">" . _t('AssetTableField.PAGESLINKING', 'The following pages link to this file:') . "<ul>" . implode("", $backlinks) . "</ul>";
         }
         if (!isset($backlinks)) {
             $backlinks = "<p>" . _t('AssetTableField.NOLINKS', "This file hasn't been linked to from any pages.") . "</p>";
         }
         $detailFormFields->addFieldToTab("BottomRoot.Links", new LiteralField("Backlinks", $backlinks));
     }
     // the ID field confuses the Controller-logic in finding the right view for ReferencedField
     $detailFormFields->removeByName('ID');
     if ($childData) {
         $childData->extend('updateCMSFields', $detailFormFields);
     }
     // add a namespaced ID instead thats "converted" by saveComplexTableField()
     $detailFormFields->push(new HiddenField("ctf[childID]", "", $childID));
     $detailFormFields->push(new HiddenField("ctf[ClassName]", "", $this->sourceClass));
     $readonly = $this->methodName == "show";
     $form = new ComplexTableField_Popup($this, "DetailForm", $detailFormFields, $this->sourceClass, $readonly);
     if (is_numeric($childID)) {
         if ($methodName == "show" || $methodName == "edit") {
             $form->loadDataFrom($childData);
         }
     }
     if (!$folder->userCanEdit() || $methodName == "show") {
         $form->makeReadonly();
     }
     return $form;
 }
 /**
  * Test removing a field from a set by it's name.
  */
 function testRemoveFieldByName()
 {
     $fields = new FieldSet();
     /* First of all, we add a field into our FieldSet object */
     $fields->push(new TextField('Name', 'Your name'));
     /* We have 1 field in our set now */
     $this->assertEquals(1, $fields->Count());
     /* Then, we call up removeByName() to take it out again */
     $fields->removeByName('Name');
     /* We have 0 fields in our set now, as we've just removed the one we added */
     $this->assertEquals(0, $fields->Count());
 }
Ejemplo n.º 18
0
 /**
  * If the record is not shown in the default language, this method
  * will try to autoselect a master language which is shown alongside
  * the normal formfields as a readonly representation.
  * This gives translators a powerful tool for their translation workflow
  * without leaving the translated page interface.
  * Translatable also adds a new tab "Translation" which shows existing
  * translations, as well as a formaction to create new translations based
  * on a dropdown with available languages.
  * 
  * @todo This is specific to SiteTree and CMSMain
  * @todo Implement a special "translation mode" which triggers display of the
  * readonly fields, so you can translation INTO the "default language" while
  * seeing readonly fields as well.
  */
 function updateCMSFields(FieldSet &$fields)
 {
     // Don't apply these modifications for normal DataObjects - they rely on CMSMain logic
     if (!$this->owner instanceof SiteTree) {
         return;
     }
     // used in CMSMain->init() to set language state when reading/writing record
     $fields->push(new HiddenField("Locale", "Locale", $this->owner->Locale));
     // Don't allow translation of virtual pages because of data inconsistencies (see #5000)
     $excludedPageTypes = array('VirtualPage');
     foreach ($excludedPageTypes as $excludedPageType) {
         if (is_a($this->owner, $excludedPageType)) {
             return;
         }
     }
     $excludeFields = array('ViewerGroups', 'EditorGroups', 'CanViewType', 'CanEditType');
     // if a language other than default language is used, we're in "translation mode",
     // hence have to modify the original fields
     $creating = false;
     $baseClass = $this->owner->class;
     $allFields = $fields->toArray();
     while (($p = get_parent_class($baseClass)) != "DataObject") {
         $baseClass = $p;
     }
     // try to get the record in "default language"
     $originalRecord = $this->owner->getTranslation(Translatable::default_locale());
     // if no translation in "default language", fall back to first translation
     if (!$originalRecord) {
         $translations = $this->owner->getTranslations();
         $originalRecord = $translations ? $translations->First() : null;
     }
     $isTranslationMode = $this->owner->Locale != Translatable::default_locale();
     // Show a dropdown to create a new translation.
     // This action is possible both when showing the "default language"
     // and a translation. Include the current locale (record might not be saved yet).
     $alreadyTranslatedLocales = $this->getTranslatedLocales();
     $alreadyTranslatedLocales[$this->owner->Locale] = $this->owner->Locale;
     if ($originalRecord && $isTranslationMode) {
         $originalLangID = Session::get($this->owner->ID . '_originalLangID');
         // Remove parent page dropdown
         $fields->removeByName("ParentType");
         $fields->removeByName("ParentID");
         $translatableFieldNames = $this->getTranslatableFields();
         $allDataFields = $fields->dataFields();
         $transformation = new Translatable_Transformation($originalRecord);
         // iterate through sequential list of all datafields in fieldset
         // (fields are object references, so we can replace them with the translatable CompositeField)
         foreach ($allDataFields as $dataField) {
             if ($dataField instanceof HiddenField) {
                 continue;
             }
             if (in_array($dataField->Name(), $excludeFields)) {
                 continue;
             }
             if (in_array($dataField->Name(), $translatableFieldNames)) {
                 // if the field is translatable, perform transformation
                 $fields->replaceField($dataField->Name(), $transformation->transformFormField($dataField));
             } else {
                 // else field shouldn't be editable in translation-mode, make readonly
                 $fields->replaceField($dataField->Name(), $dataField->performReadonlyTransformation());
             }
         }
     } elseif ($this->owner->isNew()) {
         $fields->addFieldsToTab('Root', new Tab(_t('Translatable.TRANSLATIONS', 'Translations'), new LiteralField('SaveBeforeCreatingTranslationNote', sprintf('<p class="message">%s</p>', _t('Translatable.NOTICENEWPAGE', 'Please save this page before creating a translation')))));
     }
     $fields->addFieldsToTab('Root', new Tab('Translations', _t('Translatable.TRANSLATIONS', 'Translations'), new HeaderField('CreateTransHeader', _t('Translatable.CREATE', 'Create new translation'), 2), $langDropdown = new LanguageDropdownField("NewTransLang", _t('Translatable.NEWLANGUAGE', 'New language'), $alreadyTranslatedLocales, 'SiteTree', 'Locale-English', $this->owner), $createButton = new InlineFormAction('createtranslation', _t('Translatable.CREATEBUTTON', 'Create'))));
     $createButton->includeDefaultJS(false);
     if ($alreadyTranslatedLocales) {
         $fields->addFieldToTab('Root.Translations', new HeaderField('ExistingTransHeader', _t('Translatable.EXISTING', 'Existing translations:'), 3));
         $existingTransHTML = '<ul>';
         foreach ($alreadyTranslatedLocales as $i => $langCode) {
             $existingTranslation = $this->owner->getTranslation($langCode);
             if ($existingTranslation) {
                 $existingTransHTML .= sprintf('<li><a href="%s">%s</a></li>', sprintf('admin/show/%d/?locale=%s', $existingTranslation->ID, $langCode), i18n::get_locale_name($langCode));
             }
         }
         $existingTransHTML .= '</ul>';
         $fields->addFieldToTab('Root.Translations', new LiteralField('existingtrans', $existingTransHTML));
     }
     $langDropdown->addExtraClass('languageDropdown');
     $createButton->addExtraClass('createTranslationButton');
 }
	/**
	 * Get the pop-up fields for the given record.
	 */
	function getCustomFieldsFor($childData) {
		if(!$childData) {
			user_error("AssetTableField::DetailForm No record found");
			return null;
		}
		
		if($childData->ParentID) {
			$folder = DataObject::get_by_id('File', $childData->ParentID );
		} else {
			$folder = singleton('Folder');
		}
		
		$urlLink = "<div class='field readonly'>";
		$urlLink .= "<label class='left'>"._t('AssetTableField.URL','URL')."</label>";
		$urlLink .= "<span class='readonly'><a href='{$childData->Link()}'>{$childData->RelativeLink()}</a></span>";
		$urlLink .= "</div>";
		
		$detailFormFields = new FieldSet(
			new TabSet("BottomRoot",
				$mainTab = new Tab('Main',
					new TextField("Title", _t('AssetTableField.TITLE','Title')),
					new TextField("Name", _t('AssetTableField.FILENAME','Filename')),
					new LiteralField("AbsoluteURL", $urlLink),
					new ReadonlyField("FileType", _t('AssetTableField.TYPE','Type')),
					new ReadonlyField("Size", _t('AssetTableField.SIZE','Size'), $childData->getSize()),
					new DropdownField("OwnerID", _t('AssetTableField.OWNER','Owner'), Member::mapInCMSGroups()),
					new DateField_Disabled("Created", _t('AssetTableField.CREATED','First uploaded')),
					new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT','Last changed'))
				)
			)
		);
		$mainTab->setTitle(_t('AssetTableField.MAIN', 'Main'));

		if(is_a($childData, 'Image')) {
			$tab = $detailFormFields->findOrMakeTab("BottomRoot.Image", _t('AssetTableField.IMAGE', 'Image'));
			
			$big = $childData->URL;
			$formattedImage = $childData->getFormattedImage('AssetLibraryPreview');
			$thumbnail = $formattedImage ? $formattedImage->URL : '';
			
			// Hmm this required the translated string to be appended to BottomRoot to add this to the Main tab
			$detailFormFields->addFieldToTab('BottomRoot.Main',
				new ReadonlyField("Dimensions", _t('AssetTableField.DIM','Dimensions'))
			);

			$tab->push(
				new LiteralField("ImageFull",
					"<img id='thumbnailImage' src='{$thumbnail}?r=" . rand(1,100000)  . "' alt='{$childData->Name}' />"
				)
			);
		}

		if($childData && $childData->hasMethod('BackLinkTracking')) {
			if(class_exists('Subsite')) Subsite::disable_subsite_filter(true);
			$links = $childData->BackLinkTracking();
			if(class_exists('Subsite')) Subsite::disable_subsite_filter(false);

			if($links && $links->exists()) {
				$backlinks = array();
				foreach($links as $link) {
					$backlinks[] = "<li><a href=\"admin/show/$link->ID\">" . $link->Breadcrumbs(null,true). "</a></li>";
				}
				$backlinks = "<div style=\"clear:left\">". _t('AssetTableField.PAGESLINKING','The following pages link to this file:') ."<ul>" . implode("",$backlinks) . "</ul></div>";
			}
			if(!isset($backlinks)) $backlinks = "<p>". _t('AssetTableField.NOLINKS',"This file hasn't been linked to from any pages.") ."</p>";
			$detailFormFields->addFieldToTab("BottomRoot.Links", new LiteralField("Backlinks", $backlinks));
		}
		
		// the ID field confuses the Controller-logic in finding the right view for ReferencedField
		$detailFormFields->removeByName('ID');
		
		if($childData) $childData->extend('updateCMSFields', $detailFormFields);
		
		return $detailFormFields;
	}
Ejemplo n.º 20
0
 /**
  * Remove a field from this CompositeField by Name.
  * The field could also be inside a CompositeField.
  * 
  * @param string $fieldName The name of the field
  * @param boolean $dataFieldOnly If this is true, then a field will only
  * be removed if it's a data field.  Dataless fields, such as tabs, will
  * be left as-is.
  */
 public function removeByName($fieldName, $dataFieldOnly = false)
 {
     $this->children->removeByName($fieldName, $dataFieldOnly);
 }