public function updateCMSFields(FieldList $fields)
 {
     // Payment Methods
     $payment_table = GridField::create('PaymentMethods', _t("CheckoutAdmin.PaymentMethods", "Payment Methods"), $this->owner->PaymentMethods(), GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldAddNewButton('toolbar-header-right'), new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator(20), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm()));
     // setup compressed payment options
     $payment_fields = ToggleCompositeField::create('PaymentSettings', _t("CheckoutAdmin.Payments", "Payment Settings"), array(TextField::create('PaymentNumberPrefix', _t("CheckoutAdmin.OrderPrefix", "Add prefix to order numbers"), null, 9)->setAttribute("placeholder", _t("CheckoutAdmin.OrderPrefixPlaceholder", "EG 'abc'")), TextAreaField::create('PaymentSuccessContent', _t("CheckoutAdmin.PaymentSuccessContent", "Payment successfull content"))->setRows(4)->setColumns(30)->addExtraClass('stacked'), TextAreaField::create('PaymentFailerContent', _t("CheckoutAdmin.PaymentFailerContent", "Payment failer content"))->setRows(4)->setColumns(30)->addExtraClass('stacked'), $payment_table));
     // Add html description of how to edit contries
     $country_html = "<div class=\"field\">";
     $country_html .= "<p>First select valid countries using the 2 character ";
     $country_html .= "shortcode (see http://fasteri.com/list/2/short-names-of-countries-and-iso-3166-codes).</p>";
     $country_html .= "<p>You can add multiple countries seperating them with";
     $country_html .= "a comma or use a '*' for all countries.</p>";
     $country_html .= "</div>";
     $country_html_field = LiteralField::create("CountryDescription", $country_html);
     // Deal with product features
     $postage_field = new GridField('PostageAreas', '', $this->owner->PostageAreas(), GridFieldConfig::create()->addComponents(new GridFieldButtonRow('before'), new GridFieldToolbarHeader(), new GridFieldTitleHeader(), new GridFieldEditableColumns(), new GridFieldDeleteAction(), new GridFieldAddNewInlineButton('toolbar-header-left')));
     // Add country dropdown to inline editing
     $postage_field->getConfig()->getComponentByType('GridFieldEditableColumns')->setDisplayFields(array('Title' => array('title' => 'Title', 'field' => 'TextField'), 'Country' => array('title' => 'ISO 3166 codes', 'field' => 'TextField'), 'ZipCode' => array('title' => 'Zip/Post Codes', 'field' => 'TextField'), 'Calculation' => array('title' => 'Base unit', 'callback' => function ($record, $column, $grid) {
         return DropdownField::create($column, "Based on", singleton('PostageArea')->dbObject('Calculation')->enumValues())->setValue("Weight");
     }), 'Unit' => array('title' => 'Unit (equals or above)', 'field' => 'NumericField'), 'Cost' => array('title' => 'Cost', 'field' => 'NumericField'), 'Tax' => array('title' => 'Tax (percentage)', 'field' => 'NumericField')));
     // Setup compressed postage options
     $postage_fields = ToggleCompositeField::create('PostageFields', 'Postage Options', array($country_html_field, $postage_field));
     // Setup compressed postage options
     $discount_fields = ToggleCompositeField::create('DiscountFields', 'Discounts', array(GridField::create('Discounts', '', $this->owner->Discounts(), GridFieldConfig_RecordEditor::create())));
     // Add config sets
     $fields->addFieldToTab('Root.Checkout', $payment_fields);
     $fields->addFieldToTab('Root.Checkout', $postage_fields);
     $fields->addFieldToTab('Root.Checkout', $discount_fields);
 }
 public function handleAction(GridField $gridField, $actionName, $arguments, $data)
 {
     if ($actionName == 'publishsummitevent') {
         $summit_event = $gridField->getList()->byID($arguments['RecordID']);
         $former_state = $summit_event->isPublished();
         $msg = 'Summit Event Published!';
         $code = 200;
         try {
             if ($former_state) {
                 $summit_event->unPublish();
             } else {
                 $summit_event->publish();
             }
             $summit_event->write();
             if ($former_state) {
                 $msg = 'Summit Event Unpublished!';
             }
         } catch (Exception $ex) {
             //SS_Log::log($ex->getMessage(). SS_Log::ERR);
             //throw new ValidationException($ex->getMessage(),0);
             //return sprintf('<div>%s</div>', $ex->getMessage());
             //Controller::curr()->getResponse()->setStatusCode($code,  $ex->getMessage());
             //Controller::curr()->getResponse()->setBody(sprintf('<div>%s</div>', $ex->getMessage()));
             throw new ValidationException($ex->getMessage(), 0);
         }
         Controller::curr()->getResponse()->setStatusCode($code, $msg);
     }
 }
 /**
  * Gets the classes that can be created using this button, defaulting to the model class and
  * its subclasses.
  *
  * @param GridField $grid
  * @return array a map of class name to title
  */
 public function getClasses(GridField $grid)
 {
     $result = array();
     if (is_null($this->classes)) {
         $classes = array_values(ClassInfo::subclassesFor($grid->getModelClass()));
         sort($classes);
     } else {
         $classes = $this->classes;
     }
     $kill_ancestors = array();
     foreach ($classes as $class => $title) {
         if (!is_string($class)) {
             $class = $title;
             $is_abstract = ($reflection = new ReflectionClass($class)) && $reflection->isAbstract();
             if (!$is_abstract) {
                 $title = singleton($class)->i18n_singular_name();
             }
         } else {
             $is_abstract = ($reflection = new ReflectionClass($class)) && $reflection->isAbstract();
         }
         if ($ancestor_to_hide = Config::inst()->get($class, 'hide_ancestor', Config::FIRST_SET)) {
             $kill_ancestors[$ancestor_to_hide] = true;
         }
         if ($is_abstract || !singleton($class)->canCreate()) {
             continue;
         }
         $result[$class] = $title;
     }
     if ($kill_ancestors) {
         foreach ($kill_ancestors as $class => $bool) {
             unset($result[$class]);
         }
     }
     return $result;
 }
 public function testShowEditLinksWithAdminPermission()
 {
     $this->logInWithPermission('ADMIN');
     $content = new CSSContentParser($this->gridField->FieldHolder());
     $editLinks = $content->getBySelector('.edit-link');
     $this->assertEquals(2, count($editLinks), 'Edit links should show when logged in.');
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->insertBefore(new DropdownField('MemberID', 'Member', Member::get()->map('ID', "FirstName")), 'AttendingWholeEvent');
     $siteConfig = SiteConfig::current_site_config();
     $current = $siteConfig->getCurrentEventID();
     if ($this->ParentID < 1) {
         $event = Event::get()->byID($current);
     } else {
         $event = Event::get()->byID($this->ParentID);
     }
     $fields->insertAfter(HiddenField::create('ParentID', 'Event', $event->ID), 'ExtraDetail');
     $fields->removeByName('PublicFieldsRaw');
     $fields->removeByName('Sort');
     if ($this->PlayerGames()->Count() > 0) {
         $gridField = new GridField('PlayerGames', 'Games', $this->PlayerGames(), $config = GridFieldConfig_RelationEditor::create());
         $gridField->setModelClass('PlayerGame');
         $config->addComponent(new GridFieldOrderableRows());
         $config->removeComponentsByType('GridFieldPaginator');
         $config->removeComponentsByType('GridFieldPageCount');
         $config->addComponent(new GridFieldDeleteAction(false));
         $config->addComponent($export = new GridFieldExportButton('before'));
         $export->setExportColumns(singleton("PlayerGame")->getExportFields());
         $fields->addFieldToTab('Root.PlayerGames', $gridField);
     }
     return $fields;
 }
 public function handleAction(\GridField $gridField, $actionName, $arguments, $data)
 {
     if ($actionName != $this->urlSegment) {
         return;
     }
     $record = $gridField->Form && $gridField->Form->Record ? $gridField->Form->Record : null;
     if (!$record || !$record->SiteTreeID) {
         throw new \ValidationException(_t('Link.NO_CURRENT_PAGE', 'No current page to draw from'), 0);
     }
     $root = \SiteTree::get()->filter('ParentID', $record->SiteTreeID);
     if (!$root->exists()) {
         throw new \ValidationException(_t('Link.NO_PAGES', 'No pages available'), 0);
     }
     $item = singleton($gridField->getModelClass());
     if (!$item->canCreate()) {
         throw new \ValidationException(_t('Link.CANNOT_CREATE', 'You cannot create a Link'), 0);
     }
     foreach ($root as $page) {
         $link = $item->create();
         $link->Type = 'SiteTree';
         $link->SiteTreeID = $page->ID;
         $link->write();
         $gridField->getList()->add($link);
     }
 }
 /**
  *
  * @param \GridField $gridField
  * @param \SS_List $dataList
  * @return \SS_List
  */
 public function getManipulatedData(\GridField $gridField, \SS_List $dataList)
 {
     $state = $gridField->State->Milkyway_SS_GridFieldUtils_RangeSlider;
     if (!isset($state->min) && !isset($state->value)) {
         $settings = $this->scaffoldSliderSettingsForField(singleton($gridField->getModelClass())->obj($this->filterField), $dataList);
         $this->working = [$gridField, $dataList];
         if (isset($settings['start'])) {
             if (is_array($settings['start'])) {
                 $state->min = $settings['start'][0];
                 $state->max = $settings['start'][1];
             } else {
                 $state->value = $settings['start'];
             }
         } else {
             return $dataList;
         }
     }
     $dataListClone = clone $dataList;
     $dbField = singleton($gridField->getModelClass())->obj($this->filterField);
     if (isset($state->value)) {
         $comparisonFilter = $this->comparisonFilter ? '' : ':' . $this->comparisonFilter;
         $dataListClone = $dataListClone->filter($this->filterField . $comparisonFilter, $this->getValueForDB($dbField, $state->value));
     } elseif (isset($state->min) && isset($state->max)) {
         $dataListClone = $dataListClone->filter([$this->filterField . ':GreaterThan' => $this->getValueForDB($dbField, $state->min), $this->filterField . ':LessThan' => $this->getValueForDB($dbField, $state->max)]);
     }
     return $dataListClone;
 }
 /**
  * Gets the classes that can be created using this button, defaulting to the model class and
  * its subclasses.
  *
  * @param \GridField $grid
  * @return array a map of class name to title
  */
 public function getAllowedClasses(\GridField $grid)
 {
     $result = array();
     if ($this->useAllowedClasses) {
         $classes = $this->useAllowedClasses;
         $this->useAllowedClasses = null;
         return $classes;
     } else {
         if (is_null($this->allowedClasses)) {
             $classes = array_values(\ClassInfo::subclassesFor($grid->getModelClass()));
             sort($classes);
         } else {
             $classes = $this->allowedClasses;
         }
     }
     foreach ($classes as $class => $title) {
         if (!is_string($class)) {
             $class = $title;
             $title = singleton($class)->i18n_singular_name();
         }
         if (!singleton($class)->canCreate()) {
             continue;
         }
         $result[$class] = $title;
     }
     return $result;
 }
 protected function setupGridField(GridField $gridfield, Config_ForClass $classConfig)
 {
     if (!$gridfield) {
         return;
     }
     $config = $gridfield->getConfig();
     $class = $gridfield->getModelClass();
     // More item per page
     $paginator = $config->getComponentByType('GridFieldPaginator');
     $paginator->setItemsPerPage(50);
     // Bulk manage
     if ($classConfig->bulk_manage && class_exists('GridFieldBulkManager')) {
         $already = $config->getComponentByType('GridFieldBulkManager');
         if (!$already) {
             $config->addComponent($bulkManager = new GridFieldBulkManager());
             $bulkManager->removeBulkAction('unLink');
         }
     }
     // Better export
     if ($classConfig->export_csv) {
         /* @var $export GridFieldExportButton */
         $export = $config->getComponentByType('GridFieldExportButton');
         $export->setExportColumns(ExcelImportExport::exportFieldsForClass($class));
     } else {
         $config->removeComponentsByType('GridFieldExportButton');
     }
     if ($classConfig->export_excel) {
         if ($class == 'Group') {
             $config->addComponent(new GridFieldButtonRow('after'));
         }
         $config->addComponent(new ExcelGridFieldExportButton('buttons-after-left'));
     }
 }
 public function getCMSFields()
 {
     $fields = singleton('DataObject')->getCMSFields();
     $fields->addFieldsToTab('Root.Main', array(new ReadonlyField('SubmittedBy', 'Submitted By'), new ReadonlyField('IPAddress', 'IP Address'), new ReadonlyField('Created', 'Time Submitted'), new ReadonlyField('StatusMessages'), $field = new GridField('Values', 'Responses', $this->Values(), new GridFieldConfig_FlexiFormSubmissionValues())));
     $field->addExtraClass('flexiform');
     return $fields;
 }
 protected function saveAllRecords(\GridField $grid, $arguments, $data)
 {
     if (isset($data[$grid->Name])) {
         $currValue = $grid->Value();
         $grid->setValue($data[$grid->Name]);
         $model = singleton($grid->List->dataClass());
         foreach ($grid->getConfig()->getComponents() as $component) {
             if ($component instanceof \GridField_SaveHandler) {
                 $component->handleSave($grid, $model);
             }
         }
         if ($this->publish) {
             // Only use the viewable list items, since bulk publishing can take a toll on the system
             $list = ($paginator = $grid->getConfig()->getComponentByType('GridFieldPaginator')) ? $paginator->getManipulatedData($grid, $grid->List) : $grid->List;
             $list->each(function ($item) {
                 if ($item->hasExtension('Versioned')) {
                     $item->writeToStage('Stage');
                     $item->publish('Stage', 'Live');
                 }
             });
         }
         if ($model->exists()) {
             $model->delete();
             $model->destroy();
         }
         $grid->setValue($currValue);
         if (\Controller::curr() && ($response = \Controller::curr()->Response)) {
             if (!$this->completeMessage) {
                 $this->completeMessage = _t('GridField.DONE', 'Done.');
             }
             $response->addHeader('X-Status', rawurlencode($this->completeMessage));
         }
     }
 }
 function updateCMSFields(FieldList $fields)
 {
     $fields->addFieldToTab('Root.SkitterSlides', $grid = new GridField('MaxSkitterSlides', 'Skitter slides', $this->owner->MaxSkitterSlides(), GridFieldConfig_RelationEditor::create(10)));
     if (class_exists("GridFieldSortableRows")) {
         $grid->getConfig()->addComponent(new GridFieldSortableRows('SortOrder'));
     }
 }
 public function updateCMSFields(FieldList $fields)
 {
     if ($this->owner->ID) {
         // Relation handler for Blocks
         $SConfig = GridFieldConfig_RelationEditor::create(25);
         $SConfig->addComponent(new GridFieldOrderableRows('SortOrder'));
         $SConfig->addComponent(new GridFieldDeleteAction());
         // If the copy button module is installed, add copy as option
         if (class_exists('GridFieldCopyButton')) {
             $SConfig->addComponent(new GridFieldCopyButton(), 'GridFieldDeleteAction');
         }
         $gridField = new GridField("Blocks", "Content blocks", $this->owner->Blocks(), $SConfig);
         $classes = array_values(ClassInfo::subclassesFor($gridField->getModelClass()));
         if (count($classes) > 1 && class_exists('GridFieldAddNewMultiClass')) {
             $SConfig->removeComponentsByType('GridFieldAddNewButton');
             $SConfig->addComponent(new GridFieldAddNewMultiClass());
         }
         if (self::$create_block_tab) {
             $fields->addFieldToTab("Root.Blocks", $gridField);
         } else {
             // Downsize the content field
             $fields->removeByName('Content');
             $fields->addFieldToTab('Root.Main', HTMLEditorField::create('Content')->setRows(self::$contentarea_rows), 'Metadata');
             $fields->addFieldToTab("Root.Main", $gridField, 'Metadata');
         }
     }
     return $fields;
 }
 /**
  * Handles the add action for the given DataObject.
  *
  * @param $gridField GridField
  * @param $actionName string
  * @param $arguments mixed
  * @param $data array
  *
  * @return null|SS_HTTPResponse
  *
  * @throws UnexpectedValueException
  */
 public function handleAction(GridField $gridField, $actionName, $arguments, $data)
 {
     if ($actionName == 'add') {
         $dbField = $this->getDataObjectField();
         $objClass = $gridField->getModelClass();
         /**
          * @var DataObject $obj
          */
         $obj = new $objClass();
         if ($obj->hasField($dbField)) {
             $obj->setCastedField($dbField, $data['gridfieldaddbydbfield'][$obj->ClassName][$dbField]);
             if ($obj->canCreate()) {
                 $id = $gridField->getList()->add($obj);
                 if (!$id) {
                     $gridField->setError(_t('GridFieldAddByDBField.AddFail', 'Unable to save {class} to the database.', 'Unable to add the DataObject.', array('class' => get_class($obj))), 'error');
                 }
             } else {
                 return Security::permissionFailure(Controller::curr(), _t('GridFieldAddByDBField.PermissionFail', 'You don\'t have permission to create a {class}.', 'Unable to add the DataObject.', array('class' => get_class($obj))));
             }
         } else {
             throw new UnexpectedValueException(sprintf('Invalid field (%s) on %s.', $dbField, $obj->ClassName));
         }
     }
     return null;
 }
 /**
  * @param GridField $gridField
  * @param DataObject $record
  * @param string $columnName
  *
  * @return string - the HTML for the column 
  */
 public function getColumnContent($gridField, $record, $columnName)
 {
     // No permission checks, handled through GridFieldDetailForm,
     // which can make the form readonly if no edit permissions are available.
     $data = new ArrayData(array('Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit')));
     return $data->renderWith('GridFieldEditButton');
 }
 /**
  * Gets the classes that can be created using this button, defaulting to the model class and
  * its subclasses.
  *
  * @param GridField $grid
  * @return array a map of class name to title
  */
 public function getClasses(GridField $grid)
 {
     $result = array();
     if (is_null($this->classes)) {
         $classes = array_values(ClassInfo::subclassesFor($grid->getModelClass()));
         sort($classes);
     } else {
         $classes = $this->classes;
     }
     foreach ($classes as $class => $title) {
         if (!is_string($class)) {
             $class = $title;
             if (($reflection = new ReflectionClass($class)) && $reflection->isAbstract()) {
                 continue;
             }
             $title = singleton($class)->i18n_singular_name();
         } else {
             if (($reflection = new ReflectionClass($class)) && $reflection->isAbstract()) {
                 continue;
             }
         }
         if (!singleton($class)->canCreate()) {
             continue;
         }
         $result[$class] = $title;
     }
     return $result;
 }
