Hot answers tagged

41

The correct routename for view is view.VIEW_MACHINE_NAME.PAGE_MACHINENAME(in another word "view.$view_id.$display_id" ) . try something like following use \Drupal\Core\Url; $url = Url::fromRoute('view.VIEW_MACHINE_NAME.PAGE_MACHINENAME'); $form_state->setRedirectUrl($url); and for your case $url = Url::fromRoute('view.team.page_1'); // page_1 is my ...


39

The simple way to achieve distinct values in a view is to make the following: Go and edit your view In Advanced » OTHER section click on "Query setting" Check "Distinct" check-box.


37

Basing on the code used by views_get_view_result(), I would use the following code, as code equivalent to the one you show in the question. $args = [$tid]; $view = Views::getView('test_view'); if (is_object($view)) { $view->setArguments($args); $view->setDisplay('block'); $view->preExecute(); $view->execute(); $content =...


33

Views are available through configuration in Drupal 8, and can be exported via the Configuration Management interface. In the admin menu select "Configuration" in the DEVELOPMENT section, select "Configuration synchronization": In that menu area, the Export tab leads to the path: http://sitename/admin/config/development/configuration/single/export In that ...


32

I've done a little tweaking myself, and I seem to have gotten a working solution here. Create a new block for the nodes you'd like to display Add a new Contextual Filter: Content: Has Taxonomyterm-ID Select: "when the filter is not available, provide a default value: Taxonomyterm-ID from URL." Put a check next to "Load Standard Filter from node-page, useful ...


32

drupal_goto() accepts an $options parameter to be passed on to the url() function. You can pass a query string like this: $options = array('query' => array('foo' => 'bar')); drupal_goto('path', $options); That example will forward on to /path?foo=bar


32

As per the comment here http://drupal.org/node/458316#comment-6236984 In views 3.x you can use "Path" field with option "Use absolute link (begins with "http://")" in Rewrite results section.


30

Create a node view with the appropriate filters etc. you need to get the results you want to have in the reference field. Then in the top left under the heading "Displays", Click "Add" and then select "Entity reference". Then that display will be available to your field. Edit: It doesn't have to be a node view, if you are referencing other entity types.


30

I have just found the answer to this question via Drupal.org. You have to use a URI like this: public://user_pictures/default.png in your account settings. Here, public:// stands for your public files location (often sites/default/files/). What comes after that, is the location of your image within public files. If you do this, the default image is ...


29

Let's say you have field A, and field B. Make sure A, comes before B in the fields list. Edit field A, and check "Exclude from display". The field will now no longer show up. Edit field B, find the checkbox for "Re-write the output of this field". Below the new textbox, find "Replacement patterns." There you should now be able to find something that looks ...


28

If the user you are logged in has the Administer Views permission, if not then give this permission. Also enable the 'PHP filter' core module. Give the relevant user role the Use PHP for settings permission. Paste the below url after your current url and you will see the import views page. admin/structure/views/import


28

This took me a while to figure out as well. The following code should be placed in your .module file (the code assumes your module is called "NAME") /** * Implements hook_views_api(). * * Enabling using templates inside module */ function NAME_views_api() { return array( 'api' => 3, 'path' => drupal_get_path('module', 'NAME'), 'template ...


27

Install the Multilingual modules in admin/modules Go to admin/config/regional/language and add the new language Go to edit your View and click in Translate Then click in edit And go to edit the title


26

I think your requirements can be restructured into the following: Show all content once. Show the content in the current language, fall back to the other. Then it becomes pretty easy: Add the "Default Translation" filter to a view. That basically ensures that all your nodes are shown once because each node can only have one default translation. Select "...


26

Actually its easy. Just look at the implementation Views Global handlers which is available in views.views.inc. Below is the example how you can add field handler without having a table, Specify your custom handlers in hook_views_data like below, /** * Implements hook_views_data(). */ function my_module_views_data() { $data['custom']['table']['group'...


26

In Views Slideshow 7.x-3.0, you can find this option by selecting slideshow as your format and then clicking on settings. From there, you need to find the Action section and check "View Action Advanced Options", there you can choose how many items to display.


25

Go to you view and Exposed form style settings. (You can find it right side Advanced settings of the view) and check the 'Include reset button' option . You can also change the Reset button label. Find below.


25

as @Daphna mentioned and you can see here: drupal.org/node/1234862 you can use Content: Path field value as a token for the field you want to be linked to the content: add Content: Path field and in the configure field modal box check Exclude from display to hide this field from being displayed and rearrange fields so this field is above the field you want ...


25

Under advanced portion of view choose following **Exposed form** Exposed form style: Basic | Settings Then Choose autosubmit in Settings as shown below This will hide the Apply button and the select list to work directly on selecting an item, instead of clicking on the Apply button.


25

You can get access to the view object within hook_form_alter by accessing $form_state['view']. That allows you to identify a specific view: function mymodule_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'views_exposed_form') { $view = $form_state['view']; if ($view->name == 'my_view_machine_name' && $...


25

Your module needs to implement hook_views_data(). The example given in the hook documentation is for a table defined from the following SQL. CREATE TABLE example_table ( nid INT(11) NOT NULL, plain_text_field VARCHAR(32, numeric_field INT(11), boolean_field INT(1), timestamp_field INT(8), PRIMARY KEY(nid) ); function mymodule_views_data() { $...


23

I just had a similar issue (June 2014) with Views UI. The ajax interactions on the 'style settings' simply stopped working so click on 'customize field HTML' and nothing happened. Hence finding this post/tip. I went to the Modules/JQuery configurations screen (http://website.co.uk/#overlay=admin/config/development/jquery_update) and instructed the Admin ...


23

If you want to pass a parameter to the view use: echo views_embed_view('view_machine_name', 'block_1', $param); For example: echo views_embed_view('view_machine_name', 'block_1', $node->nid); or: echo views_embed_view('view_machine_name', 'block_1', $nid, $uid);


23

I figured out a way to do this with only the Views module. It's not perfect — it doesn't generate a nice URL and breadcrumb with the taxonomy lineage the way that my solution for a taxonomy of a single depth would do. Static Depth Browser For a taxonomy of static depth (where all terms have the same depth of child terms), you would do the following: ...


22

In Contextual filters select Add; in the dialog box that appears, select Global: Null. Click on Add and configure contextual filters. In the dialog box that appear next, in the fieldset When the filter value is available or a default is provided, check Specify validation criteria, select - Basic validation - for Validator, and select Show "Page not found" ...


21

I eventually got a solution from this. I followed the second primary solution offered although the blogger personally used hook_views_query_alter(). installed the module Views filters populate. added two filters "First Name" and "Last Name" (both must not be exposed) and added them to a OR filter group (Views 3 supports this). I had to use the operator "...


21

I had the same problem, then found a solution. I'll show you the details with screenshots. First enable Internationalization Views (i18nviews). Create your custom view. For example, I'll simply list the nodes related to Article content type. Add a header: Click on "add" next to Header section Add "Global: Text area" Type your header text, and select your ...


20

As you can see in views-view-unformatted.html.twig, it says what also the commented code you've shown says, there is no fields variable. Therefore, this template is not used for fields. Available variables: title: The title of this group of rows. May be empty. rows: A list of the view's row items. attributes: The row's HTML attributes. ...


20

The Term name converted to Term ID filter looks to be missing for D8 Views. One site-builder workaround, is to add a Relationship, Taxonomy terms on node then to add a Taxonomy Term: Name filter to Contextual Filters using the aforementioned relationship. Checking the Specify validation criteria checkbox, set your Validator to Taxonomy term name & ...


20

Views are configuration entities in Drupal 8, and can be exported via the Configuration Management module.


Only top voted, non community-wiki answers of a minimum length are eligible