Silverstripe nivo slider - silverstripe

if (class_exists('DataObjectManager'))
$a='DataObjectManager';
else
$a='ComplexTableField';
$f->addFieldToTab(
"Root.Content.Panels",
new $a(
$this,
'Panels',
'NivoSliderPanel',
array('Name' => 'Name','Thumbnail' => 'Thumbnail'),
'getCMSFields_forPopup'
)
);
i am using a nivo silder can anyone help me to understand is piece of code.
I am getting a error ComplexTableField could not found.

ComplexTableField is from Silverstripe 2.4 and no longer works in 3.0 or 3.1.
If you are getting an error that ComplexTableField could not found then I am guessing you are using Silverstripe 3.1.
Silverstripe 2.4 code will not work in 3.1. This code needs modification to work in 3.1.
In Silverstripe 3.1 GridField has replaced ComplexTableField.
Using GridField looks something like this:
private static $has_many = array (
'Panels' => 'Panel'
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
$panelsField = new GridField(
'Panels',
'Panels',
$this->Panels(),
GridFieldConfig_RecordEditor::create()
);
$fields->addFieldToTab('Root.Panels', $panelsField);
return $fields;
}

Related

Rename plugin name in Wordpress Dashboard Menu

I have tried a lot of suggestions on different posts here, but none of them seem to work for me.
I want to rename the name of a plugin on the dashboard menu on my Wordpress site. The name of the plugin is Sensei LMS and the path of the plugin folder is /plugins/sensei-lms.
I'd appreciate if someone helps me with some code that I can use to rename this. Thank you
I've used this tutorial in the past.
In your case, it would be:
function my_renamed_admin_menu_items() {
global $menu;
// Define your changes here
$updates = array(
"Sensei LMS" => array(
'name' => 'New Menu Name'
),
"Another Menu Name" => array(
'name' => 'Another New Name'
)
);
foreach ($menu as $k => $props) {
// Check for new values
$new_values = (isset($updates[$props[0]])) ? $updates[$props[0]] : false;
if (!$new_values) continue;
// Change menu name
$menu[$k][0] = $new_values['name'];
}
}
add_action('admin_init', 'my_renamed_admin_menu_items');

SilverStripe - Adding 2 TreeDropdownFields, only one works

I've run into a very bizarre issue while creating 2 TreeDropdownFields for a DataObject. For some reason, only 1 of the 2 TreeDropdownFields render correctly in the SilverStripe admin. The other doesn't render as a TreeDropdownField at all but just as a label:
Here is the code:
class HomeBanner extends DataObject {
public static $db = array(
'SortOrder' => 'Int',
'Title' => 'Varchar'
);
public static $has_one = array(
'Image' => 'Image',
'SecondaryImage' => 'Image',
'FirstLink' => 'SiteTree',
'SecondLink' => 'SiteTree'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeFieldFromTab('Root.Main', 'PageID');
$fields->removeFieldFromTab('Root.Main', 'SortOrder');
$fields->addFieldToTab('Root.Main', new TreeDropdownField('FirstLinkID', 'First Link', 'SiteTree'));
$fields->addFieldToTab('Root.Main', new TreeDropdownField('SecondLinkID', 'Second Link', 'SiteTree'));
return $fields;
}
public static $summary_fields = array(
'ID' => 'ID',
'Title' => 'Title',
'Thumbnail' => 'Thumbnail'
);
public function getThumbnail() {
return $this->Image()->CMSThumbnail();
}
}
Here is what I have tried so far:
running dev/build/?flush=true
running ?flush=all and ?flush=1
logging out and logging back in after the dev/build + flushes
logging into the admin in another browser (I typically use Chrome but
logged into the site's admin on FireFox and saw the same problem)
The error logs report nothing -- they're clear
There are no errors in the console for Chrome's dev tools
Adding a third TreeDropdownField will allow the first 2 to render
properly but the third one will just show a label instead of a
TreeDropdownField
This format works, but doesn't save whatever is selected--it clears your choice as soon as you leave the page. Also, it deletes all that was saved already in the admin unless I remove it. I can't make changes or else the items saved get removed.):
$fields->addFieldToTab('Root.Main', new TreeDropdownField('SecondLink', 'Second Link', 'SiteTree', 'ID'));
Does anyone have any ideas as to why this could be happening? It doesn't seem to make sense that you can't have multiple TreeDropdownFields.
Reposting as this turned out to be the answer:
The name “HomeBanner” suggests to me that there should also be a has_one pointing back to HomePage or similar? The cause of this is probably that SilverStripe is automatically trying to set one of the has_one relations to point back to the page that the banner belongs to.
Similar conflicts can also happen when using code like this:
class Page extends SiteTree {
private static $has_many = [
'Banners' => 'Banner'
];
}
class Banner extends DataObject {
private static $has_one = [
'Page' => 'Page',
'LinkedPage' => 'Page'
];
}
As SilverStripe doesn't know whether it should use PageID or LinkedPageID to auto-populate that side of the has_many relation (GridField will try to automatically assign the correct has_one ID).
In these cases, you can use dot-notation to distinguish between them - you’d change it to $has_many = ['Banners' => 'Banner.Page'];. See https://docs.silverstripe.org/en/3/developer_guides/model/relations/#has-many for more info.

