Two Blocks for sort filter Views — Drupal 7 - drupal

I have a view in Drupal 7 with results including a field of date and another with price, I need to sort the results by means of these two fields when I click on the appropriate link (not button or dropbox radio), but the trick is I need add the different sort filter into two separate blocks, because each block will have a different per user context.
Besides the filters should be links. Any idea how to work this?

You can have different displays for all order variations and then use appropriate one depending on parameter passed with link. Of course, you can't just use block view, but create your custom block which will embed correct view depending on that parameter.
Other way would be altering view query. In you module add hook function for altering view and inside you should detect your view, check for parameter and alter order value.

You can create two block displays for the same view, each of them sorting the results with a different criteria. Once both blocks are created, enable them in the same theme region and establish the URLs in which each module should be displayed. This configuration can be set using the block configuration form.

Related

Different Views inside a Custom Block in Drupal 7

I have defined a Custom Block in my module and I want display different views in that block when user selects different sections using navigation menu. With the use of hook_block_view() i can set the content that needs to be rendered for that particular block. But how can I render different views based on the user's selection?
For a example;
I have a Block called Customers;
When user selects the Customer List form navigation menu, I want to show a customer list inside Customers Block.
When user selects a Specific Customer, I want to show the detail of that customer inside Customers Block.
What would be the best approach to achieve this in Drupal 7?
You can define your block from a code and use any logic you want to decide which view to use (simple if or switch php statement). Then you can embed different view based on your logic:
https://api.drupal.org/api/views/views.module/function/views_embed_view/7
Or you can get view results and prent data on your own:
https://api.drupal.org/api/views/views.module/function/views_get_view_result/7
Or, you can make 2 different block views and set for each one on what pages to be visible. You can do that in block settings or for more complex logic you can use context module to place appropriate block to a region depending on situation (page, what ever).

How to provide a button which will change my current page content to an previous page in drupal

I'm making a site wherein I want to show the current course that I'm gonna teach to my pupils.In this page there should also be links provided to my previous courses. Now when I'm done with this course I want to transfer it to a previous course or rather automatically create a link for it and get the new course content in it's place. I just think doing manually is kind of stupid. Rather I want to have a form where i can create my new course then click on make current course as previous and this course as new whenever i wish.How can I do this.Is this even possible
Pretty open question ... One way would be to work with views when showing a node.
In the view you should use a custom php field, which collects the record (nid) within the course-node table. And then create a link using the drupal path_alias function or by using node/nid ...
You could use panels-module as well. Where you have a view with the latest course, and under the latest course you have a view of a link to the latest course -1 . (I think you can set an offset in views to get the previous course) The view should accept an argument, namely the nid of the currently loaded node.
If you use this method, do check if your panels is giving the arguments to the views module.
Another way would be to use node reference as to what is the previous course (but you don't want it to be manual). The advantage of node_reference is that you don't need to enter your courses in a certain order. If you make it automatically, then the order in which you fill in the courses should be correct.
Easy man. Just create a content type called "course" and using CCK, add all the fields to capture information you want about the course.
Now you have the content. Using Views, create a simple view page displaying course content type and sort it on descending order, set it to display one item at a time and add a mini pager. That way the new course will be the first one displayed and the other ones will be behind it. You might need to customize the pager a bit ^^

Search forms linking to actual search page

I have created a search page uising exposed filters and views module. The user can choose from different values in order to get a table with specific results (returning node fields). This page is located under mysite.com/search. The problem is that I would like to put a simplified version of the search form on my homepage (lets say just the keyword search box + one or two checkboxes). This can be a block or a view. When the user presses the search button I would like to redirect him to the search page and show the results. Here the user shall be able to refine his search in an ordinary way. I guess this can be achieved by HTTP GET parameters and pointing to the actual search site. I was wondering however if I could do it without hardcoding the forms on my homepage, i.e. by using views, blocks, etc. I hope this makes sense. Any help will be appreciated.
Edit
The end result is that you want to have one form bring you to the search results page, and another advanced form on the search results page itself. This solution accomplishes this by creating two identical views with different filters for each form.
When someone uses the simplified form, they're taken to example.com/search, and when they're on that page and use the advanced form, they're taken to example.com/search/advanced. Because the views are identical with similar paths, the end user won't know the difference.
Here's how to accomplish this:
Create a view for the search results. Use the default display to set up the search results however you want. For filters, only put in automatic filters: don't put in the stuff you want the user to be able to filter by.
Create a new page display in that view. Give it a path of search. This is going to be the results page that a user hits when they use your simplified search form.
In this page display, override the filters. Set up and expose the filters you want for the simplified search form.
Override Expose form in block in the Basic settings for this display and set it to yes.
Create a new page display in the view, and give it a path of search/advanced. This is going to be the results page that a user hits when they use the advanced search form.
Override the filters for this display, set up and expose the filters you want for the advanced search form.
Override Expose form in block in the Basic settings for this display and set it to yes.
Now, you'll have two view pages, search and search/advanced, and two blocks, a simplified search form and an advanced search form.
Go to the block administration, and enable the simplified search block. Use the path specific visibility settings to set where you want the simplified search box to appear.
Now, enable the advanced search block. Use the path specific visibility settings to set the visibility to:
search
search/*
Let's say you wanted to create another simplified search block with a different set of filters (let's call this alternate). You can do that too: create another page display in your view as you did in steps 2-4 but instead of using the path search, give it a different path: search/alternate. You can add as many simplified forms with different filters as you want, and they'll all have the advanced search form and the same results when you use them.

Drupal Custom Form with Filters

I'm displaying cars on a page created with a view and displays. I want to be able to create a form on the home page to allow people to select the 'make', which will then update the 'models' list based on the 'make' the user selects, 'year' to and from, and 'amount' to and from. What the user selects will of course alter the list of used cars, whether that's on the existing used cars page or a new page.
I would be happy to create a custom module if required, just need some direction.
Thanks !
When using views, what you need to do is to use exposed filtes. Inside your view you can setup filters like normally, only when you expose them, the user get to change the value of the filter.
How the filters will be themed to the user will depend on how you store the values, so it's a bit hard to say how to progress from there. It might be a bit tricky to get a select and not a textfield. Once you get select fields, this could probably be done with either some theming or form_alter, all you need is to add some js to change the options. The js part should be pretty normal, you will probably need to fetch the model names and values using ajax.

Assign a taxonomy term to a view instance

Is there an easily managed way we can assign a specific taxonomy term to a specific instance of a view?
We're using the callouts module for Drupal, and it works great for nodes/pages we have in our site. But we have a handful of Views that are displaying as a page, but we cannot assign a specific taxonomy term to a specific instance of that view.
The view itself is pulling in lists of nodes based off of a taxonomy argument:
Example On the bottom left, we have some callouts, but they're shown randomly because we can’t assign a term to that page to show specific callouts.
There's 7-8 of these pages, and they all use the same View, but just passing different data through the argument. we've tried assigning the callouts we want to the taxonomy that is used to create the view, but that didn't work either.
Without changing the view output (for example, from a page to a block), how can this be accomplished?
Even if you could assign a taxonomy term to a view, I think it would not help in this case. Blocks are not aware of their context at the time they are rendered, so they have to look at the url to retrieve information about the node that's being displayed. The block checks if the page displays a node; if so the node data is loaded. The callouts module also works like that, as is explained on the module page. Since a view is not a node, the block will not render. To make this work, you would have to alter the callouts module I'm afraid.

Resources