function updateCMSFields(FieldList $fields) { $lists = CampaignMonitorSignupPage::get_ready_ones(); if ($lists && $lists->count()) { $options = array(0 => _t("EcommerceNewsletterCampaignMonitorSignup.PLEASE_SELECT", "-- please select --")) + $lists->map()->toArray(); if ($this->owner->CampaignMonitorSignupPageID) { $fields->addFieldsToTab("Root.Newsletter", array(new DropdownField("CampaignMonitorSignupPageID", _t("EcommerceNewsletterCampaignMonitorSignup.SIGN_UP_TO", "Sign-up for ..."), $options), new TextField("CampaignMonitorSignupHeader", _t("EcommerceNewsletterCampaignMonitorSignup.HEADER", "Header")), new TextField("CampaignMonitorSignupIntro", _t("EcommerceNewsletterCampaignMonitorSignup.INTRO", "Intro")), new TextField("CampaignMonitorSignupLabel", _t("EcommerceNewsletterCampaignMonitorSignup.LABEL", "Label")))); } else { $fields->addFieldsToTab("Root.Newsletter", array(new DropdownField("CampaignMonitorSignupPageID", _t("EcommerceNewsletterCampaignMonitorSignup.SIGN_UP_TO", "Sign-up for ..."), $options))); $fields->removeFieldsFromTab("Root.Main", array("CampaignMonitorSignupHeader", "CampaignMonitorSignupIntro", "CampaignMonitorSignupLabel")); } } else { $fields->addFieldToTab("Root.Newsletter", new LiteralField("ListExplanation", "<p class=\"message warning\">\n\t\t\t\t\t" . _t("EcommerceNewsletterCampaignMonitorSignup.RECOMMENDATION_TO_SETUP", "It is recommended you set up a Campaign Monitor Page with a valid list to subscribe to.") . "\n\t\t\t\t\t</p>")); } }
/** * Test removing an array of fields from a tab in a set. */ public function testRemoveMultipleFieldsFromTab() { $fields = new FieldList(); $tab = new Tab('Root'); $fields->push($tab); /* We add an array of fields, using addFieldsToTab() */ $fields->addFieldsToTab('Root', array(new TextField('Name', 'Your name'), new EmailField('Email', 'Email address'), new NumericField('Number', 'Insert a number'))); /* We have 3 fields inside the tab, which we just created */ $this->assertEquals(3, $tab->Fields()->Count()); /* We remove the 3 fields from the tab */ $fields->removeFieldsFromTab('Root', array('Name', 'Email', 'Number')); /* We have no fields in the tab now */ $this->assertEquals(0, $tab->Fields()->Count()); }