How to create dynamic router for catalog items - symfony

I'm trying to work with Kunstmaan bundles for Symfony2 and have one issue.
Currently I'm trying to create catalog bundle, everything seems okey, but I don't want to create menu item for each product. It would be great to access products dynamicaly by item slug-title in /en/catalog/* menu item. How is it possible?

We are experiencing the same problem ... we are trying to solve this by creating catalog items which are also menu items but have null as parent so that they don't show up in the tree. By doing this you still have the versioning system and everything but it doesn't slow down your tree when you have many catalog items. You can list these catalog items somewhere in an admin list using the AdminListBundle (https://github.com/Kunstmaan/KunstmaanAdminListBundle)
To link these catalog items to a certain overview page we are using the chainrouter (https://github.com/Kunstmaan/KunstmaanNodeBundle/blob/master/Resources/doc/NodeBundle.md). For now we don't have a clear example of this but maybe this can get you started? We are trying to make using the chainrouter easier, but it's still under construction: https://github.com/Kunstmaan/KunstmaanNodeBundle/pull/38/files

The fastest/easiest way would to make your product as a page which can be defined as a child for your Catalog. The KunstmaanNodeBundle will take care of the slugs.
In your Catalog class (I assume it extends AbstractPage) override the getPossibleChildTypes method :
public function getPossibleChildTypes()
{
return array (
array(
'name' => 'Product',
'class'=> "Acme\CatalogBundle\Entity\Product"
)
);
}
This way you can just create products as subpages under your catalog page. Then you just need to get the children of your catalog in the twig template of your catalog page.
The drawback is, is that each product is a page on its own (with versioning) instead of being a simple Entity.

Related

Anyone know how to add a field or column to the /ADMIN/CONTENT listing page? DRUPAL 7

I would like to add a field / column to the Content Administration Overview page but it appears the easiest theme override to do this has been deprecated with D7.
In D6 I could just override the method:
theme_node_admin_nodes($form)
But this method no longer exists for D7. What's the equivalent replacement or do I actually need to hook into node_admin_nodes() now and modify the form directly?
For me it was super easy with these two modules:
views bulk operations (VBO)
administration views (needs VBO)
As soon as both modules are installed and activated you can go to your views (admin/structure/views) where now 3 additional views appear (Administration comments, Administration nodes, Administration users). You then just need to edit the view "Administration nodes", where you can add and arrange everything you want as usually with views.
I wanted to add a column displaying all content's nids. Worked super well!
You'll have to hook into the form, the theme element has been completely removed node_admin_nodes() in Drupal 7.
It's actually node_admin_content() that you'll need to hook into as node_admin_nodes() is no longer a form function, it just builds up elements that are used by node_admin_content().
Fortunately the elements in node_admin_nodes() and node_filter_form() (the two functions used in node_admin_content() to build up the page) are nicely structured and will be very easy to override.
I've been able to add an element to the bottom of the table. Although I am unsure how you ADD a coloumn into the body of the table?
function seven_form_alter(&$form, &$form_state, $form_id) {
drupal_set_message("Form ID is : " . $form_id);
//get node_admin_content
//$nodeAdmin = drupal_get_form("node_admin_content");
// Add a checkbox to registration form about agreeing to terms of use.
$form['node_admin_content']['poland'] = array(
'#type' => 'checkbox',
'#title' => t("I agree with the website's terms and conditions."),
'#required' => TRUE,
);
}
The Administration Views module replaces a lot of admin listings with real views (as in Views module) that you can edit and configure any way you want it.

Wordpress - How can I create my own template outside of the expected hierarchy of templates and feed a query to it?

BACKGROUND
I have used WordPress custom post types to create a newsletter section for my website. Newsletters consist of Articles (dm_article), which are grouped by the Issues taxonomy (dm_issues).
1) I have created an index of all of my newsletter Articles. I am using a template called taxonomy-dm_issues.php to loop within a selected Issue and display each Article's title, excerpt and a link to the full content, which is managed by single-dm_article.php. This is working great.
2) I would also like to create second taxonomy-based template for Issues. This is going to act as a print-friendly option: "print entire newsletter". I would like the template to loop through and display each Article title, excerpt, and long description. Some of the look and feel will also be different.
For #2, let's assume I've created a template called print-dm_issues.php. It currently looks identical to taxonomy-dm_issues.php, except it has the additional long description data for each Article and contains some different styling.
I want to setup this "print friendly" option without making the WordPress admin have to jump through any hoops when Issues and Articles are created. I also do not want to have to create a new template each time a new Issue is created.
CORE QUESTION:
What I am asking for may boil down to this: How can I create my own WordPress template outside of the expected hierarchy of templates and feed a query to it? Do note I am using the "month and name" common permalink structure, so I'll have to muck with my htaccess.
ALTERNATIVES:
1) My fallback is to have taxonomy-dm_issues.php contain the information for both variations and use style to handle the different view states. I know how to do this. But, I'd rather not do this for sake of load times.
2) Using Ajax to fetch all of the Article long descriptions (the_content()) with a single click is an option, but I don't know how.
3) ???
With or without clean URLs, you can pass variables based on your taxonomies through the links query string if you want to only return a single taxonomy term and style the page differently depending on the term.
$taxonomyTerm = $_GET['dm_issues'];
$args=array(
'post_type' => 'dm_article',
'dm_issues' => $taxonomyTerm,
'post_status' => 'publish',
);
There is reference to this int he Wordpress 'query_posts' documentation by passing variable into your query parameters: http://codex.wordpress.org/Function_Reference/query_posts#Example_4
For instance in the link below, the title is generated based on the sting in the URL.
http://lph.biz/areas-we-serve/service-region/?region=Conestoga
You can set up a parameter that will return a default value if the page is reached without the variable being defined. See below:
if (empty($taxonomyTerm)) {
$taxonomyTerm = 'Default Value';
}
You can create a separate page template. Define the template name at the top of your PHP document:
<?php
/*
Template Name: Printed Page Template
*/
Place your custom query, including all of the content that you need output in this page template... In your WP admin, create a new blank page and assign your new 'Printed Page Template' template to this page. Save it and view the page.

