0

Can I have 2 gridfield components in an admin page named differently from the same dataobject - eg

   class MainLandingPage_au extends Page
   {

    private static $has_many = [
       'ImagesWithHtml' => ImageWithHtml::class,
       'ImagesWithHtml2' => ImageWithHtml::class,
    ];

    // ...
    $fields->addFieldToTab('Root.Section1', HtmlEditorField::create('Section1Title','Section 1 Title')->setRows(4));
    $fields->addFieldToTab('Root.Section1', GridField::create(
        'ImagesWithHtml',
        'Images With Html For This Page',
        $this->ImagesWithHtml(),
        GridFieldConfig_RecordEditor::create()
    ));

    $fields->addFieldToTab('Root.Section2', HtmlEditorField::create('Section2Title','Section 2 Title')->setRows(4));
    $fields->addFieldToTab('Root.Section2', GridField::create(
        'ImagesWithHtml2',
        'Images With Html For Section 2',
        $this->ImagesWithHtml2(),
        GridFieldConfig_RecordEditor::create()
    ));
user3257693
  • 486
  • 3
  • 14

2 Answers2

0

Did you try it? As you have different relations it should work in general. Of course you need the corresponding has_one relationss on the ImageWithHTML class, see https://docs.silverstripe.org/en/4/developer_guides/model/relations/#has-many

So your code should be something like:

   class MainLandingPage_au extends Page
   {

    private static $has_many = [
       'ImagesWithHtml' => `\Namespace\Of\ImageWithHtml.Foo`,
       'ImagesWithHtml2' => `\Namespace\Of\ImageWithHtml.Bar`
    ];

and on the other side

   class ImageWithHtml extends DataObject
   {

    private static $has_one = [
       'Foo' => MainLandingPage_au::class,
       'Bar' => MainLandingPage_au::class
    ];
wmk
  • 4,598
  • 1
  • 20
  • 37
0

Yes can use 2 gridfields this worked for the proper individual relations

class MainLandingPage_au extends Page
   {

    private static $has_many = [
       'ImagesWithHtml' => ImageWithHtml::class . '.AuMainLandingPage',
       'ImagesWithHtml2' => ImageWithHtml::class . '.AuMainLandingPage2'
    ];

    // ...
    // Gridfields as in posted question
    // ... etc

Other side

class ImageWithHtml extends DataObject
    {

    private static $has_one = [
       'AuMainLandingPage' => AuMainLandingPage::class . '.ImagesWithHtml',
       'AuMainLandingPage2' => AuMainLandingPage::class . '.ImagesWithHtml2'
    ];
user3257693
  • 486
  • 3
  • 14