2017 © Pedro Peláez
 

silverstripe-vendormodule hasoneedit

Allows editing the fields of a has_one object directly in the CMS

image

stevie-mayhew/hasoneedit

Allows editing the fields of a has_one object directly in the CMS

  • Monday, July 16, 2018
  • by stevie-mayhew
  • Repository
  • 4 Watchers
  • 16 Stars
  • 1,426 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 5 Open issues
  • 7 Versions
  • 9 % Grown

The README.md

Has One Edit

This module allows you to directly edit the fields of a related has_one object directly, without having to mess around with GridField or links to ModelAdmin. If the related has_one doesn't exist yet, then this module also creates the object and sets up the relation for you on first write., (*1)

This module has been tested editing a has_one in both a GridFieldDetailForm and on a generic Page in CMSMain., (*2)

Requirements

SilverStripe 4.x., (*3)

Basic testing has been carried out on 4.0.x-dev. Extensive testing may be required as SS4 becomes more solid., (*4)

Usage

To use this module, simply add a field to the CMS fields for your object in your getCMSFields() method. The name of the field should be HasOneName-_1_-FieldName., (*5)

For example, say you have a has_one called Show and that has_one has a field called Title you want to edit. You'd add the field TextField::create('Show-_1_-Title', 'Show Title')., (*6)

If you do not require that the outputted name of the field matches the value you supply, you can also use a colon as a separator instead of -_1_-., (*7)

Generating fields with the ProvidesHasOneInlineFields trait

If you simply want to display all the CMS fields for a related object, you can add the ProvidesHasOneInlineFields trait to the object. This adds a method which calls getCMSFields() on your DataObject and return the FormFields for that object. Those FormFields will be converted for use with this module by adding the relation name and separator to their name., (*8)

In the owning object, where you want to display the fields, call HasOneEdit::getInlineFields($this, 'my_has_one_name', ['db']). This will return the db subset of fields for adding to the CMS - e.g. you can display the related object's fields in their own tab by calling $fields->addFieldsToTab('Root.RelatedObject', HasOneEdit::getInlineFields($this, 'Relation', ['db']))., (*9)

This has the advantage of running the entire getCMSFields() call tree (e.g. updateCMSFields for any functionality provided via extension) etc. without having to repeat logic in a lot of places., (*10)

You can also implement a method public function provideHasOneInlineFields($relationName) returning FieldList|FormField[] to provide a custom interface different to getCMSFields() (e.g. just a small subset of fields). In this case, all the field names should be in the form $relationName . HasOneEdit::FIELD_SEPARATOR . $dataObjectFieldName. This method will be called by HasOneEdit::getInlineFields even if your class does not use the ProvidesHasOneInlineFields trait., (*11)

Using with your own form

To add support to your own forms, you need to add the SGN\HasOneEdit\UpdateFormExtension extension to your controller and call $this->extend('updateEditForm', $form) before returning the form to the template. Without this, the fields will not get populated with the values from the has_one though saving will work., (*12)

The Versions

16/07 2018

dev-master

9999999-dev

Allows editing the fields of a has_one object directly in the CMS

  Sources   Download

WTFPL

The Requires

 

cms silverstripe has_one

16/07 2018

2.0.0

2.0.0.0

Allows editing the fields of a has_one object directly in the CMS

  Sources   Download

WTFPL

The Requires

 

cms silverstripe has_one

11/04 2018

1.0.7

1.0.7.0

Allows editing the fields of a has_one object directly in the CMS

  Sources   Download

WTFPL

The Requires

 

cms silverstripe has_one

21/03 2017

3.x-dev

3.9999999.9999999.9999999-dev

Allows editing the fields of a has_one object directly in the CMS

  Sources   Download

WTFPL

The Requires

 

cms silverstripe has_one

21/03 2017

1.0.6

1.0.6.0

Allows editing the fields of a has_one object directly in the CMS

  Sources   Download

WTFPL

The Requires

 

cms silverstripe has_one

17/12 2015

1.0.5

1.0.5.0

Allows editing the fields of a has_one object directly in the CMS

  Sources   Download

WTFPL

The Requires

 

cms silverstripe has_one

04/08 2015

1.0.4

1.0.4.0

Allows editing the fields of a has_one object directly in the CMS

  Sources   Download

WTFPL

The Requires

 

cms silverstripe has_one