elliot-sawyer / silverstripe-linkfield

Adds a Linkfield for gorriecoe/silverstripe-link
BSD 3-Clause "New" or "Revised" License
9 stars 25 forks source link

Many_Many_Extrafields error #3

Closed Greg808 closed 6 years ago

Greg808 commented 6 years ago

I use your module with silverstripe 4.2.1, elemental 3.0.0. After i installed the module and ran dev/build/?flush i get this error message: [Emergency] Uncaught Exception: Couldn't find the sort field 'Sort' when i create a new element. This is my code

    private static $many_many = [
        'MainElementLinks' => Link::class
    ];

    private static $many_many_extraFields = [
        'MainElementLinks' => [
            'Sort' => 'Int'
        ]
    ];

  $fields = parent::getCMSFields();

        $extraClass = $fields->dataFieldByName('ExtraClass')->setTitle('Extra Css Class');

        $fields->removeByName(['FileTracking', 'LinkTracking', 'Links' ,'Settings']);

        /** @var GridField $linkField */
        $fields->addFieldsToTab('Root.Main', [
                $extraClass,
                LinkField::create(
                    'MainElementLinks',
                    'MainElementLinks',
                    $this
                )
            ]
        );

     return $fields;

I set the relations in a yml file like:

gorriecoe\Link\Models\Link:
  belongs_many_many:
    MainElements : ZimetPage\Elements\MainElement

If built a work around:

   if (!$this->exists()) {
            $fields->addFieldsToTab('Root.Main', [
                    LiteralField::create('HelperText', _t('ZimetPage\Elements\MainElement.HelperText', 'Please create element to add links'))

                ]
            );
        }

        if ($this->exists()) {
            $fields->addFieldsToTab('Root.Main', [
                LinkField::create(
                    'MainElementLinks',
                    'MainElementLinks',
                    $this
                )
            ]);
        }

The problem is GridFieldOrderableRows does not work with unsaved relationlist. Now that it works i think there is also an error with the css.

bildschirmfoto 2018-09-19 um 13 02 00

or is the red intended?

If you need more information or i can be helpful in any other way just let me know.

gorriecoe commented 6 years ago

Hey @Greg808, thanks for reporting this. I have made a few changes to linkfield that might help. First, I have removed the debug styles causing the red bar. Second, I have added an option to define your own sort column. https://github.com/gorriecoe/silverstripe-linkfield#sort-column. I suspect if you change the default sort column to sortorder or something else it might work.

Let me know if those fixes help. If not, I'll add documentation about the belongs many many rule you mention.

Cheers

Greg808 commented 6 years ago

Hey @gorriecoe, sorry for the late response the fixes helped thank you.