How to Get visual composer page through rest api

I'm developing an ionic app in which I have a rest api to get the blog contents from wordpress page. I'm trying to get the visual composer page through api but I'm getting raw html format and css or missing for visual component pages. Can I get the visual composer page fully along the properties through api or is there any restriction to use api ??
I think you find your answer here: https://github.com/WP-API/WP-API/issues/2578
The example below was taken from the link above (thank you, bradmsmith!)
Here is an example how to render the VC shortcodes on the content of a post:
add_action( 'rest_api_init', function ()
{
register_rest_field(
'page',
'content',
array(
'get_callback' => 'compasshb_do_shortcodes',
'update_callback' => null,
'schema' => null,
)
);
});
function compasshb_do_shortcodes( $object, $field_name, $request )
{
WPBMap::addAllMappedShortcodes(); // This does all the work
global $post;
$post = get_post ($object['id']);
$output['rendered'] = apply_filters( 'the_content', $post->post_content );
return $output;
}

Silverstripe 3 - LinkingMode() for Dataobject

I created this function to show dataobjects as page
// DISPLAY ITEM AS PAGE
public function produkt(SS_HTTPRequest $request) {
$urlSegment = $this->request->param('URLSegment');
$item = ShopItem::get()->filter('URLSegment', $urlSegment)->first();
if( $item ) {
$data = array(
'Item' => $item,
'Title' => $item->Title,
'Parent' => Shop::get()->First(),
'Controller' => $this,
'URLSegment' => $item->URLSegment
);
return $this->customise($data)->renderWith(array('ShopItem', 'Page'));
} else {
return $this->httpError(404);
}
}
That's my YML File
---
Name: productRoute
After: 'framework/routes#coreroutes'
---
Director:
rules:
'onlineshop//produkt/$URLSegment!': 'Shop_Controller'
The function is on my Shop_Controller. and the Dataobjects are shown under onlineshop/produkt/blablabla-1
That works fine but in the navigation the link "Onlineshop" is not highlight as section.
I think I need to put the "LinkinMode()" function in my dataobject. But I don't know what the function should contain. return section current or link doesen't work.
Can someone help me?
thank you in advance
You just want to highlight "Onlineshop" which is a Page in your SiteTree, right?
If so, just override the LinkingMode() method inside that Class (extending SiteTree) and make it return section or current for your custom route being active...
You would just need that method on the DataObject itself if you would like to show each DataObject in the Navigation and highlighted when active.
see http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-1-keeping-it-simple/

Drupal 7 .10 hook_menu implementation error

I am trying to figure out why hook_menu implementation is not working anymore after upgrade from 7.4 to 7.10 for a custom module Menu links were working properly until update to latest version. after update all custom module links are deleted from table menu_links and menu_router.
After many attempts, I also installed a fresh version for D7.10 and created a simple custom module with one item link only (see code below) for testing purpose only. The link is not implemented once the module is enabled. Tables menu_links and menu_routers are not updated.
I have been looking around many possible errors and solution without success.
Really stacked now. What makes me doubt is that I do not see anybody else having the same issue... Any suggestion? Thank you
function misite_menu() {
$items = array();
$items['a/main'] = array(
'title' => 'main',
'page callback' => 'main',
'description' => t('Main front page'),
'access callback' => TRUE,
);
return $items;
}
function misite_theme() {
return array(
'main' => array
(
'template' => 'main',
'variables' => array('title' => NULL),
),
);
}
function main() {
$path = drupal_get_path('module', 'a');
$title = t('');
$build['mainelement'] = array(
'#theme' => 'main',
'#title' => $title,
);
$output = drupal_render($build);
return $output;
}
From the looks of this line:
$path = drupal_get_path('module', 'a');
Your module is called a.
In Drupal, the convention for hook naming is MODULE_NAME_name_of_hook() (see http://api.drupal.org/api/drupal/includes--module.inc/group/hooks/7).
This is true for both hook_menu() and hook_theme() so in your case if the module is called a your functions should be names a_menu() and a_theme().
If you make changes to any hooks make sure you clear Drupal's cache so the relevant registrys are updated.

Resources