taoceanz

But very cool to see it implemented at any rate. Thanks @andante

taoceanz

Ah yep there it is. I think it would be better if you could click anywhere on the #modal. Someone flooded with adrenaline needs a big target.

taoceanz

Should be able to close the overlay by clicking anywhere off the main content and or, if there was an x but very cool to see it on the site. It's not possible to close the overlay unless you reload the site. I'd imagine if I was in danger and had to pull the Shielded Site up, I'd want to to be able to close asap if someone threatening me was near.

taoceanz

I've got an model that has a field specified as a unique index and when you try to save an object of that model type with an index that exists, it throws an error. That seems pretty normal. What's the best way to validate the index field to make sure the proposed value to save doesn't exist so I can display a warning message to inform the CMS user that they need to enter a unique value?

taoceanz

Is there any way to make a $db record unique? I'm thinking it's along the lines of $indexes...

taoceanz

How can I specify the upload folder for the image on the Benefits object? When clicking into the Benefits admin area, form fields are populated without the need for getCMSFields so not sure how to access the Image field to set the folder name...

  1. class BenefitsAdmin extends ModelAdmin
  2. {
  3. private static $managed_models = [
  4. 'Benefits',
  5. ];
  6. }
  1. class Benefits extends DataObject
  2. {
  3. private static $db = [
  4. 'Title' => 'Varchar(255)',
  5. ];
  6. private static $has_one = [
  7. 'Image' => 'Image'
  8. ];
  9. }
taoceanz

Oh, dataFieldByName... I was using fieldByName as it was noted here: https://docs.silverstripe.org/en/3.0/reference/dataobject/#scaffolding-form-fields

But awesome, @Ed Linklater, that worked and the upload folder is set correctly. Thank you.

taoceanz

Thanks @nightjarnz I had basically what Ed put (with the exception of fieldByName instead of dataFieldByName) and was getting an error stating I couldn't add a folder to null but I think I may have forgotten to return $fields in getCMSFields from focusing too much on getting a reference to an existing field. Thanks for the clarification on the difference between the two methods, though.

taoceanz

Ok @nightjarnz no just commented out 'return $fields' and that gives a different error. 'Uncaught Error: Call to a member function setFolderName() on null' is returned from the following code:

  1. $fields = parent::getCMSFields();
  2. $fields->fieldByName('Image')->setFolderName('folder');
  3. return $fields;

where as the code works successfully when fieldByName is changed to dataFieldByName

  1. $fields = parent::getCMSFields();
  2. $fields->dataFieldByName('Image')->setFolderName('folder');
  3. return $fields;
nightjarnz

sometimes giving the full tabbed name helps e.g. Root.Main.Image

taoceanz

Ah bingo @nightjarnz, there you go. Full tabbed name got it. That's a nice gold nugget for the knowledge bank.

taoceanz

I suppose it makes sense. If fieldByName is searching anything field related, it would be looking for Image in the Root space, which it shouldn't find. Then dataFieldByName I'm assuming would be looking at all fields from the same level so Image would be at the same nest level as any other dataField. Just what it seems like it could be doing without looking at the API so I could be wildly off with that.

taoceanz

If that's correct, I'm guessing dataFieldByName might run into some issues if there was Root.Main.Image and Root.Secondary.Image.

nightjarnz

can't have two fields named the same on the same form anyway. ¯_(ツ)_/¯


Show less replies
taoceanz

Ok thanks @nightjarnz that's what I had thought was going to be the next step. The original purpose was to pass an array containing values from a shortcode to an includes file to specify which sections of that includes file would display without having to create a data object to store the individual sections.

But ok, I was just being lazy and trying to make it work an easy way. Thanks for the heads up. I'll create the datatype, generate the loopable object in the controller and pass that to the view to be rendered. Will make content admin easier in the future too.

taoceanz

Is it possible to use PHP functions in a .ss file? I'm rendering a view file and passing an array of data but want to check whether certain values exist within the array before displaying a section in that view file. I thought using in_array() or isset() would be sufficient but it's behaving like the function isn't being run.

taoceanz

Good to see another SilverStripe Akl meet up planned.

🙂 (1)