SilverStripe MultiForm not working - php

I installed and configured SilverStripe on my server. I installed the MultiForm module and followed the instructions in the module documentation.
After following the instructions I still don't see any new page type in my CMS Portal.
I also tried db/build?flush=1 & dev/build?flush=1 but it doesn't make a difference.
I Created the Following files in mysite/code/ directory
SponsorSignupForms.php
class SponsorSignupForms extends MultiForm{
protected static $start_step = 'CompanyDetailsStep';
}
CompanyDetailsStep.php
class CompanyDetailsStep extends MultiFormStep{
public static $next_steps = 'ContactDetailsStep';
function getFields()
{
$fields = singleton('Member')->getFrontendFields();
return $fields;
}
function getValidator()
{
return new Member_Validator('FirstName', 'Surname', 'Email', 'Password');
}
}
ContactDetailsStep.php
class ContactDetailsStep extends MultiFormStep{
public static $is_final_step = true;
function getFields()
{
$fields = singleton('Reference')->getFrontendFields();
return $fields;
}
}
How do I get these custom MultiForms working and appearing as creatable pages?

Of course you don't see any new page type in the list of available pages, you will only see subclasses of SiteTree there, MultiFormStep is "just" a subclass of DataObject.
You can plug your form to every page you want manually, but you also can create a new page type for your form and include the Form in your Controller and Template, see readme of MultiForm:
class MyFormPage extends Page
{
}
class MyFormPageController extends Page_Controller
{
//
private static $allowed_actions = array(
'SponsorSignupForms',
'finished'
);
public function SponsorSignupForms() {
return new SponsorSignupForms($this, 'Form');
}
public function finished() {
return array(
'Title' => 'Thank you for your submission',
'Content' => '<p>You have successfully submitted the form!</p>'
);
}
}
In the template just include the form:
<% if $SponsorSignupForms %>
$SponsorSignupForms
<% end_if %>
and you should see the form now.

Related

My SilverStripe module overrides other modules display

I'm writing a subscribe module to plugin to the SilverStripe Blog module. So far I have my yml as:
---
Name: subscription
After: 'framework/*','cms/*'
---
Blog:
extensions:
- Subscription
Page_Controller:
extensions:
- SubscriptionWidget
And my SubscriptionWidget.php:
<?php
class SubscriptionWidget extends DataExtension {
public function SubscriptionWidget() {
$controller = SubscriptionWidget_Controller::create();
$form = $controller->SubscriptionWidget();
return $form;
}
}
class SubscriptionWidget_Controller extends Controller {
private static $allowed_actions = array('SubscriptionWidget');
public function SubscriptionWidget () {
$form = Form::create(
$this,
__FUNCTION__,
FieldList::create(
TextField::create('Email', 'Email'),
TextField::create('Name', 'Name')
),
FieldList::create(
FormAction::create('submit', 'Subscribe')
)
);//->setTemplate('SubscriptionWidget');
return $form;
}
public function submit($data, $form) {
return $this->redirect('/subscribed');
}
}
At the moment this works as intended however another plugin I use called BetterNavigator disappears from the screen. If I take out
Page_Controller:
extensions:
- SubscriptionWidget
from my yml it reappears. I've looked through both code bases which are quite simple and there are no conflicting functions. I've also tried using ContentController instead of Page_Controller and my template disappears until I disable BetterNavigator and then it reappears. I do have one or two pretty empty classes but all are called some variation of Subscriber while there is only one function in BetterNavigator called BetterNavigator.
Why would this be happening?
I see only one clash in your code that results in incorrect runtime behaviour. Your method SubscriptionWidget::SubscriptionWidget() is treated as legacy class constructor. So I suggest you thinking about better class and method names.
class SubscriptionWidget extends Extension
{
// explicitly defined constructor
public function __construct() {
parent::__construct();
}
// now this one is normal function
public function SubscriptionWidget() {
$controller = SubscriptionWidget_Controller::create();
$form = $controller->SubscriptionWidget();
return $form;
}
}

SilverStripe 3.1+ Dynamically creating page redirects

