How to use Page Selector in Custom Block?

Hello guys!

I'm totally new to concrete5 and try to wrap my head around... well everything.

I've build a custom block with some input fields, where the user should have the possibility to pick a page or write in in external link into a field. Now that works just great with the standard link picker coming with concrete5.

But that's where my problems start:
1.) Can i get the link picker functionality into my custom block (so i'm able to do it with add.php and edit.php)?


2.) Can i use the page selector class to accomplish this?

This gets me the page selector where i can select a page from the sitemap, but haven't figured out yet how i can my hands on the URL Path to the selected page.
$html = Core::make('helper/form/page_selector');
print $html->selectPage('page_link');

As said the best solution would be the standard link picker, but i haven't figured out yet how to implement this into my custom block.

Any of you guys? I don't need a complete solution, maybe just a hint to a block or concrete5 addon which i has that functionality, so i can just analyze the code.

Thanks in advance!

View Replies: View Best Answer
hutman replied on at Permalink Reply
I'm not sure what exactly you mean by "standard link picker" but if you have the page_id which is what gets saved from the selectPage bit, you can do this to get the url

$nh = Loader::helper('navigation');
$page = Page::getByID($page_link);
$url = $nh->getLinkToCollection($page);
s0krates replied on at Permalink Reply 1 Attachment
Thanks, i will look into it!

Sorry for the rather bad english, with "standard link picker" i mean the functionality from the WYSIWYG Editor, where you can select a word and put a link on it. Hope this is a clearer statement.

Now i'm hooked up on the concrete5 events which get fired when doing stuff, i can see the object in my dev console, but don't know how to access it. In that object is everything i need, please see the attached screenshot. Is that prototype?

I figured i need to use the eventlistener, but don't get the object back i need.
Concrete.event.bind('ConcreteSitemap', function(e, instance) {
       Concrete.event.bind('SitemapSelectPage', function(e, data) {

As said, this doesn't give me the object i need but it gets me some other object with cID, pagetitle and some DOM Sets from the page selector sitemap itself. Maybe it's the wrong event listener?
hutman replied on at Permalink Best Answer Reply
I think you are overthinking this. In your db.xml you should have created a field to store the page_id (in my example that field is linkCID), if you did that you should be able to put this into your block add/edit

$pageSelector = Loader::helper('form/page_selector');
echo $pageSelector->selectPage('linkCID', $linkCID, 'ccm_selectSitemapNode');

When the block is saved, the page's ID will be stored in the db in that field. When you come to the view.php you should be able to just do

$nh = Loader::helper('navigation');
$page = Page::getByID($linkCID);
$url = $nh->getCollectionURL($page);

No need for events or anything like that, it will all be handled within the block.
s0krates replied on at Permalink Reply
Thank you very much! That worked like a charm and indeed i was overthinking this issue, wasn't aware that i can do that. Amazing!

Still... does someone know how i can access those objects coming back from the cms? Could be very helpful in the future.