test if certain content type is placed on page.

7 views
Skip to first unread message

Brian Jones

unread,
Nov 6, 2009, 6:05:53 PM11/6/09
to Reason Discussion
Is there a call to test if a media work has been placed on a page?

Nathan White

unread,
Nov 6, 2009, 6:39:43 PM11/6/09
to reason-d...@googlegroups.com
Hi Brian - well the details depend on the context, but ... basically you would run an entity selector to grab the media works associated with a page. If there are none, the result of that entity selector would be false.

Here are three pieces of info you need.

1. The page id that could have media works.
2. The unique name of the Media Work type.
3. The allowable relationship name that is used to relate pages to media works.
4. Which side of the page to media work relationship media works are on.

The page id, in the context of a module, would be available using $this->page_id. If the page has a unique_name, you could get the id using the function id_of($page_unique_name).

You can find the unique name of the type by previewing the type in the MASTER ADMIN site. In this case, for the Media Work type, the unique name is "av".

The allowable relationship name can be found using the allowable relationship manager. From the MASTER ADMIN site, there should be a link under "Other Links" on the menu at left to the allowable relationship manager. From that page, if I enter "Media Work" under the column right and do a search, I find the allowable relationship name is "minisite_page_to_av". This means Media Work is on the right side of the relationship. If I found no results when searching for "Media Work," I might have tried searching for it on the left side. Often, but not always, the items on the right side of a relationship are items contained by something on the left ... minisite_page_to_image, page_to_asset, etc. Pages, in particular, are usually on the left.

So ... now that I have my four pieces of info I can write an entity selector like this:

$es = new entity_selector();
$es->add_type(id_of('av'));
$es->add_right_relationship($my_page_id, relationship_id_of('minisite_page_to_av'));
$result = $es->run_one();

If $result is false, there was no media work found on the page. If there are media works on the page, $result will consist of an array of media work entities. The noun right in "add_right_relationship" signifies which side of the relationship the type (Media Work) you are selecting is on.

Here is a more efficient entity selector that I'd write if all I cared about was whether any media work existed and didn't need to grab the whole set. It also assumes I have a known site id available.

$es = new entity_selector($my_site_id);
$es->add_type(id_of('av'));
$es->add_right_relationship(($my_page_id, relationship_id_of('minisite_page_to_av'));
$es->limit_tables();
$es->limit_fields();
$es->set_num(1);
$result = $es->run_one();

Hope this is helpful - let me know if you have questions.

Nate

Brian Jones

unread,
Nov 9, 2009, 12:30:09 PM11/9/09
to Reason Discussion
Nate,

The information was very helpful. Problem solved. Thanks.

Brian
Reply all
Reply to author
Forward
0 new messages