Skip to content

Commit

Permalink
fix(versioned-relations): add compatibility for 0.1.9;
Browse files Browse the repository at this point in the history
fix(gridfield): cleanup columns, enable html formatted preview
  • Loading branch information
flxqr2 committed Jan 30, 2018
1 parent e010626 commit c5b073d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions code/GridFieldPageSectionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function getColumnContent($gridField, $record, $columnName) {

return ViewableData::create()->customise(array(
"ButtonField" => $field,
"Title" => $record->Title,
"Title" => $record->i18n_singular_name(),
))->renderWith("GridFieldPageElement");
}

Expand All @@ -173,7 +173,7 @@ public function getColumnContent($gridField, $record, $columnName) {
$temp = $record;
while ($temp->_Parent) {
$temp = $temp->_Parent;
$link = Controller::join_links("item", $temp->ID,
$link = Controller::join_links("item", $temp->ID,
"ItemEditForm", "field", "Children", $link
);
}
Expand Down
28 changes: 21 additions & 7 deletions code/PageElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ function canCreate($member = null) { return true; }
);

public static $summary_fields = array(
'SingularName',
'ID',
'GridFieldPreview',
);

Expand All @@ -56,7 +54,7 @@ public function onBeforeWrite() {
$list = $this->Children()->Sort("SortOrder")->toArray();
$count = count($list);

for ($i = 1; $i <= $count; $i++) {
for ($i = 1; $i <= $count; $i++) {
$this->Children()->Add($list[$i - 1], array("SortOrder" => $i * 2));
}
}
Expand All @@ -77,12 +75,13 @@ public function getChildrenGridField() {
->addComponent($addNewButton)
->addComponent(new GridFieldPageSectionsExtension($this->owner))
->addComponent(new GridFieldDetailForm());

$dataColumns->setFieldCasting(array('GridFieldPreview' => 'HTMLText->RAW'));

return new GridField("Children", "Children", $this->Children(), $config);
}

public function getGridFieldPreview() {
return null;
return $this->Title;
}

public function getCMSFields() {
Expand All @@ -97,7 +96,7 @@ public function getCMSFields() {

return $fields;
}

public function getParentIDs() {
$IDArr = array($this->ID);
foreach($this->Parents() as $parent) {
Expand All @@ -117,7 +116,7 @@ public function forTemplate($parentList = "") {
$parents = ArrayList::create();
$splits = explode(",", $parentList);
$num = count($splits);
for ($i = 0; $i < $num - 1; $i++) {
for ($i = 0; $i < $num - 1; $i++) {
$parents->add(PageElement::get()->byID($splits[$i]));
}
$page = SiteTree::get()->byID($splits[$num - 1]);
Expand All @@ -127,4 +126,19 @@ public function forTemplate($parentList = "") {
array("ParentList" => $parentList, "Parents" => $parents, "Page" => $page)
);
}

public function getBetterButtonsUtils() {
$fieldList = FieldList::create(array(
BetterButtonPrevNextAction::create(),
));
return $fieldList;
}

public function getBetterButtonsActions() {
$fieldList = FieldList::create(array(
BetterButton_SaveAndClose::create(),
BetterButton_Save::create(),
));
return $fieldList;
}
}
12 changes: 7 additions & 5 deletions code/PageSectionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function extraStatics($class = null, $extensionClass = null) {
Config::inst()->update($class, "many_many_extraFields", $many_many_extraFields);
return array();
}

public static function getAllowedPageElements() {
$classes = array_values(ClassInfo::subclassesFor("PageElement"));
$classes = array_diff($classes, ["PageElement"]);
Expand All @@ -44,12 +44,12 @@ public function onBeforeWrite() {
$list = $this->owner->$name()->Sort("SortOrder")->toArray();
$count = count($list);

for ($i = 1; $i <= $count; $i++) {
for ($i = 1; $i <= $count; $i++) {
$this->owner->$name()->Add($list[$i - 1], array("SortOrder" => $i * 2));
}
}
}

public function updateCMSFields(FieldList $fields) {
$sections = $this->owner->config()->get("page_sections");
if (!$sections) $sections = array("Main");
Expand All @@ -58,7 +58,7 @@ public function updateCMSFields(FieldList $fields) {
$name = "PageSection".$section;

$fields->removeByName($name);

if ($this->owner->ID) {
$addNewButton = new GridFieldAddNewMultiClass();
$addNewButton->setClasses($this->owner->getAllowedPageElements());
Expand All @@ -74,6 +74,8 @@ public function updateCMSFields(FieldList $fields) {
->addComponent($addNewButton)
->addComponent(new GridFieldPageSectionsExtension($this->owner))
->addComponent(new GridFieldDetailForm());
$dataColumns = $config->getComponentByType('GridFieldDataColumns');
$dataColumns->setFieldCasting(array('GridFieldPreview' => 'HTMLText->RAW'));

$f = new GridField($name, $section, $this->owner->$name(), $config);
$fields->addFieldToTab("Root.PageSections", $f);
Expand All @@ -82,7 +84,7 @@ public function updateCMSFields(FieldList $fields) {
}

public function PageSection($name = "Main") {
$elements = $this->owner->getVersionedRelation("PageSection" . $name);
$elements = $this->owner->{"PageSection" . $name}();
return $this->owner->renderWith(
"RenderChildren",
array("Elements" => $elements, "ParentList" => strval($this->owner->ID))
Expand Down

0 comments on commit c5b073d

Please sign in to comment.