function testFieldHasExtraClass() { /* TextField has an extra class name and is in the HTML the field returns */ $textField = new TextField('Name'); $textField->addExtraClass('thisIsMyClassNameForTheFormField'); preg_match('/thisIsMyClassNameForTheFormField/', $textField->Field(), $matches); $this->assertTrue($matches[0] == 'thisIsMyClassNameForTheFormField'); /* EmailField has an extra class name and is in the HTML the field returns */ $emailField = new EmailField('Email'); $emailField->addExtraClass('thisIsMyExtraClassForEmailField'); preg_match('/thisIsMyExtraClassForEmailField/', $emailField->Field(), $matches); $this->assertTrue($matches[0] == 'thisIsMyExtraClassForEmailField'); /* OptionsetField has an extra class name and is in the HTML the field returns */ $optionsetField = new OptionsetField('FeelingOk', 'Are you feeling ok?', array(0 => 'No', 1 => 'Yes'), '', null, '(Select one)'); $optionsetField->addExtraClass('thisIsMyExtraClassForOptionsetField'); preg_match('/thisIsMyExtraClassForOptionsetField/', $optionsetField->Field(), $matches); $this->assertTrue($matches[0] == 'thisIsMyExtraClassForOptionsetField'); }
private function buildPosts(&$request, &$fields) { $posts = $request->data; $unmoderatedCount = 0; foreach ($posts as $post) { $moderated = DataObject::get('InstagramPost')->filter(array('MediaID' => $post->id)); if (!$moderated->count()) { $postData = '<div class="post"><img src="' . $post->images->standard_resolution->url . '" width="300" height="300" alt="" /><p>' . $post->caption->text . '</p></div>'; $postField = new OptionsetField($name = 'Instagram_' . $post->id, $title = $postData, $source = array("approve" => "Approve", "reject" => "Reject")); $imageField = new HiddenField('ImageData_' . $post->id, 'ImageData_' . $post->id, json_encode(array('images' => $post->images, 'link' => $post->link))); $postField->addExtraClass('instagram-post'); $fields->add($postField); $fields->add($imageField); $unmoderatedCount++; } } if (!$unmoderatedCount) { $request = $this->requestPosts($request->pagination->next_url); $this->buildPosts($request, $fields); } }
/** * Returns a FieldList with which to create the CMS editing form * * @return FieldList The fields to be displayed in the CMS. */ function getCMSFields() { Requirements::javascript("forum/javascript/ForumAccess.js"); Requirements::css("forum/css/Forum_CMS.css"); $fields = parent::getCMSFields(); $fields->addFieldToTab("Root.Access", new HeaderField(_t('Forum.ACCESSPOST', 'Who can post to the forum?'), 2)); $fields->addFieldToTab("Root.Access", $optionSetField = new OptionsetField("CanPostType", "", array("Inherit" => "Inherit", "Anyone" => _t('Forum.READANYONE', 'Anyone'), "LoggedInUsers" => _t('Forum.READLOGGEDIN', 'Logged-in users'), "OnlyTheseUsers" => _t('Forum.READLIST', 'Only these people (choose from list)'), "NoOne" => _t('Forum.READNOONE', 'Nobody. Make Forum Read Only')))); $optionSetField->addExtraClass('ForumCanPostTypeSelector'); $fields->addFieldsToTab("Root.Access", array(new TreeMultiselectField("PosterGroups", _t('Forum.GROUPS', "Groups")), new OptionsetField("CanAttachFiles", _t('Forum.ACCESSATTACH', 'Can users attach files?'), array("1" => _t('Forum.YES', 'Yes'), "0" => _t('Forum.NO', 'No'))))); //Dropdown of forum category selection. $categories = ForumCategory::get()->map(); $fields->addFieldsToTab("Root.Main", DropdownField::create('CategoryID', _t('Forum.FORUMCATEGORY', 'Forum Category'), $categories), 'Content'); //GridField Config - only need to attach or detach Moderators with existing Member accounts. $moderatorsConfig = GridFieldConfig::create()->addComponent(new GridFieldButtonRow('before'))->addComponent(new GridFieldAddExistingAutocompleter('buttons-before-right'))->addComponent(new GridFieldToolbarHeader())->addComponent($sort = new GridFieldSortableHeader())->addComponent($columns = new GridFieldDataColumns())->addComponent(new GridFieldDeleteAction(true))->addComponent(new GridFieldPageCount('toolbar-header-right'))->addComponent($pagination = new GridFieldPaginator()); // Use GridField for Moderator management $moderators = GridField::create('Moderators', _t('MODERATORS', 'Moderators for this forum'), $this->Moderators(), $moderatorsConfig); $columns->setDisplayFields(array('Nickname' => 'Nickname', 'FirstName' => 'First name', 'Surname' => 'Surname', 'Email' => 'Email', 'LastVisited.Long' => 'Last Visit')); $sort->setThrowExceptionOnBadDataType(false); $pagination->setThrowExceptionOnBadDataType(false); $fields->addFieldToTab('Root.Moderators', $moderators); return $fields; }