Block view content relative to the page it's on in Drupal 6

I want to make a Views block's content show things that's related to the page I'm on. For example I have a content type 'Parent' that has many nodes of type 'Child' related to it, so on the 'Parent' node I want to show all 'Children' in my block.
Not that complicated but I just can't get it to work. I've been using the Node Relativity module to setup the Parent-Child relationship and then I tried adding an argument in the View to filter the Child nodes. The problem with this is I can't get the Parent ID saved from the Child node + I can't really get the ID of the page I'm on (the Parent's ID) either without using a the URL argument, which means no clean URLs.
I experimented with saving the ID of the parent as a taxonomy term for the Child nodes. The problem with this is I want the Parent-Child relationship to be setup automatically when creating a new node (by using the current page's ID as a parameter when creating a new node).
Maybe I'm looking at this from the wrong angle though... Does someone have any insight in this?
What you want is views attach so that on a given node you can show things related to that node. Check out this recipe from Mustardseed Media for making related content creation & views things rather easy.
Views attach would do it, but doesn't it attach to the node content rather than as a block?
To do it in a block, create a views block with the parent node reference id as the views argument.
Then select to provide the views default argument. With views 2 I think you can just use "Provide node id from URL". If that doesn't work then provide the argument with PHP and enter this as the php:
<?php if (arg(0) == 'yourcontenttype' && arg(1) != '') {  return arg(1); } ?>
Let me know how that works for you.

Create dynamic link in drupal

Could anyone tell me how to create a dynamic link in drupal?
I want to create a link to a group membership list. I have created the view with the argument. How do I create the menu item link to the view? It will be different depending on the group.
Thanks
I create a redirect link for such situations. For example, if I want a menu link to direct the user to their user edit page, I will implement hook_menu() as follows:
function my_module_menu()
{
$menu['user/cp'] = array
(
'title' => 'User Control Panel',
'page callback' => 'user_cp_redirect_page',
'access callback' => 'user_is_logged_in',
'type' => MENU_CALLBACK,
);
return $menu;
}
Then, I set the page callback to look like this:
function user_cp_redirect_page()
{
global $user;
drupal_goto('user/' . $user->uid . '/edit');
}
In short, you can't. Drupal's menu system caches the entire menu: menu items can't appear differently for different users (although you can set access permissions for them). If you want menu items to appear, you have to either register them in hook_menu() (which is only called when the menu is rebuilt), or you have to add them manually in Menu administration.
The handbook page on the Menu system provides more information about this.
However, you can create a fake menu using a block display in your view and the HTML list row style. This is useful if you wanted to have a category listing block, outside the main menu structure.
It sounds like you may need to use views arguments to filter your results if you are pulling different "groups" based on a single view. I would start here to learn more about views arguments: http://drupal.org/node/54455, if this is indeed what you are trying to accomplish.
EDIT:
I guess it would help if I read the question fully. It sounds like you are already using arguments for your view. In this case you already have created dynamic links to your page. Try putting the arguments for each "group" at the end of the URL. For example if created a page display with a path news, you can pass the argument by appending it at the end of the URL. So, if you created an argument using "Node:Created Year" you could then filter this content by putting something like example.com/news/2009 to access only the nodes that were created in 2009. What you pass is dependent on the type of argument you have created.

Get a node to show up underneath a View's menu item

So I've got a content type of "News" and then a View which shows a list of News nodes as a menu item.
Is there any way to highlight the News View in the menu tree when you're viewing a News node?
I'm sort of aware of why this doesn't work, and why doing this might be hacky, but there's got to be a way to have a "default" menu item or something that a node can show up under.
Actually, I found a module that does basically what the template.php answer above does, by allowing you to assign a default menu item by content type.
It's called Menu Trails. Here is an excerpt from its project page:
... adds some common-sense usability to Drupal's menu system
Menu Trails implements primary/secondary links which keep the current menu trail "active" or highlighted. A handy snippet ready to go into your template.php is included.
The module provides a means of broadly categorizing nodes (by type or taxonomy) as falling "under" a known menu item. These nodes are not added to the menu tree (keeping the menu admin system sane) but they will trigger the functionality above -- preserving navigation state for the user -- when viewed.
New for 6.0: Menu Trails can also set breadcrumbs for nodes, keeping them in sync with the trail.
New for 6.0: Menu Trails is now Organic Groups aware, so nodes can be designated to fall "under" the first group node they belong to.
New for 6.0: A token is exposed to pathauto (and other token-aware modules) allowing for the menu trail to be used in automatic path alias creation.
Assuming the answer to my above comment is "yes," this is something you can accomplish through the template.php file in your theme folder
The final solution will depend on your settings, but generally most of the action will happen inside phptemplate_preprocess_page
// Simplified, and untested in this form
function phptemplate_preprocess_page(&$vars) {
if (isset($vars['node'])) { // if we're looking at a node
$body_classes[] = (($vars['node']->type == 'News') || (arg(0) == 'News')) ? 'news_page' : ''; // Page is news page
}
else if (arg(0) == 'taxonomy') {
// ... Special handling for news taxonomy pages, if you want
} else {
$body_classes[] = "page-type-" . arg(0);
}
$body_classes = array_filter($body_classes); // Out! Out! Damn empty elements!
$vars['body_classes'] = implode(' ', $body_classes);
}
This will give the you the body.news_page style class to work with, and you can combine that with the style of your news menu block to make it appear how you like.
if Menutrails doesn't work (for me it didn't) you can do it yourself by something like:
$somenode = menu_get_item('node/5');
menu_set_item($somenode);
I have found you have more control if you do something like this in hook_nodeapi().
// this code worked for me
$somenode = menu_get_item();
$somenode['href'] = 'node/5';
menu_set_item(NULL, $somenode);
You may need to set the weight of your custom module to be heavier than core modules: at least 1

Resources