I have a page type 'ProductPage', it has tabs that are navigated to like so:
/ProductPageUrlSegment/?tab=video
/ProductPageUrlSegment/?tab=audio
/ProductPageUrlSegment/?tab=photos
I'd like for redirects to be created when each new product page is created so that if you navigated /ProductPageUrlSegment/video it goes to /ProductPageUrlSegment/?tab=video
and the same for all tabs. I'm not clear if I should be using Routing https://docs.silverstripe.org/en/3.3/developer_guides/controllers/routing/ or redirection https://docs.silverstripe.org/en/3.3/developer_guides/controllers/redirection/
I have a link function for another project which goes to the parent page
public function Link() {
return $this->Parent()->Link() . '#' . $this->URLSegment;
}
Mine would be something like:
public function LinkVideo() {
return $this->Link()->'/?=video' . '#' . $this->URLSegment->'/video';
}
I don't have the knowledge to work this out so any guidance appreciated.
This will achieve the above, by handling the URL as an action and then redirecting to the same page, but with the get variable set...
class ProductPage extends Page {
}
class ProductPage_Controller extends Page_Controller {
private static $allowed_actions = array(
'video',
'audio',
'photos',
);
public function video() {
$this->redirect($this->Link().'?tab=video');
}
public function audio() {
$this->redirect($this->Link().'?tab=audio');
}
public function photos() {
$this->redirect($this->Link().'?tab=photos');
}
}

SilverStripe ModelAdmin

I am new to silverstripe framework and trying to fetch a list of menu in the admin panel.
I found lots of example to show menu on front-end by Menu(1) and Menu(2) etc. but did not get any sample code to fetch same menu array in admin model.
The code I tried is:
public function getCMSfields() {
$fields = FieldList::create(TabSet::create('Root'));
$fields->addFieldsToTab('Root.Main', array(
TextField::create('Name'),
DropdownField::create('URL')
->setSource(SiteTree::get()),
));
return $fields;
}
ModelAdmin is mainly there to manage DataObjects and not Pages. Have a look at the Docs and this Lesson to learn more about ModelAdmin.
But if you want to manage pages in a ModelAdmin, you could do it like that
class MyPageAdmin extends ModelAdmin {
...
...
private static $managed_models = array(
'Page'
);
public function getList() {
$list = parent::getList();
if($this->modelClass == 'Page'){
$list = $list->filter('ParentID', '1');
}
return $list;
}
}
To manage only children from a specific page, use the getList() function and filter your list after your needs.
There is also (albiet for an older version) this tutorial http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-2-using-model-admin-and-url-segments-to-create-a-product-catalogue/ from ssbits

Redirect to DataObject edit page inside BetterButton custom action

I'm trying to create a custom button that clones a DataObject using the unclecheese/betterbuttons v.1.2 module.
Everything is working fine but at the end I would like to redirect the user to the newly created DataObject edit page instead of refresh/go back. How can I do this?
Here is my custom button code:
class GridFieldCloneBetterButton extends DataExtension {
private static $better_buttons_actions = array(
'clone_do'
);
public function updateBetterButtonsActions($actions) {
$actions->push(
BetterButtonCustomAction::create('clone_do', 'Clone')
->setSuccessMessage('Object cloned')
->setRedirectType(BetterButtonCustomAction::GOBACK)
);
return $actions;
}
public function clone_do() {
$current_record = $this->owner;
$clone = $this->owner->duplicate();
}
}
Maybe if I can access GridFieldDetailForm_ItemRequest from inside the DataExtension I can make this work, but I really don't know how to do it.

Silverstripe - return an array of pages selected with TreeMultiselectField

I am trying to use TreeMultiselectField to associate many pages to one page in Silverstripe. I was able to do that, the CMS saves them. But now I need to be able to display the pages I selected on the template. How do I do that?
Here's my code so far
class FundsAndPerformancePage extends Page {
public static $many_many = array(
"Funds" => "SiteTree",
"Information" => "SiteTree"
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new TreeMultiselectField('Funds','Select pages for section "Our Funds"', 'SiteTree'));
$fields->addFieldToTab('Root.Main', new TreeMultiselectField('Information','Select pages for section "More Information"', 'SiteTree'));
return $fields;
}
public function Funds(){
//Need to return an array of pages selected with TreeMultiselectField
}
}
class FundsAndPerformancePage_Controller extends Page_Controller {
}
if you want to loop the related Pages in a template, you don't have to define a getter method yourself.
<% loop $Funds %> should work by default, by using the default (magic) getter method ->Funds()
If you need an array anyway, you could do something like this:
public function FundsAsArray(){
return $this->Funds()->toArray();
}
as the getter method returns an instance of ManyManyList, which would have an toArray method inherited from DataList
see http://api.silverstripe.org/3.0/source-class-DataList.html#_toArray

Categories