Last active
December 15, 2015 17:29
-
-
Save gordonbanderson/5297295 to your computer and use it in GitHub Desktop.
Adding multiple maps to a page using Mappable for SilverStripe 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object::add_extension('ContactPageAddress','MapExtension'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ContactPage extends DemoPage { | |
static $has_many = array( | |
'Locations' => 'ContactPageAddress' | |
); | |
function getCMSFields() { | |
$fields = parent::getCMSFields(); | |
$gridConfig = GridFieldConfig_RelationEditor::create(); | |
$gridConfig->getComponentByType( 'GridFieldAddExistingAutocompleter' )->setSearchFields( array( 'PostalAddress' ) ); | |
$gridConfig->getComponentByType( 'GridFieldPaginator' )->setItemsPerPage( 100 ); | |
$gridField = new GridField( "Locations", "List of Addresses:", $this->Locations(), $gridConfig ); | |
$fields->addFieldToTab( "Root.Addresses", $gridField ); | |
return $fields; | |
} | |
} | |
class ContactPage_Controller extends Page_Controller { | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% require css(weboftalent-mappable-demo/css/mapdemo.css) %> | |
<h1>$Title</h1> | |
$BriefDescription | |
<h2>Addresses</h2> | |
<% loop Locations %> | |
<h3>$PostalAddress</h3> | |
$BasicMap | |
<% end_loop %> | |
$Content |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ContactPageAddress extends DataObject { | |
static $db = array( | |
'PostalAddress' => 'Text' | |
); | |
static $has_one = array( 'ContactPage' => 'ContactPage' ); | |
public static $summary_fields = array( | |
'PostalAddress' => 'PostalAddress' | |
); | |
function getCMSFields() { | |
$fields = new FieldList(); | |
$fields->push( new TabSet( "Root", $mainTab = new Tab( "Main" ) ) ); | |
$mainTab->setTitle( _t( 'SiteTree.TABMAIN', "Main" ) ); | |
$fields->addFieldToTab( "Root.Main", new TextField( 'PostalAddress' ) ); | |
$this->extend( 'updateCMSFields', $fields ); | |
return $fields; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment