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 field on $has_many relation #28

Closed
dacar opened this issue Feb 10, 2013 · 3 comments
Closed

SortOrder field on $has_many relation #28

dacar opened this issue Feb 10, 2013 · 3 comments

Comments

@dacar
Copy link

dacar commented Feb 10, 2013

sort_order
Hi, if i use a has_many relation, than there will always be the editable "SortOrder" field on create a new item or on editing an existing. How can i get rid of it?

page.php

static $has_many = array(
    'Zusatzinfos' => 'Zusatzinfos'
);

[...]

// optionale Zuordnung von Zusatzinformationen (Accordeon) je Seite
    $zusatzinfosFieldConfig = GridFieldConfig::create()->addComponents(
      new GridFieldToolbarHeader(),
      new GridFieldAddNewButton('toolbar-header-right'),
      new GridFieldSortableHeader(),
      new GridFieldDataColumns(),
      new GridFieldPaginator(10),
      new GridFieldEditButton(),
      new GridFieldDeleteAction(),
      new GridFieldDetailForm(),
      new GridFieldDeleteAction('unlinkrelation'),
      new GridFieldSortableRows('SortOrder')
    );

    $ZusatzinfosField = new GridField("Zusatzinfos", "Zusatzinfos:", $this->Zusatzinfos()->sort('SortOrder'), $zusatzinfosFieldConfig);
    $fields->addFieldToTab('Root.Zusatzinfos', $ZusatzinfosField);

zusatzinfos.php

static $db = array (
    'Headline' => 'Varchar(100)',
    'InfoText' => 'HTMLText',
    'SortOrder'=>'Int'
);

public function getCMSFields_forPopup() {

$InfoTextBildField = new UploadField(
    $name = 'Bild',
    $Title = 'Bild (px * px)'
);
$InfoTextBildField->allowedExtensions = array('jpg', 'png', 'gif');
$InfoTextBildField->setConfig('allowedMaxFileNumber', 5);
$InfoTextBildField->setFolderName('Infotextbilder');
$InfoTextBildField->setConfig('previewMaxWidth', 100);
$InfoTextBildField->setConfig('previewMaxHeight', 100); 
$InfoTextBildField->setConfig('autoUpload', true);
return new FieldList(
  $InfoTextBildField,
  new TextField('Headline', 'Headline'),
  new TextareaField('InfoText', 'Text'),
  new TreeDropdownField('PagelinkID', 'Bitte eine interne Verlinkung wählen', 'SiteTree', 'ID', 'Title', true)
);

}

Thanks for your advice, Carsten.

@UndefinedOffset
Copy link
Owner

Carsten,
You need to override getCMSFields on your data object and remove the field or define your own list of fields. I'm guessing that you do not have a getCMSFields on that object. If your not sure how to do this check the SilverStripe docs or I can post a quick snippet later today.

@UndefinedOffset
Copy link
Owner

Second thought (now that i can actually read the snippets you posted, stupid GitHub Issues app on ios). Try renaming your getCMSFields_forPopup() to getCMSFields(), that should fix things ;). SilverStripe 3.0 does not use getCMSFields_forPopup.

@dacar
Copy link
Author

dacar commented Feb 10, 2013

Oh, didn't noticed that. Thanks a lot for the module and for your help! Greetings, Carsten.

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

2 participants