<commit_before><?php
class SubsitesVirtualPage extends VirtualPage {

	private static $description = 'Displays the content of a page on another subsite';

	private static $db = array(
		'CustomMetaTitle' => 'Varchar(255)',
		'CustomMetaKeywords' => 'Varchar(255)',
		'CustomMetaDescription' => 'Text',
		'CustomExtraMeta' => 'HTMLText'
	);
	
	public function getCMSFields() {
		$fields = parent::getCMSFields();
		
		$subsites = DataObject::get('Subsite');
		if(!$subsites) {
			$subsites = new ArrayList();
		}else {
			$subsites=ArrayList::create($subsites->toArray());
		}
		
		$subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0)));

		$subsiteSelectionField = new DropdownField(
			"CopyContentFromID_SubsiteID", 
			_t('SubsitesVirtualPage.SubsiteField',"Subsite"), 
			$subsites->map('ID', 'Title'),
			($this->CopyContentFromID) ? $this->CopyContentFrom()->SubsiteID : Session::get('SubsiteID')
		);
		$fields->addFieldToTab(
			'Root.Main',
			$subsiteSelectionField,
			'CopyContentFromID'
		);
		
		// Setup the linking to the original page.
		$pageSelectionField = new SubsitesTreeDropdownField(
			"CopyContentFromID", 
			_t('VirtualPage.CHOOSE', "Choose a page to link to"), 
			"SiteTree",
			"ID",
			"MenuTitle"
		);
		
		if(Controller::has_curr() && Controller::curr()->getRequest()) {
			$subsiteID = Controller::curr()->getRequest()->postVar('CopyContentFromID_SubsiteID');
			$pageSelectionField->setSubsiteID($subsiteID);
		}
		$fields->replaceField('CopyContentFromID', $pageSelectionField);
		
		// Create links back to the original object in the CMS
		if($this->CopyContentFromID) {
			$editLink = "admin/page/edit/show/$this->CopyContentFromID/?SubsiteID=" . $this->CopyContentFrom()->SubsiteID;
			$linkToContent = "
				<a class=\"cmsEditlink\" href=\"$editLink\">" . 
				_t('VirtualPage.EDITCONTENT', 'Click here to edit the content') . 
				"</a>";
			$fields->removeByName("VirtualPageContentLinkLabel");
			$fields->addFieldToTab(
				"Root.Main", 
				$linkToContentLabelField = new LabelField('VirtualPageContentLinkLabel', $linkToContent),
				'Title'
			);
			$linkToContentLabelField->setAllowHTML(true);
		}
		
		
		$fields->addFieldToTab(
			'Root.Main', 
			TextField::create(
				'CustomMetaTitle', 
				$this->fieldLabel('CustomMetaTitle')
			)->setDescription(_t('SubsitesVirtualPage.OverrideNote', 'Overrides inherited value from the source')), 
			'MetaTitle'
		);
		$fields->addFieldToTab(
			'Root.Main', 
			TextareaField::create(
				'CustomMetaKeywords', 
				$this->fieldLabel('CustomMetaTitle')
			)->setDescription(_t('SubsitesVirtualPage.OverrideNote')), <commit_msg>Correct link to editing a subsite virtual page.<commit_after><?php
class SubsitesVirtualPage extends VirtualPage {

	private static $description = 'Displays the content of a page on another subsite';

	private static $db = array(
		'CustomMetaTitle' => 'Varchar(255)',
		'CustomMetaKeywords' => 'Varchar(255)',
		'CustomMetaDescription' => 'Text',
		'CustomExtraMeta' => 'HTMLText'
	);
	
	public function getCMSFields() {
		$fields = parent::getCMSFields();
		
		$subsites = DataObject::get('Subsite');
		if(!$subsites) {
			$subsites = new ArrayList();
		}else {
			$subsites=ArrayList::create($subsites->toArray());
		}
		
		$subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0)));

		$subsiteSelectionField = new DropdownField(
			"CopyContentFromID_SubsiteID", 
			_t('SubsitesVirtualPage.SubsiteField',"Subsite"), 
			$subsites->map('ID', 'Title'),
			($this->CopyContentFromID) ? $this->CopyContentFrom()->SubsiteID : Session::get('SubsiteID')
		);
		$fields->addFieldToTab(
			'Root.Main',
			$subsiteSelectionField,
			'CopyContentFromID'
		);
		
		// Setup the linking to the original page.
		$pageSelectionField = new SubsitesTreeDropdownField(
			"CopyContentFromID", 
			_t('VirtualPage.CHOOSE', "Choose a page to link to"), 
			"SiteTree",
			"ID",
			"MenuTitle"
		);
		
		if(Controller::has_curr() && Controller::curr()->getRequest()) {
			$subsiteID = Controller::curr()->getRequest()->postVar('CopyContentFromID_SubsiteID');
			$pageSelectionField->setSubsiteID($subsiteID);
		}
		$fields->replaceField('CopyContentFromID', $pageSelectionField);
		
		// Create links back to the original object in the CMS
		if($this->CopyContentFromID) {
			$editLink = "admin/pages/edit/show/$this->CopyContentFromID/?SubsiteID=" . $this->CopyContentFrom()->SubsiteID;
			$linkToContent = "
				<a class=\"cmsEditlink\" href=\"$editLink\">" . 
				_t('VirtualPage.EDITCONTENT', 'Click here to edit the content') . 
				"</a>";
			$fields->removeByName("VirtualPageContentLinkLabel");
			$fields->addFieldToTab(
				"Root.Main", 
				$linkToContentLabelField = new LabelField('VirtualPageContentLinkLabel', $linkToContent),
				'Title'
			);
			$linkToContentLabelField->setAllowHTML(true);
		}
		
		
		$fields->addFieldToTab(
			'Root.Main', 
			TextField::create(
				'CustomMetaTitle', 
				$this->fieldLabel('CustomMetaTitle')
			)->setDescription(_t('SubsitesVirtualPage.OverrideNote', 'Overrides inherited value from the source')), 
			'MetaTitle'
		);
		$fields->addFieldToTab(
			'Root.Main', 
			TextareaField::create(
				'CustomMetaKeywords', 
				$this->fieldLabel('CustomMetaTitle')
			)->setDescription(_t('SubsitesVirtualPage.OverrideNote')), 
{'fraction_non_alphanumeric': 0.16005266127515516, 'fraction_numerical': 0.002633063757758134, 'mean_word_length': 4.749189189189189, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7292178', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1689, 'n_words': 295}