Iam New to drupal.I have created a custom block in drupal7.Now In this Block I want to display the data of custom content type(i.e for example Advertisements).This Advertisements have a faciltity to display the ads in homepage,teaser,full view mode page.
Now the problem is I want to get programatically the view mode of block similar to node view so that I can get the advertisements related to that view(i.e advertisements with teaser view) etc..
This is how I have implemented but it failed to show the view mode
/**
* Implements hook_block_view().
*/
function Advertisement_block_view($delta = '',$view_mode) {
echo $view_mode;
$block['subject'] = t('Advertisements');
$block['content'] = Advertisement_block_content();
return $block;
}
Please help with this..
Thankyou
By default Blocks do not support view modes. Not the way nodes do at least as far as I know of. Take a look at the Drupal API on the hook_block_view() you used. It doesn't mention a $view_mode argument. You should actually be getting a warning if used.
Getting Advertisements (nodes) of a certain view mode sounds somewhat weird imo since you don't assign view modes onto nodes but onto a content type which means that all Advertisement nodes would be able to be viewed in a certain view mode once it is assigned to its content type.
If you want to get all view modes configured on a content type you can use: field_view_mode_settings($entity_type, $bundle) in which you pass $entity_type = 'node' & $bundle = 'Your_advertisement_content_type_machine_name'
Related
I want to understand utility of isExecuted() in ADF's ViewObjectImpl class.
The documentation is very sparse(Indicates whether the row set has been executed or not) and I couldn't get my doubts cleared.
As per documentation, only if row set is executed at least once it will return true. But, I am seeing that as soon as my application module is created, a view Object which is housed in the application module, is returning "isExecuted() = true " .. Is this expected or is there any setting because of which this is happening ?
It is hard to see purely via the Application Module Tester.
But if you have data controls based on your AM and use them on an interface (such as a UI page), you can check the working of the isExecuted method.
On your user interface, you can create a basic page that does not bind to any of the data controls based on the VO's - but only to a simple AM operation that you expose via AM's client interface:
public void showIsExecuted() {
System.out.println("*******TestAppModuleImpl::showIsExecuted() DepartmentsView1:" + this.getDepartmentsView1().isExecuted());
System.out.println("*******TestAppModuleImpl::showIsExecuted() DepartmentsView2:" + this.getDepartmentsView1().isExecuted());
System.out.println("*******TestAppModuleImpl::showIsExecuted() ViewObj1:" + this.getViewObj1().isExecuted());
}
On a UI page (view1.jsf), you call only this method without using any of the VO based data controls and your output should show this:
*******TestAppModuleImpl::showIsExecuted() DepartmentsView1:false
*******TestAppModuleImpl::showIsExecuted() DepartmentsView2:false
*******TestAppModuleImpl::showIsExecuted() ViewObj1:false
Now, on another UI page (e.g. view2.jsf), show some of the data from one or more of the VO's and also a button for the custom AM function. After running the page, you should get the below in logs (as expected):
*******TestAppModuleImpl::showIsExecuted() DepartmentsView1:true
*******TestAppModuleImpl::showIsExecuted() DepartmentsView2:true
*******TestAppModuleImpl::showIsExecuted() ViewObj1:false
For reference, this is what my design time setup (in JDeveloper 12.2.1.1) looks like :
Also, you can further tweak the options under AM -> General -> Tuning -> Customize Runtime Instantiation Behaviour
How do I extract specific field for display in a taxonomy page?
I have a custom content type called "film" and each film has a Term Reference field called "casting". As expected I can click on a "casting" (tag) it brings me a page where all films are listed wherever this tag is associated. For expample if I click on "Kate Winslet" from movie Titanic, I land on a page http://localhost/mysite/tags/kate-winslet where other movies of Kate Winslet are listed. Up to this point everything is just fine.
I do not want Drupal to pull in and show default fields like just Title and Body in its own display format. Rather I want it so that I can display a photo from each film, year of release and of course the title and trimmed version of the body. I only want to customize the content of this page so that I have the control over What to Show and Where To Show a specific field value.
This is what I tried:
I cloned and put page.tpl.php in my theme's template folder. Renamed it as page--vocabulary--tags.tpl.php. Then I took out the following line of code (<?php print render($page['content']);?>) from my page--vocabulary--tags.tpl.php. The intention was to check whether the overridden template is actually being accessed by Drupal or not. It does!
But I am not been able to extract fields like field_photo or field_release_date from $page['content]. To get an idea about defined variables and how they are placed I used the following line of code:
<pre><?php /*print var_export(get_defined_vars(), TRUE);*/ ?></pre>. But even from there I could not extract a particular field like I mentioned above. The fields look to be somewhere inside $page['content']['system_main']['nodes'], but I don't know how to get to a specific field directly.
I also created a template.php with the following preprocess hook function:
<?php
function introduction_preprocess_page(&$vars) {
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
$term = taxonomy_term_load(arg(2));
$vars['theme_hook_suggestions'][] = 'page__vocabulary__' . $term->vocabulary_machine_name;
$vars['content'] = $vars['page']['content']['system_main']['nodes'];
}
}
?>
Both <?php print render($content) ?> and <?php print render($page['content']) ?> print the same result but I want something like <?php render($content['photo_field'])?> which I am not been able to.
I am sorry for making this too long. I have just stepped into Drupal. So wanted to make sure that what I am trying to explain matches exactly what I want to accomplish.
You are probably trying the long way to this.
You can use Views module. It allows to create custom listings querying the database, but also override existent ones, like the case of the taxonomy term page listing.
Once you have the module installed (if it's not yet), particularly the Views UI module, go to /admin/structure/views and scroll to bottom, where disabled views (grayed rows) are. You'll find one called Taxonomy term, described as 'A view to emulate Drupal core's handling of taxonomy/term.'
Click Enable on the right of it and then go to the same place where the Enable link is, click the arrow to unfold and choose Edit.
Once you're in the view edit page, you can manipulate the listing at your convenience, adding/removing fields or whatever you want to do in your particular case. If you are not familiar with Views, I recommend you to learn about it, there is a lot of related content on the web and it is close to essential for Drupal development.
Also, if you want to add more customisation to the page, you can use the same approach with the Panels module, who allows to override system pages (not just listings like Views).
I have different fields and showing in different blocks, and want to apply exposed filter to all but my problem is it shows different exposed filters for each different block. I want to make it common for each block.
Below are the steps,
I made 5 blocks to be displayed for each buttons.
Added exposed filter for languages for each block.
Now each block showing its different exposed filter.
But I want the exposed filter should be shown above the buttons and should work for each block display. Attached screenshot for the issue.
I installed Views Global Filter but is gives Session error.
I was just about to suggest the Views Global Filter.
Another way is to set a contextual filter on all your blocks that pulls from the url, so they each pull the same value.
This is an active issue in the views issue queue, with a few people who have made it work:
https://www.drupal.org/node/1587894
Comment #6 has some simple code, and that would be applied here
https://www.drupal.org/node/1871388
After 3 days, I haven't found the solution, even by programmatically.
Then what I had the last option(in my mind, huh) is,
I get all the fields in one block only, not creating the different blocks for different tab or buttons.
Used the description of Better Exposed Filters, in which I pasted my buttons/tab UI HTML as its.
Now on changing the language all the fields are fetched according to the selected language. But in this case my active tab/button get lost its activeness.
Now, I need to get the last active tab/buuton, so that I can click it again to get the active tab after filtering my languages.
Below is the piece of code which is need to my js file.
// Active target element to make the tab/button active after
// ajax responds in filter
var activeTargetElement;
Drupal.behaviors.events = {
attach: function (context, settings) {
$('#views-exposed-form-MY_VIEW_MACHINE_NAME-BLOCK_NAME', context).ajaxStart(function () {
// my tabs/button are active on the basis of data-target attribute,
// so need to memorise which tab/button is active before fitering any language
activeTargetElement = $('#MY_TABS li.active a').data('target');
}).ajaxSuccess(function () {
// if any target is memorised, then simply click it or trigger a click event for it
if($('[data-target="'+activeTargetElement+'"]').length){
$('[data-target="'+activeTargetElement+'"]').click();
}
});
}
};
CASE:
I've created a content type 'Attorney', and have set a url alias pattern for all attorneys to be 'attorneys/[node:title]'. I'd like to create a view that uses the aliased path to display the information about the attorney. This view should have a 'page' display.
EXAMPLE:
When a user visits 'http://mydomain.com/attorneys/aaron-silber' the view returns data for the Attorney with the name Aaron Silber.
BACKGROUND:
I've searched high and low for a solution to this but can't seem to find one that works for me. Typically I'm asked to create a page view with a url of 'attorneys/%' and add a contextual filter with 'Content: Nid', choosing to provide a default value (type: Raw value from URL, path component 2).
The resources on the web for this case are aweful at best. Lets try to fix it here once and for all.
Thanks!
Use a Views block instead with the visibility set to "Only the listed pages" and supply "attorneys/*" in the textarea. Set the block to display in the main content region. Use the Content: Nid filter with a default value of path component 2, as you were previously attempting.
You can't have an attorney node page and a Views page occupying the same URL.
I'm currently developing a Drupal 7 site where I use Page Manager's "node_view" to customize the layout for my "Article" content type.
So, whenever viewing an Article I want to show a little box with "Related content".
I have a taxonomy vocabulary "Shared category" that I use in all my content types.
For example I also have a "Gallery" content type, so when viewing an article in with the "myTag" term - I want to show a Content Pane with images tagged with "myTag" from the "Shared category" vocabulary.
My question is about setting up the Contextual Filter for the Content Pane.
Should the "Argument input" be a Vocabulary or a Term? - I've tried both but can't get it to work.
Also I have another question: Is it possible to use a Content Pane as a block, that is shown with the Panel? - I guess not, sinse the Contextual filter value comes from Page Manager.
You won't want to manually input the argument in the panel, as it will vary for each article.
You'll want to set it automatically using a default argument that gets the tid from the node.
To get the related content block to show content based on the same terms as the node being viewed, you'd need to add a taxonomy term id argument to the view.
You can then try the 'Set a default argument' and use 'taxonomy term from URL' ( node option )
If that doesn't work, you may need to get the relevant tid from node using php code in the default argument area, with something like node_load or menu_get_object to load the node.
e.g something like
if($node = menu_get_object()){
if(isset($node->field_shared_category[$node->language][0]['tid'])){
return $node->field_shared_category[$node->language][0]['tid'];
}
}
Related content can be shown by using contextual filter in block views. This block view will contain content which are associated with the current content viewed by a user.
You can goto "Create related content block view based on terms in Drupal 7" blog post to get step by step instruction to create this block view.