Skip to content

Instantly share code, notes, and snippets.

@gordonbanderson
Last active December 15, 2015 17:29
Show Gist options
  • Save gordonbanderson/5297295 to your computer and use it in GitHub Desktop.
Save gordonbanderson/5297295 to your computer and use it in GitHub Desktop.
Adding multiple maps to a page using Mappable for SilverStripe 3
Object::add_extension('ContactPageAddress','MapExtension');
<?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 {
}
?>
<% require css(weboftalent-mappable-demo/css/mapdemo.css) %>
<h1>$Title</h1>
$BriefDescription
<h2>Addresses</h2>
<% loop Locations %>
<h3>$PostalAddress</h3>
$BasicMap
<% end_loop %>
$Content
<?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