Example #17
0
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName('Features');
     $fields->removeByName('ExtraContent');
     $regContent = $fields->dataFieldByName('RegistrationContent');
     $afterContent = $fields->dataFieldByName('AfterRegistrationContent');
     $profileContent = $fields->dataFieldByName('ProfileContent');
     $regContent->addExtraClass('no-pagebreak');
     $afterContent->addExtraClass('no-pagebreak');
     $profileContent->addExtraClass('no-pagebreak');
     $fields->insertAfter(TextareaField::create('ApprovalEmailTemplate', 'Approval Email Template'), 'EmailTemplate');
     $fields->insertAfter(TextField::create('ApprovalEmailSubject', 'Approval Email Subject'), 'EmailTemplate');
     $fields->insertAfter(TextareaField::create('ExpiryReminderEmailTemplate', 'Expiry Reminder Email Template'), 'ApprovalEmailTemplate');
     $fields->insertAfter(TextField::create('ExpiryReminderEmailSubject', 'Expiry Reminder Email Subject'), 'ApprovalEmailTemplate');
     $fields->insertAfter(TextareaField::create('ExpiryEmailTemplate', 'Expiry Email Template'), 'ExpiryReminderEmailTemplate');
     $fields->insertAfter(TextField::create('ExpiryEmailSubject', 'Expiry Email Subject'), 'ExpiryReminderEmailTemplate');
     $fields->addFieldToTab('Root.Members', LiteralField::create('MembersNote', '<p class="message"><strong>Note:</strong> This list has been filtered to include current and pending members only. Use the Members admin area for handling expired memberships and non-member website users.</p>'));
     $members = Member::get()->exclude(array('MembershipStatus' => 'Not applied'))->exclude(array('MembershipStatus' => 'Expired'))->sort(array('ExpiryDate' => 'ASC'));
     $gridField = new GridField('Members', 'NZLARP Members', $members, $config = GridFieldConfig_RecordEditor::create());
     $gridField->setModelClass('Member');
     $columns = $config->getComponentByType('GridFieldDataColumns');
     $columns->setFieldFormatting(array('LastEdited' => function ($value, $item) {
         return $item->LastEditedNice();
     }));
     $columns->setDisplayFields(array('getName' => 'Name', 'Region.Title' => 'Region', 'MembershipStatus' => 'Status', 'ExpiryDate' => 'Expires', 'LastEdited' => 'Last Activity'));
     $fields->addFieldToTab('Root.Members', $gridField);
     $config->getComponentByType('GridFieldPaginator')->setItemsPerPage(200);
     return $fields;
 }
 public function testGetManipulatedData()
 {
     $list = new DataList('GridFieldSortableHeaderTest_Team');
     $config = new GridFieldConfig_RecordEditor();
     $gridField = new GridField('testfield', 'testfield', $list, $config);
     // Test normal sorting
     $state = $gridField->State->GridFieldSortableHeader;
     $state->SortColumn = 'City';
     $state->SortDirection = 'asc';
     $compontent = $gridField->getConfig()->getComponentByType('GridFieldSortableHeader');
     $listA = $compontent->getManipulatedData($gridField, $list);
     $state->SortDirection = 'desc';
     $listB = $compontent->getManipulatedData($gridField, $list);
     $this->assertEquals(array('Auckland', 'Cologne', 'Melbourne', 'Wellington'), $listA->column('City'));
     $this->assertEquals(array('Wellington', 'Melbourne', 'Cologne', 'Auckland'), $listB->column('City'));
     // Test one relation 'deep'
     $state->SortColumn = 'Cheerleader.Name';
     $state->SortDirection = 'asc';
     $relationListA = $compontent->getManipulatedData($gridField, $list);
     $state->SortDirection = 'desc';
     $relationListB = $compontent->getManipulatedData($gridField, $list);
     $this->assertEquals(array('Wellington', 'Melbourne', 'Cologne', 'Auckland'), $relationListA->column('City'));
     $this->assertEquals(array('Auckland', 'Cologne', 'Melbourne', 'Wellington'), $relationListB->column('City'));
     // Test two relations 'deep'
     $state->SortColumn = 'Cheerleader.Hat.Colour';
     $state->SortDirection = 'asc';
     $relationListC = $compontent->getManipulatedData($gridField, $list);
     $state->SortDirection = 'desc';
     $relationListD = $compontent->getManipulatedData($gridField, $list);
     $this->assertEquals(array('Cologne', 'Auckland', 'Wellington', 'Melbourne'), $relationListC->column('City'));
     $this->assertEquals(array('Melbourne', 'Wellington', 'Auckland', 'Cologne'), $relationListD->column('City'));
 }
 function updateCMSFields(FieldList $fields)
 {
     $fields->addFieldToTab('Root.MaxCarouselItems', $grid = new GridField('MaxCarouselItems', 'Carousel items', $this->owner->sortedMaxCarouselItems(), GridFieldConfig_RelationEditor::create(10)));
     if (class_exists("GridFieldSortableRows")) {
         $grid->getConfig()->addComponent(new GridFieldSortableRows('SortOrder'));
     }
 }
 /**
  *
  * @param GridField $gridField
  * @param DataObject $record
  * @param string $columnName
  * @return string - the HTML for the column 
  */
 public function getColumnContent($gridField, $record, $columnName)
 {
     $data = new ArrayData(array('Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'refresh')));
     $templatePath = dirname(dirname(__FILE__)) . '/templates/GridFieldRefreshButton.ss';
     $templatePath = str_replace(BASE_PATH, '', $templatePath);
     return $data->renderWith('../' . $templatePath);
 }
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $pictures_per_page = $this->config()->get('picturesPerPage');
     $conf = GridFieldConfig_RelationEditor::create($pictures_per_page);
     $conf->getComponentByType('GridFieldPaginator')->setItemsPerPage($pictures_per_page);
     $conf->addComponent(new GridFieldBulkUpload());
     $conf->addComponent(new GridFieldSortableRows('Sort'));
     $imageFolder = $this->config()->get('imageFolder');
     if ($this->config()->get('usePageURLSegmentAsSubfolder')) {
         $imageFolder = preg_replace("/^(.+?)\\/*\$/", '$1/', $imageFolder) . $this->URLSegment;
     }
     $conf->getComponentByType('GridFieldBulkUpload')->setUfSetup('setFolderName', $imageFolder);
     $gridField = new GridField('Pictures', 'Pictures', $this->SortedPictures(), $conf);
     $dataColumns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
     $imageFieldMapping = $this->config()->get('galleryImageListFieldMapping');
     foreach ($imageFieldMapping as $key => $value) {
         $imageFieldMapping[$key] = _t('GalleryPicture.' . $key, $value);
     }
     $dataColumns->setDisplayFields($imageFieldMapping);
     if ($this->ID > 0) {
         $fields->addFieldsToTab('Root.' . _t('GalleryPage.Photos', 'Photos'), array($gridField));
     }
     return $fields;
 }
	/**
	 * @covers GridFieldDataColumns::getFieldFormatting
	 * @covers GridFieldDataColumns::setFieldFormatting
	 */
	public function testFieldFormatting() {
		$obj = new GridField('testfield', 'testfield');
		$columns = $obj->getConfig()->getComponentByType('GridFieldDataColumns');
		$this->assertEquals(array(), $columns->getFieldFormatting());
		$columns->setFieldFormatting(array("myFieldName" => '<a href=\"custom-admin/$ID\">$ID</a>'));
		$this->assertEquals(array("myFieldName" => '<a href=\"custom-admin/$ID\">$ID</a>'), $columns->getFieldFormatting());
	}
Example #23
0
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->insertBefore(TextareaField::create('Intro', 'Intro'), 'Content');
     $fields->insertAfter(ColorPaletteField::create("Colour", "Colour", array('night' => '#333333', 'air' => '#009EE2', 'earth' => ' #79c608', 'passion' => '#b02635', 'people' => '#de347f', 'inspiration' => '#783980')), "Intro");
     $fields->insertBefore($image = UploadField::create('SplashImage', 'Splash Image'), 'Content');
     $image->setFolderName('Uploads/Splash-Images');
     if ($this->ClassName === "Page" || $this->ClassName === "HomePage") {
         $fields->insertAfter(HTMLEditorField::create('ExtraContent'), 'Content');
         $gridField = new GridField('FeatureItems', 'FeatureItems', $this->FeatureItems()->sort(array('Sort' => 'ASC', 'Archived' => 'ASC')), $config = GridFieldConfig_RelationEditor::create());
         $gridField->setModelClass('FeatureItem');
         $fields->addFieldToTab('Root.Features', $gridField);
         $config->addComponent(new GridFieldOrderableRows());
     } else {
         if ($this->ClassName === "CalendarPage") {
             $content = $fields->dataFieldByName('Content');
             $content->addExtraClass('no-pagebreak');
             $events = Event::get()->sort(array('StartDateTime' => 'Desc'))->filterByCallback(function ($record) {
                 return !$record->getIsPastEvent();
             });
             $gridField = new GridField('Event', 'Upcoming Events', $events, $config = GridFieldConfig_RecordEditor::create());
             $gridField->setModelClass('Event');
             $dataColumns = $config->getComponentByType('GridFieldDataColumns');
             $dataColumns->setDisplayFields(array('Title' => 'Title', 'StartDateTime' => 'Date and Time', 'DatesAndTimeframe' => 'Presentation String'));
             $fields->addFieldToTab('Root.UpcomingEvents', $gridField);
         }
     }
     return $fields;
 }
 /**
  * @return FieldList
  */
 public function getCMSFields()
 {
     $f = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main')));
     $f->addFieldToTab('Root.Main', new TextField('Name', 'Name'));
     $f->addFieldToTab('Root.Main', $ddl = new DropdownField('ListType', 'ListType', $this->dbObject('ListType')->enumValues()));
     $f->addFieldToTab('Root.Main', $ddl2 = new DropdownField('CategoryID', 'Category', PresentationCategory::get()->filter('SummitID', $_REQUEST['SummitID'])->map('ID', 'Title')));
     $ddl->setEmptyString('-- Select List Type --');
     $ddl2->setEmptyString('-- Select Track  --');
     if ($this->ID > 0) {
         $config = GridFieldConfig_RecordEditor::create(25);
         $config->addComponent(new GridFieldAjaxRefresh(1000, false));
         $config->addComponent(new GridFieldPublishSummitEventAction());
         $config->removeComponentsByType('GridFieldDeleteAction');
         $config->removeComponentsByType('GridFieldAddNewButton');
         $config->addComponent($bulk_summit_types = new GridFieldBulkActionAssignSummitTypeSummitEvents());
         $bulk_summit_types->setTitle('Set Summit Types');
         $result = DB::query("SELECT DISTINCT SummitEvent.*, Presentation.*\nFROM SummitEvent\nINNER JOIN Presentation ON Presentation.ID = SummitEvent.ID\nINNER JOIN SummitSelectedPresentation ON SummitSelectedPresentation.PresentationID = Presentation.ID\nINNER JOIN SummitSelectedPresentationList ON SummitSelectedPresentation.SummitSelectedPresentationListID = {$this->ID}\nORDER BY SummitSelectedPresentation.Order ASC\n");
         $presentations = new ArrayList();
         foreach ($result as $row) {
             $presentations->add(new Presentation($row));
         }
         $gridField = new GridField('SummitSelectedPresentations', 'Selected Presentations', $presentations, $config);
         $gridField->setModelClass('Presentation');
         $f->addFieldToTab('Root.Main', $gridField);
     }
     return $f;
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     // Main Content tab
     // Carousel tab
     $carouselItemsGrid = null;
     // Manay to many relations can only be established if we have an id. So put a place holder instead of a grid if this is a new object.
     if ($this->ID == 0) {
         $carouselItemsGrid = TextField::create("CarouselItems", "Carousel Items")->setDisabled(true)->setValue("Page must be saved once before adding Carousel Items.");
     } else {
         $carouselItemsGrid = new GridField('CarouselItems', 'Carousel', $this->CarouselItems()->sort('Archived'), GridFieldConfig_RelationEditor::create());
         $carouselItemsGridUploadComponent = new GridFieldBulkUpload("Image");
         $carouselItemsGridUploadComponent->setUfSetup("setFolderName", $this->ImageFolder("carousel"));
         $carouselItemsGrid->setModelClass('CarouselItem')->getConfig()->addComponent($carouselItemsGridUploadComponent)->addComponent(new GridFieldOrderableRows("SortID"));
     }
     $fields->addFieldToTab('Root.Carousel', $carouselItemsGrid);
     // Links
     $fields->addFieldToTab('Root.Links', new TreeDropdownField('LearnMorePageID', 'Page to link the "Learn More" button to:', 'SiteTree'));
     $fields->addFieldToTab('Root.Links', new TextField('LearnMoreButtonText', 'Text to display on the "Learn More" button:', 'SiteTree'));
     $quickLinksGrid = new GridField('Quicklinks', 'Quicklinks', $this->Quicklinks(), GridFieldConfig_RelationEditor::create());
     $quickLinksGrid->setModelClass('Quicklink');
     $quickLinksFieldGroup = FieldGroup::create($quickLinksGrid)->setTitle('Quick Links');
     $quickLinksFieldGroup->setName("QuicklinkGroup");
     $fields->addFieldToTab('Root.Links', $quickLinksFieldGroup);
     $fields->removeByName('Translations');
     $fields->removeByName('Import');
     $fields->addFieldToTab('Root.Features', ToggleCompositeField::create('FeatureOne', _t('SiteTree.FeatureOne', 'Feature One'), array(new TextField('FeatureOneTitle', 'Title'), new DropdownField('FeatureOneCategory', 'Category', singleton('ExpressHomePage')->dbObject('FeatureOneCategory')->enumValues()), new HTMLEditorField('FeatureOneContent', 'Content'), new TreeDropdownField('FeatureOneLinkID', 'Page to link to', 'SiteTree'), new TextField('FeatureOneButtonText', 'Button text')))->setHeadingLevel(3));
     $fields->addFieldToTab('Root.Features', ToggleCompositeField::create('FeatureTwo', _t('SiteTree.FeatureTwo', 'Feature Two'), array(new TextField('FeatureTwoTitle', 'Title'), new DropdownField('FeatureTwoCategory', 'Category', singleton('ExpressHomePage')->dbObject('FeatureTwoCategory')->enumValues()), new HTMLEditorField('FeatureTwoContent', 'Content'), new TreeDropdownField('FeatureTwoLinkID', 'Page to link to', 'SiteTree'), new TextField('FeatureTwoButtonText', 'Button text')))->setHeadingLevel(3));
     return $fields;
 }
 public function handleSave(GridField $grid, DataObjectInterface $record)
 {
     $list = $grid->getList();
     $value = $grid->Value();
     if (!isset($value[__CLASS__]) || !is_array($value[__CLASS__])) {
         // throw error ?
         return;
     }
     $updatedList = ArrayList::create();
     foreach ($value[__CLASS__] as $id => $v) {
         if (!is_numeric($id)) {
             continue;
         }
         $updatedList->push($id);
     }
     $list->exclude(['ID' => $updatedList->toArray()])->removeAll();
     foreach ($updatedList->toArray() as $i => $id) {
         // if list already contains item, leave it there
         if ($list->byID($id)) {
             continue;
         }
         $gridfieldItem = DataObject::get_by_id($list->dataClass, $id);
         if (!$gridfieldItem || !$gridfieldItem->canEdit()) {
             continue;
         }
         $list->add($gridfieldItem);
     }
 }
 /**
  * Converts a GridField into a read only one.
  *
  * @param GridField $gridField GridField to convert
  * 
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 08.03.2013
  */
 public static function convertToReadonly(GridField $gridField)
 {
     $gridFieldConfig = $gridField->getConfig();
     $gridFieldConfig->removeComponentsByType('GridFieldEditButton');
     $gridFieldConfig->removeComponentsByType('GridFieldDeleteAction');
     $gridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
     $gridFieldConfig->removeComponentsByType('GridFieldAddExistingAutocompleter');
 }
 /**
  * Retrieves an instance of a GridFieldPaginator attached to the same control
  * @param GridField $gridField The parent gridfield
  * @return GridFieldPaginator The attached GridFieldPaginator, if found.
  * @throws LogicException
  */
 protected function getPaginator($gridField)
 {
     $paginator = $gridField->getConfig()->getComponentByType('GridFieldPaginator');
     if (!$paginator && Config::inst()->get('GridFieldPageCount', 'require_paginator')) {
         throw new LogicException(get_class($this) . " relies on a GridFieldPaginator to be added " . "to the same GridField, but none are present.");
     }
     return $paginator;
 }
Example #29
0
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $gridField = new GridField('CarouselItems', 'Carousel', $this->CarouselItems(), GridFieldConfig_RelationEditor::create());
     $gridField->setModelClass('CarouselItem');
     $fields->addFieldToTab('Root.Carousel', $gridField);
     return $fields;
 }
 /**
  *
  * @param GridField $gridField
  * @param DataObject $record
  * @param string $columnName
  * @return string - the HTML for the column 
  */
 public function getColumnContent($gridField, $record, $columnName)
 {
     if (!$record->canEdit()) {
         return;
     }
     $data = new ArrayData(array('Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit')));
     return $data->renderWith('GridFieldEditButton');
 }