Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SortOrder column missing #182

Open
streamflyer opened this issue Mar 9, 2023 · 5 comments
Open

SortOrder column missing #182

streamflyer opened this issue Mar 9, 2023 · 5 comments

Comments

@streamflyer
Copy link

After installing the module, upon creating the Member Profile Page, whenever I want to open the page I get this error message:

[2023-03-09 15:18:55] error-log.WARNING: E_WARNING: Undefined array key "SortOrder" {"code":2,"message":"Undefined array key "SortOrder"","file":"/home/jsgrueni/www/podcastschmiede/live/vendor/undefinedoffset/sortablegridfield/src/Forms/GridFieldSortableRows.php","line":233} []

Can anybody help me fix this? I'm using SS 4.12, installed the module via composer.

@streamflyer
Copy link
Author

I tried adding a SortOrder column to the MemberProfileClass, but nothing changed.

@nyeholt
Copy link
Contributor

nyeholt commented Mar 17, 2023

Hi @streamflyer - what other modules or extensions do you have installed? In a base installation with memberprofiles and sortablegridfield installed I don't have any issue. The "Sort" being used is referenced in MemberProfilePage ~line 255, where it references the "Sort" field on the MemberProfileField objects. It sounds like you may have a different module/extension in place that's conflicting?

@streamflyer
Copy link
Author

Hi @nyeholt . I work with the following requirements:

"require": {
        "php": "^7.1 || ^8",
        "silverstripe/recipe-plugin": "^1.2",
        "silverstripe/recipe-cms": "~4.12@stable",
        "silverstripe-themes/simple": "^3.2",
        "silverstripe/login-forms": "^4.8@stable",
        "silverstripe/blog": "^3.11",
        "arillo/silverstripe-metatags": "^2.1",
        "undefinedoffset/sortablegridfield": "^2.1",
        "wilr/silverstripe-googlesitemaps": "^2.2",
        "tractorcow/silverstripe-sliderfield": "^4.0",
        "silverstripe/asset-admin": "^1.11",
        "i-lateral/silverstripe-gallery": "^2.2",
        "symbiote/silverstripe-memberprofiles": "~4.0",
        "symbiote/silverstripe-gridfieldextensions": "^3.5",
    }

I've uninstalled all non-essential modules and just reinstalled sortablegridfield and memberprofiles. Now I've narrowed the error down to one line of code:

Every Page of mine has_many Sections. And these sections are sortable. So on Page.php I have this code:

public function getCMSFields() 
        {
        $fields = parent::getCMSFields();

        $conf = GridFieldConfig_RelationEditor::create(10);
        $conf->addComponent(GridFieldSortableRows::create('SortOrder'));

        $fields->addFieldToTab(
            'Root.Main',
            GridField::create(
                'Sections',
                'Sections',
                $this->Sections(),
                $conf
            )
        );

return $fields;
}

Now, when I comment out the line "$conf->addComponent(GridFieldSortableRows::create('SortOrder'));", your extensions works. But my sections are not sortable anymore.
I tried renaming the SortOrder field on my Sections to rule out a naming conflict - doesn't work.

Any ideas? ;-)

Thanks,
Nico

@michalkleiner
Copy link

Can you post the code for the Section DO, @streamflyer? Does it have a $db field SortOrder?

@streamflyer
Copy link
Author

Sure, @michalkleiner , this is the Section Model:

`<?php

namespace Streamflyer\Section;

use Page;
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;
use SilverStripe\Versioned\Versioned;
use Streamflyer\Section\SectionIconParagraph;

use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;

class Section extends DataObject
{
private static $extensions = [
Versioned::class
];

private static $db = [
    'Title' => 'Varchar',
    'Content' => 'HTMLText',
    'SortOrder' => 'Int',
    'Type' => "Enum(array('Default','ImageHalfLeft','ImageHalfRight','IconParagraphs'), 'Default')",
    'Style' => "Enum(array('Default','Dark','White','Accent','Light'), 'Default')",
    'ShowInLinkBar' => 'Boolean',
    'ImageLink' => 'Varchar',
    'ImageWidth' => 'Varchar'
];

private static $indexes = [
    'SortOrder' => true,
];

private static $has_one = [
    'Page' => Page::class,
    'Image' => Image::class
];

private static $has_many = [
    'IconParagraphs' => SectionIconParagraph::class
];

private static $owns = [
    'Image'
    //Adding this will make sure the image is published with the page.
];

private static $default_sort = 'SortOrder';
private static $singular_name = 'Sektion';
private static $plural_name = 'Sektionen';
private static $description = 'Abschnitt einer Seite';
private static $table_name = 'streamflyer_section_section';

// Summary fields
private static $summary_fields = [
    'Title' => 'Titel',
    'Type' => 'Typ',
    'Style' => 'Farbstil'
];

public function getCMSFields()
{
    //Konfiguration für Bild
    $image = UploadField::create('Image', 'Bild');
    $image->setFolderName('Images');
    
    //Konfiguration für IconParagraph
    $conf = GridFieldConfig_RelationEditor::create(10);
    $conf->addComponent(new GridFieldSortableRows('SortOrder'));
    
    $fields = FieldList::create(
        TextField::create('Title', 'Titel'),
        CheckboxField::create('ShowInLinkBar', 'Text am Start der Seite als Link anzeigen.'),
        HTMLEditorField::create('Content', 'Inhalt'),
        DropdownField::create('Type', 'Typ', $this->dbObject('Type')->enumValues()),
        DropdownField::create('Style', 'Farbstil', $this->dbObject('Style')->enumValues()),
        $image,
        TextField::create('ImageLink', 'Bild-Link'),
        TextField::create('ImageWidth', 'max. Bild-Breite, z.B. "200px" oder "50%"'),
        GridField::create(
            'IconParagraphs',
            'Icon-Abschnitte',
            $this->IconParagraphs(),
            $conf
        )
    );
    
    return $fields;
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants