How do (or should) two separate modules implement the same external library using the Libraries 2.x API? The Libraries module exists to make it easier for multiple modules to use the same library, but how is this actually done?

Do Module A and Module B both implement the library using hook_libraries_info() and hook_requirements()? If so, how do they avoid conflicting with each other? In my experience (trying to use Masonry API and Manual Crop modules), they conflict, even when both use the same namespacing, etc.

Or should a new module (Module C) be created that implements the library, and then Module A and Module B depend on Module C and use libraries_load()?

The Libraries module provides libraries_load which allows on-demand loading of libraries that are in sites/all/libraries. Libraries are defined by using hook_libraries_info.

It's a good idea to have a single module that defines hook_libraries_info() for a given library. For many modules, this is the primary module for Drupal. Take for instance Mailchimp or one of many commerce modules.

Alternatively, if you know that this module will be used by one or more modules that have no dependency on each other, you can define just a single module which defines the library and then have each module depend on that one.

As far as hook_requirements go, that is entirely up to you. I will say that if you do decide to put a requirement in each individual module, please namespace it. Lots of payment modules require the cURL extension and drop that requirement into $requirements['curl'] instead of $requirements['MYMODULE_curl'] this will cause a problem since requirements do not have an alter hook and a key collision will cause errors. So make sure you do the latter and not the former. However, if you're doing a single module, this wouldn't be a problem as you'd just do hook_requirements in it.


In webforms, how do I send the current user an email automatically? I'm trying to send an email to the logged in user who filled out the form without having them enter their email.

The form is made with webforms 8.x-5.x which has a lot of functionality.

I've only tried doing it non-programmatically through the interface by adding an email and using the "custom to email address" where i attempted to use the token: [current-user:mail] which did not work.

I've made a separate email handler for anonymous users, which just uses the email they fill in.

As @huelfe recommended, the token [webform-authenticated-user:mail] actually works for this purpose in the custom to email address.


Creating a fake JavaScript exposed filter in Drupal 7 Views module In this website I'm building there's a page with a Views list of people, divided into categories.
I've exposed a category filter and a name filter to visitors.

Since the list isn't long, I would like to show all the items on page load and use the exposed filters as "fake" filters. Those will not actually make a request to the database, but call a JavaScript function that will go through the list and hide the unwanted items using CSS.

I can create my own filters, but then the category filter will not auto update when a new category is created.
I've seen that I can use MYTHEME_preprocess_views_exposed_form hook to change it to how I want, but then the page will still download and run auto-submit.js, which is the CTools JS file that Views module uses for auto submitting. I can remove it with MYTHEME_js_alter, but it seems like a lot of effort - and mostly wasted computational time slowing the page load - for a simple task.

Does anyone know a better way to accomplish this? Am I just overreacting over a few lines of code?

Thanks guys, hope everything is clear.

EDIT:

About 5 seconds after posting I've realized that I could use auto-submit.js with the JavaScript too. So all I need to do is remove the action of the form and add onSubmit that'll point to my script.

Here is the solution I used:

I created a new module named "My Views' Client Side Filters".

In the module's .module file I added:

<?php

function my_views_client_side_filters_form_views_exposed_form_alter(&$form, &$form_state, $form_id)
{
    $form['#attributes']['onsubmit'] = 'return exposedFilterOnSubmit();';
    drupal_add_js('sites/all/themes/MY_THEME/js/MY_JS_FILE.js');
}

Which resulted in the HTML:

<form onsubmit="return exposedFilterOnSubmit();" action="MY FORM DESTINATION" method="get">

And sites/all/themes/MY_THEME/js/MY_JS_FILE.js:

function isEmpty(str) {
    return (str.length === 0 || !str.trim());
}
var departmentAllShown = true;
var nameAllShown = true;
(function ($) {
    function reloadNames(name) {
        $('.views-row').each(function() {
            if($(this).find('.doctors_view_row_title').text().toLowerCase().indexOf(name.toLowerCase()) >= 0)
                $(this).css('display','block');
            else
                $(this).css('display','none');
        });
        nameAllShown = false;
    }
    jQuery.extend({
        exposedFilterHider: function()
        {
            //Handle url (JavaScript only now enabled)
            if(!isEmpty(window.location.search))
                location = "MY_SITE_LOCATION/FORM_PAGE";

            var department = $('#edit-field-department-value')[0].value;
            var departmentIndex = $('#edit-field-department-value')[0].selectedIndex;
            var name = $('#edit-title')[0].value;

            var nameIsEmpty = isEmpty(name);

            if (departmentIndex != 0)
            {
                $('.item-list').each(function() {
                    if ($(this).children().first().text() === department)
                    {
                        $(this).css('display','block');
                        if (!nameIsEmpty)
                            reloadNames(name);
                        else
                            if (!nameAllShown)
                            {
                                $('.views-row').css('display','block');
                                nameAllShown = true;
                            }
                    }
                    else
                        $(this).css('display','none');
                });
                departmentAllShown = false;
            }
            else
            {
                //Enable all categories if not already
                if (!departmentAllShown)
                {
                    $('.item-list').css('display','block');
                    departmentAllShown = true;
                }

                if (!nameIsEmpty)
                    reloadNames(name);
                else //Enable all names if not already
                    if (!nameAllShown)
                    {
                        $('.views-row').css('display','block');
                        nameAllShown = true;
                    }
            }
        }
    });
})(jQuery);

function exposedFilterOnSubmit()
{
    jQuery.exposedFilterHider();
    return false;
}

Sorry I don't explain any further, I'm kind of stressed in time. If someone asks a specific question I promise to answer.

Hope this helps anyone!

BTW, although the code is a bit long it works spectacularly and runs swiftly.

Remember to change the classes! You might need to change things a bit since my layout may not be the same as yours.

My classes:

.views-row - Entire "person" row (The name container is somewhere inside and there are a few of those in every category)

.doctors_view_row_title - Name container

.item-list - The category container

Good luck guys!


Change Number of Values in CCK Filefield/Upload Using hook_form_alter(), how would I change the default of 1-10 then Unlimited, to 1-24 then Unlimited?  CCK Only gives 1-10 as options before going to Unlimited and I need to have 1-24.  I know this is possible using hook_form_alter() but I do not know the syntax of how to write that.

Any help is greatly appreciated!

/**
 * Implementation of hook_form_alter().
 */
function YOURMODULENAME_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'content_field_edit_form') {
    $form['field']['multiple']['#options'] = array(1 => t('Unlimited'), 0 => 1) + drupal_map_assoc(range(2, 24));
  }
}


Is there a way to create CSS image styles? Is there a way to assign css to image styles?

I don't see any drop down for custom...

Would be nice to add img-responsive style to ALL images on the site...

Is there a module that can do that? Shouldn't it be native functionality?

What you are looking for is considered theming and is done mainly in the theme's template.php file.

There is a guide available here: Add bootstrap image css class to pictures

<?php
/**
 *
 */
function THEMENAME_preprocess_image_style(&$vars) {
        $vars['attributes']['class'][] = 'img-responsive'; // http://getbootstrap.com/css/#overview-responsive-images
}
?>


Is there any template debugging technique similar to Twig debugging? David Rothstein pointed out in the comments that as of Drupal 7.33, this functionality has been back-ported to Drupal 7.

Is there any template debugging technique similar to Twig debugging?

As reported in Working with template suggestions, yes.

  As of Drupal 7.33, Drupal core has a theme debug mode that can be enabled and disabled via the theme_debug variable. Theme debug mode can be used to see possible template suggestions and the locations of template files right in your HTML markup (as HTML comments). To enable it, add this line to your settings.php:

$conf['theme_debug'] = TRUE;

As said in that page, you can use Drush to enable/disable it, respectively with drush vset theme_debug 1 and drush vset theme_debug 0.

After you set theme_debug to TRUE, the source of the page will appear as follows.

<!-- THEME DEBUG -->
<!-- CALL: theme('page') -->
<!-- FILE NAME SUGGESTIONS:
   * page--front.tpl.php
   * page--node.tpl.php
   x page.tpl.php
-->
<!-- BEGIN OUTPUT from 'modules/system/page.tpl.php' -->

<!-- END OUTPUT from 'modules/system/page.tpl.php' -->


Date vs Timestamp field-type My new project involves the requirement of manually setting a time of creation of nodes because they're looking into manually migrating parts of their old website into their new one. The date will mainly be used to sort the nodes, only 2 out of 6 content types will have the date printed in the frontend.

In D8 you can select between a date and timestamp field. Both output options seem to be the same. The only difference I noticed is the HTML output.

The timestamp output looks like this

Mon, 03/18/2019 - 18:00

Date output looks like that

<time datetime="2019-03-18T18:00:17Z" class="datetime">Mon, 03/18/2019 - 18:00</time>

I found a documentation page for D7 on the matter: https://www.drupal.org/node/1455576 but I have the feeling that this information doesn't apply for those two field types in D8.

Which one should I choose for this purpose? And what's the difference in D8 between those two field types?

In Drupal 8, timestamps (and created and updated) are stored as integers in the database.  They do not use the native datatype.  Timestamps can be added via the UI, but created and updated can only be used as basefields.

Datetime and daterange fields are stored as ISO strings: date-only as Y-m-d and date+time as the full ISO8601 format (currently without the UTC offset).  These are store as plain strings, not as a native type, since the date/time handling in the default database backends is not portable.

The reason you are seeing different HTML, is that the two field types use different formatters.  Your timestamp is using TimestampFormatter and it looks like your datetime is using DatetimeDefaultFormatter.  It is possible to get both fields to output the same if you use the DatetimePlainFormatterformatter. You can also write your own formatter for timestamps to output HTML5 time.  For various reasons, they formatters between the two types are different.


Custom module update with project status url My .info file is the following.

name = {some_name}
description = This will contain all {some_name} related information
package = {Package_name}
core = 7.x

; Information added by Drupal.org packaging script on 2014-10-03
version = "7.x-1.1"
core = "7.x"
project = "{project_name}"
project status url=http://domain.com/{project_name}/7.0/sub_module
datestamp = "1432104957"

I uploaded the sub_module.zip and the sub_module.tar.gz files, as well as the sub_module folder to the above project status URL, with .info version set to 7.x.2.1.

Still I'm not getting any updates for my custom module.
Can anyone help me with this?

The project status URL you provided in the .info file is wrong: It should be http://domain.com, in the same way for Drupal.org that URL is http://updates.drupal.org/. A Drupal site will then access (in your case) http://domain.com/{project_name}/{drupal_version} to verify the module needs to be updated.
http://domain.com/{project_name}/{drupal_version} needs to return XML data listing all the versions available for that project and that Drupal version.

To make an example with a project hosted on Drupal.org, the list of all the versions available for Drupal 7.x of the Views module is returned from http://updates.drupal.org/release-history/views/7.x, which returns the following.

<?xml version="1.0" encoding="utf-8"?>
<project xmlns:dc="http://purl.org/dc/elements/1.1/">
<title>Views</title>
<short_name>views</short_name>
<dc:creator>merlinofchaos</dc:creator>
<type>project_module</type>
<api_version>7.x</api_version>
<recommended_major>3</recommended_major>
<supported_majors>3</supported_majors>
<default_major>3</default_major>
<project_status>published</project_status>
<link>https://www.drupal.org/project/views</link>
<terms><term><name>Projects</name><value>Modules</value></term><term><name>Maintenance status</name><value>Seeking co-maintainer(s)</value></term><term><name>Development status</name><value>Under active development</value></term></terms>
<releases>
<release><name>views 7.x-3.16</name><version>7.x-3.16</version><tag>7.x-3.16</tag><version_major>3</version_major><version_patch>16</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.16</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.16.tar.gz</download_link><date>1491158584</date><mdhash>d840cb148809da844b93d73b16b453f9</mdhash><filesize>1643030</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.16.tar.gz</url><archive_type>tar.gz</archive_type><md5>d840cb148809da844b93d73b16b453f9</md5><size>1643030</size><filedate>1491158584</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.16.zip</url><archive_type>zip</archive_type><md5>58da4a76b03278e613f8298e69f761c6</md5><size>1913513</size><filedate>1491158584</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.16-rc1</name><version>7.x-3.16-rc1</version><tag>7.x-3.16-rc1</tag><version_major>3</version_major><version_patch>16</version_patch><version_extra>rc1</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.16-rc1</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.16-rc1.tar.gz</download_link><date>1489763584</date><mdhash>cba59381dbf64ac9d9d76fa549b4c7c1</mdhash><filesize>1642814</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.16-rc1.tar.gz</url><archive_type>tar.gz</archive_type><md5>cba59381dbf64ac9d9d76fa549b4c7c1</md5><size>1642814</size><filedate>1489763584</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.16-rc1.zip</url><archive_type>zip</archive_type><md5>460ed4581a0a7680fad79e1c124cedc3</md5><size>1913275</size><filedate>1489763584</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security>RC releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.15</name><version>7.x-3.15</version><tag>7.x-3.15</tag><version_major>3</version_major><version_patch>15</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.15</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.15.tar.gz</download_link><date>1487784184</date><mdhash>473cb5384456d55af988feabc1af12ed</mdhash><filesize>1642425</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.15.tar.gz</url><archive_type>tar.gz</archive_type><md5>473cb5384456d55af988feabc1af12ed</md5><size>1642425</size><filedate>1487784184</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.15.zip</url><archive_type>zip</archive_type><md5>d22aa50667d4905a6b954c58d7c29832</md5><size>1913348</size><filedate>1487784184</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.14</name><version>7.x-3.14</version><tag>7.x-3.14</tag><version_major>3</version_major><version_patch>14</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.14</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.14.tar.gz</download_link><date>1466019539</date><mdhash>168bb684c8f34297be94b03c797841e5</mdhash><filesize>1656594</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.14.tar.gz</url><archive_type>tar.gz</archive_type><md5>168bb684c8f34297be94b03c797841e5</md5><size>1656594</size><filedate>1466019539</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.14.zip</url><archive_type>zip</archive_type><md5>b8ee0f4278b2f67e4d10997dc2a05ec4</md5><size>1913123</size><filedate>1466019539</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.13</name><version>7.x-3.13</version><tag>7.x-3.13</tag><version_major>3</version_major><version_patch>13</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.13</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.13.tar.gz</download_link><date>1446804839</date><mdhash>50d3b231f689f8c4ff15d79ea3c261d9</mdhash><filesize>1650157</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.13.tar.gz</url><archive_type>tar.gz</archive_type><md5>50d3b231f689f8c4ff15d79ea3c261d9</md5><size>1650157</size><filedate>1446804839</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.13.zip</url><archive_type>zip</archive_type><md5>d30756ba6b3489fd919ddd359f5decad</md5><size>1900939</size><filedate>1446804839</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.12</name><version>7.x-3.12</version><tag>7.x-3.12</tag><version_major>3</version_major><version_patch>12</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.12</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.12.tar.gz</download_link><date>1446653339</date><mdhash>a50033bb090730176d9263ddae7f32b2</mdhash><filesize>1650130</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.12.tar.gz</url><archive_type>tar.gz</archive_type><md5>a50033bb090730176d9263ddae7f32b2</md5><size>1650130</size><filedate>1446653339</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.12.zip</url><archive_type>zip</archive_type><md5>56beb9d18dcc252ca77834f52b9050d1</md5><size>1900868</size><filedate>1446653339</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.11</name><version>7.x-3.11</version><tag>7.x-3.11</tag><version_major>3</version_major><version_patch>11</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.11</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.11.tar.gz</download_link><date>1430320981</date><mdhash>00d722e1d8ed57e912c8bd586cf2edbe</mdhash><filesize>1649389</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.11.tar.gz</url><archive_type>tar.gz</archive_type><md5>00d722e1d8ed57e912c8bd586cf2edbe</md5><size>1649389</size><filedate>1430320981</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.11.zip</url><archive_type>zip</archive_type><md5>448b10631be9423948f4bad59d269593</md5><size>1899261</size><filedate>1430320981</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.10</name><version>7.x-3.10</version><tag>7.x-3.10</tag><version_major>3</version_major><version_patch>10</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.10</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.10.tar.gz</download_link><date>1423648081</date><mdhash>c9806ffd69448bc505a67e790f97da58</mdhash><filesize>1648314</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.10.tar.gz</url><archive_type>tar.gz</archive_type><md5>c9806ffd69448bc505a67e790f97da58</md5><size>1648314</size><filedate>1423648081</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.10.zip</url><archive_type>zip</archive_type><md5>45246351588a7f9f74a7d8ba1e0554f4</md5><size>1897924</size><filedate>1423648081</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.8</name><version>7.x-3.8</version><tag>7.x-3.8</tag><version_major>3</version_major><version_patch>8</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.8</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.8.tar.gz</download_link><date>1400618927</date><mdhash>0fbe71c455f5d34c7193797563b63b3f</mdhash><filesize>1646817</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.8.tar.gz</url><archive_type>tar.gz</archive_type><md5>0fbe71c455f5d34c7193797563b63b3f</md5><size>1646817</size><filedate>1400618927</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.8.zip</url><archive_type>zip</archive_type><md5>c1a997653b21943a86bcd42f5c803403</md5><size>1886165</size><filedate>1400618927</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term><term><name>Release type</name><value>New features</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.7</name><version>7.x-3.7</version><tag>7.x-3.7</tag><version_major>3</version_major><version_patch>7</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.7</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.7.tar.gz</download_link><date>1365499237</date><mdhash>3f36f0d13f3b724d719f6729cbc110ba</mdhash><filesize>1639539</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.7.tar.gz</url><archive_type>tar.gz</archive_type><md5>3f36f0d13f3b724d719f6729cbc110ba</md5><size>1639539</size><filedate>1365499237</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.7.zip</url><archive_type>zip</archive_type><md5>c764bcc139e3698b24f4bfcc531542e4</md5><size>1878608</size><filedate>1365499237</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.6</name><version>7.x-3.6</version><tag>7.x-3.6</tag><version_major>3</version_major><version_patch>6</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.6</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.6.tar.gz</download_link><date>1363810217</date><mdhash>1531a1ece3970332db1559b854f5dcc9</mdhash><filesize>1639219</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.6.tar.gz</url><archive_type>tar.gz</archive_type><md5>1531a1ece3970332db1559b854f5dcc9</md5><size>1639219</size><filedate>1363810217</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.6.zip</url><archive_type>zip</archive_type><md5>0d7c7de301caa52670869060e22d1ef3</md5><size>1878465</size><filedate>1363810217</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.5</name><version>7.x-3.5</version><tag>7.x-3.5</tag><version_major>3</version_major><version_patch>5</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.5</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.5.tar.gz</download_link><date>1345829395</date><mdhash>fba70998d4ebcca5116ef5ee90117738</mdhash><filesize>1632919</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.5.tar.gz</url><archive_type>tar.gz</archive_type><md5>fba70998d4ebcca5116ef5ee90117738</md5><size>1632919</size><filedate>1345829395</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.5.zip</url><archive_type>zip</archive_type><md5>8b1102f6cd54949eee147c63c4fd352b</md5><size>1866348</size><filedate>1345829395</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.4</name><version>7.x-3.4</version><tag>7.x-3.4</tag><version_major>3</version_major><version_patch>4</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.4</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.4.tar.gz</download_link><date>1345559303</date><mdhash>72bd0f35ac467aed74e533c10a76c93f</mdhash><filesize>1632803</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.4.tar.gz</url><archive_type>tar.gz</archive_type><md5>72bd0f35ac467aed74e533c10a76c93f</md5><size>1632803</size><filedate>1345559303</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.4.zip</url><archive_type>zip</archive_type><md5>0e92dc862bea87904d507af72e710af7</md5><size>1866193</size><filedate>1345559303</filedate></file></files><terms><term><name>Release type</name><value>New features</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.3</name><version>7.x-3.3</version><tag>7.x-3.3</tag><version_major>3</version_major><version_patch>3</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.3</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.3.tar.gz</download_link><date>1329946249</date><mdhash>70f24086dc7acfa7fc23c6148c7f8e00</mdhash><filesize>1583249</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.3.tar.gz</url><archive_type>tar.gz</archive_type><md5>70f24086dc7acfa7fc23c6148c7f8e00</md5><size>1583249</size><filedate>1329946249</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.3.zip</url><archive_type>zip</archive_type><md5>e8b5f8d4de7526d2919993bb3a34c0bf</md5><size>1803054</size><filedate>1329946249</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.2</name><version>7.x-3.2</version><tag>7.x-3.2</tag><version_major>3</version_major><version_patch>2</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.2</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.2.tar.gz</download_link><date>1329778551</date><mdhash>c350603991445ca69b30eddf3befe887</mdhash><filesize>1582617</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.2.tar.gz</url><archive_type>tar.gz</archive_type><md5>c350603991445ca69b30eddf3befe887</md5><size>1582617</size><filedate>1329778551</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.2.zip</url><archive_type>zip</archive_type><md5>641a7c36bc39d5c17b997ff5babf6d47</md5><size>1801836</size><filedate>1329778552</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.1</name><version>7.x-3.1</version><tag>7.x-3.1</tag><version_major>3</version_major><version_patch>1</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.1</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.1.tar.gz</download_link><date>1326750948</date><mdhash>e158435dc66d1d89a0df587c39ef1a23</mdhash><filesize>1575585</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.1.tar.gz</url><archive_type>tar.gz</archive_type><md5>e158435dc66d1d89a0df587c39ef1a23</md5><size>1575585</size><filedate>1326750948</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.1.zip</url><archive_type>zip</archive_type><md5>43999fc1888c1aa88f1d20288aace84c</md5><size>1792932</size><filedate>1326750949</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.0</name><version>7.x-3.0</version><tag>7.x-3.0</tag><version_major>3</version_major><version_patch>0</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0.tar.gz</download_link><date>1324170451</date><mdhash>1be8cbd6fd3f37bfd1493693dfa95d8d</mdhash><filesize>1461460</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0.tar.gz</url><archive_type>tar.gz</archive_type><md5>1be8cbd6fd3f37bfd1493693dfa95d8d</md5><size>1461460</size><filedate>1324170451</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0.zip</url><archive_type>zip</archive_type><md5>99769e8808519ae36171fa619cf00997</md5><size>1672723</size><filedate>1324170451</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.0-rc3</name><version>7.x-3.0-rc3</version><tag>7.x-3.0-rc3</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>rc3</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-rc3</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc3.tar.gz</download_link><date>1321467945</date><mdhash>b3e58f4195308e37621155d3c843e53f</mdhash><filesize>1456218</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc3.tar.gz</url><archive_type>tar.gz</archive_type><md5>b3e58f4195308e37621155d3c843e53f</md5><size>1456218</size><filedate>1321467945</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc3.zip</url><archive_type>zip</archive_type><md5>502f84cfadb4bf4744b6c452fc01f2d6</md5><size>1665759</size><filedate>1321467946</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security>RC releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.0-rc1</name><version>7.x-3.0-rc1</version><tag>7.x-3.0-rc1</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>rc1</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-rc1</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc1.tar.gz</download_link><date>1308341221</date><mdhash>e158db78ae2f8cc615edb910a09384b0</mdhash><filesize>1481151</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc1.tar.gz</url><archive_type>tar.gz</archive_type><md5>e158db78ae2f8cc615edb910a09384b0</md5><size>1481151</size><filedate>1308341221</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc1.zip</url><archive_type>zip</archive_type><md5>941111b41371084230bc82374ebcae19</md5><size>1682522</size><filedate>1308341221</filedate></file></files><terms><term><name>Release type</name><value>New features</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security>RC releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.0-beta3</name><version>7.x-3.0-beta3</version><tag>7.x-3.0-beta3</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>beta3</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-beta3</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta3.tar.gz</download_link><date>1301301971</date><mdhash>114c76f201523ef3e50b9a1d431b0364</mdhash><filesize>1469580</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta3.tar.gz</url><archive_type>tar.gz</archive_type><md5>114c76f201523ef3e50b9a1d431b0364</md5><size>1469580</size><filedate>1301301971</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta3.zip</url><archive_type>zip</archive_type><md5>d69e051c8b4fa2066575c28e3ae197ba</md5><size>1671930</size><filedate>1301301971</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security>Beta releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.0-beta2</name><version>7.x-3.0-beta2</version><tag>7.x-3.0-beta2</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>beta2</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-beta2</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta2.tar.gz</download_link><date>1301158871</date><mdhash>c39fab1e76e55b15291fecf2c10386c2</mdhash><filesize>1469243</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta2.tar.gz</url><archive_type>tar.gz</archive_type><md5>c39fab1e76e55b15291fecf2c10386c2</md5><size>1469243</size><filedate>1301158871</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta2.zip</url><archive_type>zip</archive_type><md5>cd30442906e8d9e9bffc7ea8b28f3702</md5><size>1671405</size><filedate>1301158871</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security>Beta releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.0-beta1</name><version>7.x-3.0-beta1</version><tag>7.x-3.0-beta1</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>beta1</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-beta1</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta1.tar.gz</download_link><date>1301099796</date><mdhash>6ee4495cbdf0a8d19bd214f57bef0bf4</mdhash><filesize>1468892</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta1.tar.gz</url><archive_type>tar.gz</archive_type><md5>6ee4495cbdf0a8d19bd214f57bef0bf4</md5><size>1468892</size><filedate>1301099796</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta1.zip</url><archive_type>zip</archive_type><md5>36acc8675052e2dcb0c933e1ac8eab1d</md5><size>1670997</size><filedate>1301099796</filedate></file></files><terms><term><name>Release type</name><value>New features</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security>Beta releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.0-alpha1</name><version>7.x-3.0-alpha1</version><tag>7.x-3.0-alpha1</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>alpha1</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-alpha1</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-alpha1.tar.gz</download_link><date>1294276882</date><mdhash>8635e5b0c03fed4516abae25489a5a5c</mdhash><filesize>1561161</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-alpha1.tar.gz</url><archive_type>tar.gz</archive_type><md5>8635e5b0c03fed4516abae25489a5a5c</md5><size>1561161</size><filedate>1294276882</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-alpha1.zip</url><archive_type>zip</archive_type><md5>f5ffc235849f2a3a5f66b66f84a73aac</md5><size>1772425</size><filedate>1294276882</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security>Alpha releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.x-dev</name><version>7.x-3.x-dev</version><tag>7.x-3.x</tag><version_major>3</version_major><version_extra>dev</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.x-dev</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.x-dev.tar.gz</download_link><date>1491154383</date><mdhash>b8b158ae6a7c9f4e84540fbfcfa83ee3</mdhash><filesize>1643061</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.x-dev.tar.gz</url><archive_type>tar.gz</archive_type><md5>b8b158ae6a7c9f4e84540fbfcfa83ee3</md5><size>1643061</size><filedate>1491154383</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.x-dev.zip</url><archive_type>zip</archive_type><md5>db78a5499cda151d5a352a908adf7e6b</md5><size>1913538</size><filedate>1491154383</filedate></file></files><security>Dev releases are not covered by Drupal security advisories.</security></release></releases>
</project>

To make it short:

You need to change the project update URL reported in the .info file of the module (e.g. http://domain.com)
The server, on http://domain.com/release-history/{project_name}/{drupal_version}, needs to return XML data that describe all the project versions available and compatible with the Drupal version reported as last part of the URL (e.g. 7.x for Drupal 7, 8.x for Drupal 8)


Migrate a filefield to another filefield? I'm using Drupal 7. I have a field called field_a which is a file-field and want to create another file-field called field_b. What I want to do is to migrate all the files from field_a to field_b, then I also want to erase the records from field_a without erasing field_a. Note that field_a and field_b are in the same content type.

Is it possible? Is there a way to do this with VBO?

The best way to do this without writing a module or messing with your database is to use views bulk operations with rules.

Here is an example of moving a file from one file field to another.  You'll have to change the field names before you import this rule.

Basically add a rules component- then add your conditions and action

Variables

Datatype Node

Usage Parameter

Conditions

Entity has field - field_a

Entity has field - field_b

Actions

Create a loop to loop over multiple values in field_a.

Inside loop add item to list

Inside same loop remove item from list

Outside of loop Save your node.

{ "rules_fa_fb" : {
    "LABEL" : "Move resource files from one field to another.",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "TAGS" : [ "Dev" ],
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "nodes" : { "label" : "nodes", "type" : "node" } },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "nodes" ], "field" : "field_field_a" } },
      { "entity_has_field" : { "entity" : [ "nodes" ], "field" : "field_field_b" } }
    ],
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "nodes:field-field-b" ] },
          "ITEM" : { "file" : "files" },
          "DO" : [
            { "list_add" : {
                "list" : [ "nodes:field-field-a" ],
                "item" : [ "file" ],
                "unique" : 1
              }
            },
            { "entity_save" : { "data" : [ "resource" ], "immediate" : "1" } },
            { "list_remove" : { "list" : [ "nodes:field-field-a" ], "item" : [ "file" ] } }
          ]
        }
      },
      { "entity_save" : { "data" : [ "nodes" ], "immediate" : 1 } }
    ]
  }
}

Then create the view with a bulk operations field, you'll need to change some values to import into your system.

$view = new view();
$view->name = 'move_files_from_on_field_to_another';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Move files from on field to another';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Move files from on field to another';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Field: Bulk operations: Content */
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'node';
$handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '0';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
  'action::node_assign_owner_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_delete_item' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_delete_revision' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_script_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::flag_node_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_make_sticky_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_make_unsticky_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_modify_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
    'settings' => array(
      'show_all_tokens' => 1,
      'display_values' => array(
        '_all_' => '_all_',
      ),
    ),
  ),
  'rules_component::rules_fa_fb' => array(
    'selected' => 1,
    'postpone_processing' => 0,
    'skip_confirmation' => 1,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_argument_selector_action' => array(
    'selected' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
    'settings' => array(
      'url' => '',
    ),
  ),
  'action::node_promote_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_publish_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_unpromote_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_save_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::system_send_email_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::redhen_fields_email_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_unpublish_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_unpublish_by_keyword_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::auto_entitylabel_entity_update_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::pathauto_node_update_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
);
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Content: Files - for digital */
$handler->display->display_options['fields']['field_resource_file']['id'] = 'field_resource_file';
$handler->display->display_options['fields']['field_resource_file']['table'] = 'field_data_field_resource_file';
$handler->display->display_options['fields']['field_resource_file']['field'] = 'field_resource_file';
$handler->display->display_options['fields']['field_resource_file']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_resource_file']['delta_offset'] = '0';
/* Field: Content: Files - for print */
$handler->display->display_options['fields']['field_files_for_print']['id'] = 'field_files_for_print';
$handler->display->display_options['fields']['field_files_for_print']['table'] = 'field_data_field_files_for_print';
$handler->display->display_options['fields']['field_files_for_print']['field'] = 'field_files_for_print';
$handler->display->display_options['fields']['field_files_for_print']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_files_for_print']['delta_offset'] = '0';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'resource' => 'resource',
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'admin/move-files-from-on-field-to-another';


Getting node view mode in field preprocess I am trying to get the view mode of a node to use it in a field twig file by writing this function in my_theme, but it doesn't work:

function MY_THEME_preprocess_field(&$variables, $hook) {
 if ($node = \Drupal::routeMatch()->getParameter('node')) {
  $variables['view_mode_2'] = $node->view_mode;
 }
}

I don't know if the variable is correct, but when I write some echo code I see that already the if condition isn't fulfilled.

EDIT: the if condition is only fulfilled when the node is open, but not when its teaser is shown as part of a view on the front page.

In a field template the view mode is stored here:

$variables['element']['#view_mode']

So you could check in preprocess, if the node is not displayed as teaser:

function MY_THEME_preprocess_field(&$variables) {
  if ($variables['element']['#view_mode'] != 'teaser')  {
    // node is not displayed on the front page
  }
}

The same condition in a field twig:

field.html.twig

{% if element['#view_mode'] != 'teaser' %}
  node is not displayed on the front page
{% endif %}


Ubercart particular item has extra shipping fee domestic vs international I am using Ubercart 2.9 with Drupal 6.

Is there a way to add an extra fee to a certain product that has one value for domestic and a different value for international?

You can try UC Multiprice

  This module allows you to set a different product pricing for each
  enabled country in Ubercart. It also got support for roles, currencies
  and i18n

Its only in dev version use at your own risk.


In add filter criteria "user" not coming from FILTER list in add views I am following the book "The Definitive Guide to Drupal 7" where I am trying to add a new view. But when I tried to add filter,I can't find the User in the FILER list . I am very beginner to Drupal,though I know PHP .

It depends on what kind of view you're creating. You are probably working on a view for content. So the filters are limited to those related to content. You can add a relationship "Content: Author" (Relate content to the user who created it.) under "Advanced Options" to add more filter criteria to the filter criteria list (User will show up in the filter list then, too).

Or you try creating a view for users.


How to Ajaxify a Drupal 7 Views block I have a custom content type, with an associated block, which all displays correctly.
The block is initially hidden, upon clicking a button the block is moved into view, and the user is able to scroll horizontally through each content item.

Each content item contains an image, so I am interested in preventing them from being loaded initially, and only when the button is clicked (in order to reduce initial loading time).

I don't suppose there is a Drupal way of doing this?
The only way I can think of is making direct calls to the database, which I don't want to do for obvious reasons.

I noticed a "Use Ajax" option in the Views interface, however I wouldn't have thought this would work with my custom jQuery code?

You might try the Lazy Image Loader.  I'm not sure if it will work for your case, but it's worth a shot.  You can also implement the lazy behavior yourself.  Use javascript to test the "complete" property of each image, and change the src attribute on any image that currently hidden from view.  When it becomes visible, swap in the original src.  I've seen good results with this script: http://www.appelsiini.net/projects/lazyload.


How to get Google Analytics to track progress through a multi-page Drupal Webform? I've got a couple of complex multipage webforms, and want to track progress through these forms so that I can how much time users are spending on each page, and whether there are particular pages that cause users to drop out altogether. I thought Google Analytics could do the trick, but it seems to require a unique URL for each page, and that's something that the Webform module doesn't provide.

Has anyone got this to work, and if so how?

if the url doesn't change, you can use google's single page applications approach to track:

https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications

You can set a "virtual" url for each page using javascript. Then create a goal funnel in Google Analytics using these virtual url's. You'll probably need to custom write this js to look for specific fields etc to let it know which page it's on.

I think another way is to use custom fields in the call to ga. Not sure if those are available as goals though.


Running triggered rules actions in the background? I am using triggered rules to set off potentially lengthy actions on nodes, e.g. automatic node translation using Google Translate. Running those actions during the node creation page request slows down the response and potentially uses up server resources.

Instead, I'd like to enqueue the actions, so that they may be executed during the next cron run, or via the Queue API. Is there a known way to achieve this? Is it possible to do that using Rules Scheduler?

Turns out you can use Rules Scheduler for this. Here's the recipe:

Create an action set with the actions to run in the background
Add the action "Schedule component evaluation" to your trigger, choosing the action set you created above
Set the "Scheduled evaluation date" to now

When your trigger fires, its actions will be called at the next cron run. That was simple!


How to create a raw link in view(with contexual filter) custom text I am creating a block in view.
I have a content type with a field(plain text).
I am passing contexual filter "content id" from url.

I am giving value in the fields as "www.facebook.com/SomePage"
Now i want that to be created as link text from custom text in views.

In custom text i am providing

    Click Here

Now when i click here it is redirecting me to "[sitename]/node/www.facebook.com/SomePage"

I want to open like www.facebook.com/SomePage.

How to do.
Any suggestion?

I'd rather add a 'Custom text' field to the view, give it some text ("Click here"), and under "Rewrite Results" check "Output this field as a custom link", link path is {{ field_abc }} and then check "External server URL"


Is a node linked in any Panel (Drupal 7)? Is there a way in Drupal 7 to find out if a specific node is used in any panel of any page?

Would be helpful to prevent my editors from deleting content when it's still needed in some other part of the page.

You are looking for something along the lines of file_usage_list() I guess. I also assume that you are interested in the "Add content > Existing node" functionality of Panels.

You could implement your own function, with the following code:

function _panels_node_usage_list() {
  $result = db_query(
    "SELECT * FROM {panels_pane} WHERE type = 'node' AND subtype = 'node'"
  );
  $node_usage_list = array();
  foreach ($result as $pane) {
    $pane_configuration = unserialize($pane->configuration);
    $node_usage_list[$pane_configuration['nid']]++;
  }
  return $node_usage_list;
}

and then call this function from your own implementation of hook_node_access() where you can check if the nid of the node to be deleted is in the array returned by _panels_node_usage_list().

Good luck!


How can I keep the current language prefix for internal link? If the links are menu items the destinations of the links are always with the language inherited from the previous pages. But how can I do the same thing for the internal links using ordinal  tags?  I have some internal links in some blocks but those links can't keep the language prefix the use is currently viewing of.
For example:

 takes the user to my-site.com/about-us though the user is currently viewing the page with the language prefix "jp" which is Japanese. But I would like to make the destination of the link to my-site.com/jp/about-us.

I've been searching for the solution for days but no luck so far. I have tried pathfilter and pathologic but they don't seem to work for this purpose.

Generally you want to use Drupal core functions as much as possible. Both the l() and url() functions fit perfectly your need. The difference between them is that l() returns an anchor tag, and url() returns a URL without HTML.

As a perk, the l() function allows you to specify the language for the link. Example:

<?php
$options = array('language' => 'jp');
$link = l('About Us', 'about-us', $options);


Is it possible to preserve image quality when uploading images? Is it possible to preserve image quality when uploading images through Drupal7?

For example, I take this image:
http://f.cl.ly/items/0L3j21030C3O2A3x2w0b/thumb.jpg

I upload it using an Imagefield, which has no min/max resolution set, and it looks like this:
http://f.cl.ly/items/2B2q2a1H402T1Z1j3w2j/baboon-onesie-costume-thumb.jpeg

So already we're seeing a loss in quality. Then it's displayed using a view, which scales the image (which it should do IF) it's larger than 190x280 (which it isn't), and now it looks like:
http://f.cl.ly/items/2n023q1Q331J3E2d3a3I/baboon-onesie-costume-thumb-1.jpeg

The quality difference is massive - there's a huge loss of colours and severe artefact creation around the image edges.

The GD image settings are JPEG quality: 100%.

Is there anything that can be done to prevent this ridiculous loss of quality?

There's two solutions to this. The easiest is:

Upload images with a "jpeg" extension instead of a "jpg" extension. For whatever reason, images with a jpeg extension are not mangled by Drupal.

However, the best solution if you have control over your hosting environment is:

Install the imagemagick module.


header and menu is missing from Login module page--user--login.tpl.php I am implementing Custom Login module but Header is missing...

My Directory is :

modules
  |
  --- module_name
          |
          --- css
          |
          --- module_name.info
          |
          --- module_name.module
          |
          --- templates

module_name.module contains :

function module_name_form_alter(&$form, &$form_state, $form_id) {
    if ($form_id == 'user_login') {
        $form['name']['#attributes']['autofocus'] = 'autofocus';
        $form['name']['#attributes']['placeholder'] = t('Email');
        $form['pass']['#attributes']['placeholder'] = t('Password');
        // We don't really need descriptions to tell us what we already know...
        unset($form['name']['#description']);
        unset($form['pass']['#description']);

        // $form['#attached']['css'][] = drupal_get_path('module', 'module_name') . '/css/login.css';
    }

    // We don't want to change page titles on other pages.
    // Array of arg(1) url values on target pages.
    $pages = array('login', 'password');
    if (!in_array(arg(1), $pages)) {
        return;
    }

    switch ($form_id) {
        case 'user_login':
            drupal_set_title(t('Login'));
            break;

        case 'user_pass':
            drupal_set_title(t('Forgot your password?'));
            break;
    }
}

/**
 * Implements hook_theme_registry_alter().
 */
function module_name_theme_registry_alter(&$theme_registry) {
    $mod_path = drupal_get_path('module', 'module_name');

    $theme_registry_copy = $theme_registry;
    _theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', '', $mod_path);
    $theme_registry += array_diff_key($theme_registry_copy, $theme_registry);

    $hooks = array('page');
    foreach ($hooks as $h) {
        if (!isset($theme_registry[$h]['theme paths'])) {
            $theme_registry[$h]['theme paths'] = array();
        }

        _module_name_insert_after_first_element($theme_registry[$h]['theme paths'], $mod_path);
    }
}

/**
 * Function responsible for inserting a new element after the first one.
 */
function _module_name_insert_after_first_element(&$a, $element) {
    if (is_array($a)) {
        $first_element = array_shift($a);
        if ($first_element) {
            array_unshift($a, $first_element, $element);
        }
        else {
            array_unshift($a, $element);
        }
    }
}

templates/page--user--login.tpl.php contains:

<?php print $title; ?>

    <?php print $messages; ?>
<?php print render($page['content']); ?>

Everything is ok, but Header and Menu is missing (as defined in my current theme) from HTML output (/user/login), any suggestion?

Your page--user--login.tpl.php is overriding the page.tpl.php. Print your header & menus regions/variables  in the file 'page--user--login.tpl.php'.


I need a way to automatically make Panel layouts responsive Before I asked this question I did a humble Google research for several times but I really couldn't find any efficient solution for this problem. I consider a working answer to be a grace with the community:

Until now, I haven't had many panels in my sites (say no more than 1-2 mini Panels + 1 panel page, per site). I made each Panel responsive by per block elements. I must say that could take some time and it's surly not an efficient solution when you have many panels in your site...

Therefore, I am looking for a way to automize this process - Instead of making any panel layout responsive manually, I need a way (maybe even a general CSS code piece if not a module) just to ensure my panel layouts will be responsive, and an example would be:

instead of width: 50%+50% or 33%+33%+33% float\text-align: right\left, all will be centered).

So, how can you to "Auto-responsify" all existing panels, including all panels to come, in a site?

I think the closest you're going to get to out of the box is Panels Extra layouts, which ships with a bunch of adaptive layouts.

Other than that, your best bet is just to create a bunch of custom layouts by yourself, with their respective templates. The documentation is not bad for that; you can find it here: Panels 3: Creating a custom layout in your theme. Alternatively, just look in the Panels codebase for their implementations.


Modal with content depending on opening hours I need the user to enter opening hours for their helpline in the CMS along with two sets of text, one that will be displayed if the user views it during their opening hours & another which is displayed outside of their opening hours.

This content needs to be displayed in a modal on specified pages when a link is clicked (a 'modal box' is like a JavaScript overlay on the page).

The way I have been trying to approach the problem (taken from a suggestion else where on Stack Exchange) was to use the Office Hours & Colorbox Node modules together. Unfortunately unless I've misunderstood what Colorbox Node does or how it works I cannot get it to open a modal at all, I can't actually get it to do anything.

Below are the steps I've taken to install the Office Hours & the Colorbox Node modules so hopefully someone can spot what I've done wrong. I am more than open to other suggestions to solve this problem though.

Using the two modules mentioned my plan was to create a custom template which would read the current date & time, compare it to what has been entered into the Office Hours module then display the appropriate text from one of two text area fields in the CMS.

Created fresh Drupal 7 install
Installed Office Hours 7.x-1.4 module (https://www.drupal.org/project/office_hours)

2a. Installed required module Date api 7.x-2.9 (https://www.drupal.org/project/date)
Installed Colorbox node 7.x-3.5 module (https://www.drupal.org/project/colorbox_node)

3a. Installed required module colorbox 7.x-2.10 (https://www.drupal.org/project/colorbox)

3b. Installed required module Libaries 7.x-2.2 (https://www.drupal.org/project/libraries)
Created new content type with the Office Hours field
Created new node setting the new office hours
Created test page with link to office hours page, link has class of "colorbox-node" which should show a modal?

This is what the link tag currently looks like:

Test link

if you run your site under an url like example.com/dat/fresh/site/, remove the first slash in the href, like:

Test link

or change to full path, like:

Test link


Custom DOM placement using AJAX I'm using unlimited image upload option in my content type. Upload image and remove the uploaded image options are working fine with the unlimited option.

Usually, the uploaded images will be displaying one by one (Last in Last - Image1, Image2, Image3,..ImageN). But, I need show the uploaded image at first/top place (Last in First - ImageN,..., Image3, Image2, Image1).

Can you please help me in this?

UPDATE:

PFA for bulk node edit page in admin section. I used image upload as nested objects (unlimited). You can see two nodes display in edit mode (Title 1 and Title 2).

New upload field should be add before the exiting uploaded image section when I click the "Add another item" button OR
Ok. It can display under the existing uploaded image section. But, the image should be reorder as per my above requirement when I click the "Upload" button.

Note: I saw some hook in ajax.js file that will handle the ajax process. But, I don't know, how it's help to solve my problem.

 *  Drupal.behaviors.myCustomAJAXStuff = {
 *      attach: function (context, settings) {
 *        Drupal.ajax['edit-submit'].commands.insert = function (ajax, response, status) {
 *          new_content = $(response.data);
 *          $('#my-wrapper').append(new_content);
 *          alert('New content was appended to #my-wrapper');
 *        }
 *      }
 *    };

I suggest you first create a View of the image files with node id passed as Contextual Argument. Make it display the images in the order you want and then add this View as a field using Viewfield


Why aren't the main menu and the secondary menu simply regions? I noticed that you can put content pretty much anywhere ( where a theme provides regions) using blocks.

This becomes pretty straight forward and makes sense. But then I was trying to find where the "My account" and "Logout" links came from. And after some searching I found out they are configured in the Menus -> Settings admin page.

Now I read the controversy about the misleading help text for the Source for the Secondary links, so this "special" behavior to display secondary links doesn't seem to work anymore in Drupal 7.

So my question is: Why are these "regions", treated separately at all ?

Why not have normal main menu and secondary menu regions ?

So after much research I found that the main menu and secondary menu settings are there for historical reasons. They had proper functionality in Drupal 5 but its usefulness has declined over the release of newer version ( 6 and 7 ) to the point where modern themes ignore them completely in favor of the powerful regions concept.

The included themes ( as others have mentioned ) have these special "regions" still just because no one cares to remove them.

The original idea was to have an easy way to present sub menu links ( secondary menu ) dependent on the what you select in the main menu.

The modern approach is to have a pop-out sub menu ( like Superfish ) this has made the secondary menu feature obsolete.

So much so in fact, that the functionality is broken and no one fixes it.

In summary, the feature is broken and obsolete. I hope someone removes it from Drupal 8.


How to reduce options for units of measurement to just miles and km for proximity search Using geofield with Views and exposed filters to the user to search for things on the map within a certain radius of a particular location.

I only require miles and kilometres as units of measurement, not: Yards, Feet, Nautical Miles. Any way to omit these?

They are defined in the module geofield's file, geofield.elements.inc code:

/**
 * Returns options for radius of the Earth.
 */

function geofield_radius_options() {
  return array(
    GEOFIELD_KILOMETERS => t('Kilometers'),
    GEOFIELD_METERS => t('Meters'),
    GEOFIELD_MILES => t('Miles'),
    GEOFIELD_YARDS => t('Yards'),
    GEOFIELD_FEET => t('Feet'),
    GEOFIELD_NAUTICAL_MILES => t('Nautical Miles'),
  );
}

But I don't want to hack this and remove them.

The approach I am expecting to use would be to implement hook_form_alter in my own module and remove the options from there.

But is there a better way?

Another approach is simply using CSS.

The select list is built like this:

<select>
  <option value="6371">Kilometres</option>
  <option value="6371000">Metres</option>
  <option value="3959">Miles</option>
  <option value="6975175">Yards</option>
  <option value="20925525">Feet</option>
  <option value="3444">Nautical Miles</option>
</select>

You could hide the undesired values with the following style (in this case only "kilometres" and "miles" remain):

option[value="6371000"],
option[value="6975175"],
option[value="20925525"],
option[value="3444"]{
  display: none;
}

If you're only using one value, it may look a bit silly to have a select box of it. You could disguise it as regular text though. Make sure the font is identical to the rest, remove the border, set a width to the container of the select list and hide everything seeping out of it, whilst making the select list a tad longer (thus the dropdown arrow gets hidden by the overflow):

.form-item-field-geofield-distance-unit{
    width: 90px;
    overflow: hidden;
}

select{
    width: 120px;
    border: 0;
    cursor: text;
}

Alternatively (Bootstrap 3):

.form-item-field-geofield-distance-unit select{
    border: 0 !important;
    box-shadow: none;
    cursor: text;
    -moz-appearance: none;
    -webkit-appearance: none;
    appearance: none;
}

Adjust the margins or paddings if necessary…


Content Type template override - Dash or Underscore? I am looking for some clarification on whether to use and underscore ("_") or a dash ("-") when creating a page template override for a content type. Some tutorials and articles say the format should use underscores such as ...

page--content_type_name.tpl.php

while others specify the format as dashes like ...

page--content-type-name.tpl.php

If my content type has a multi-word name how should the template override filename be formatted?

If you look at theme_get_suggestions(), there is a comment:

// When we discover templates in @see drupal_find_theme_templates,
// hyphens (-) are converted to underscores (_) before the theme hook
// is registered. We do this because the hyphens used for delimiters
// in hook suggestions cannot be used in the function names of the
// associated preprocess functions. Any page templates designed to be used
// on paths that contain a hyphen are also registered with these hyphens
// converted to underscores so here we must convert any hyphens in path
// arguments to underscores here before fetching theme hook suggestions
// to ensure the templates are appropriately recognized.

If you look at a preprocess, like template_preprocess_node(), you will see things like:

$variables['theme_hook_suggestions'][] = 'node__' . $node->type;

This is using the machine name of the content type directly, which is underscored.

-- is a delimiter between things, underscores are used within a thing.


Disable user registration for certain pattern of: IP address, name, mail I run a Drupal 7.10 / CentOS 6.2 website (where users can register after confirming their mail by clicking on a link) and there is a person registering at my site every night and then changing his name to obscene words.

First I've added a line to /etc/sysconfig/iptables to block his area:

-A INPUT -s 2.132.0.0/16 -j DROP

but this has blocked other users from that area (Alma-Ata city).

The pattern of this user is:

His IP address: strpos($_SERVER['REMOTE_ADDR'], '2.132.') === 0
His mail (changing every time): preg_match('/vlad.+@mail.ru/i', $mail)
His name (usually): stripos($name, 'st') !== FALSE

As you see - I have all the components there, I just need to know a good spot to put this code in. Anywhere to make his registration more difficult. An ideal case would be to sent  admin a mail for registration verification, but just bailing out of the registration script (which one is it please?) would be okay too.

Drupal 6 had the possibility of avoid specific usernames, email addresses, matching an SQL pattern match could be used from users, and avoid those users matching those conditions could log in. There was also a setting for avoiding users could be log in from specific IPs, which is the only part kept in Drupal 7.

The other part has been moved to a third-party module I maintain. Being the maintainer, I can tell you that I didn't recently commit code for User restrictions, which at the moment is not usable because the code needs to be fixed. I count to start committing the code I have developed in the previous months starting from tomorrow, if there is not something else that take me busy.
I actually need it in my website, which is running Drupal 7. I count to make the module as much generic as possible, and allow other modules to integrate with it through hooks; for example, the code I developed allows other modules to add rules that would be used to temporary block users.

For avoiding users would use specific usernames, there is also Ban List.

  Banlist allows the administrator to disallow users from using a username from a list of usernames. The list consist of usernames such as: admin, administrator, root, demo, test, superuser, etc.

  Although core can handle this, the primary purpose of the module is for people in the community to contribute to the list and make it very easy for everyone else to take advantage.


I don't want ajax submit / callback validate form '#required' => TRUE, I have form with static fields and dynamic fields as follow:

fieldset

textfield00 (require = true)
textfield01 (require = true)

fieldset

textfield02

fieldset

add textfield
submit button

so, everytime add textfield pressed, it will add new/duplicate textfield02.

with add textfield code as follow:

$form['fields']['modules']['add'] = array(
      '#type' => 'submit',
      '#name' => 'addtextfield',
      '#value' => t('Add more TextField'),
      '#submit' => array(array($this, 'addTextfieldSubmit')),
      '#ajax' => array(
        'callback' => array($this, 'addTextFieldCallback'),
        'wrapper' => 'wrapper',
        'effect' => 'fade',
      ),
    );

the adding field is working fine, the only problem i have here is: because textfield00 and textfield01 is mandatory, if i pressed add button, it will send me an error message 'mandatory fields' before i can add new textfield.

so how can i 'bypass' the requried validation, everytime i press add textfiled and only validate 'required = true' when i press submit button.

Thank You,
AnD

'#limit_validation_errors' => array();

$form['actions']['previous'] = array(
    '#type' => 'submit',
    '#value' => t('Previous'),
    '#limit_validation_errors' => array(
      // Validate $form_state->getValue('step1').
      array('step1'),
      // Validate $form_state->getValue(array('foo', 'bar')).
      array('foo', 'bar'),
    ),
    '#submit' => array('some_submit_function'), // #submit required.
  );


How to disable links in taxonomy term node fields I have a list of rendered taxonomy terms in a node sidebar, rendered as h2 tags, linked to the taxonomy page for that tid.  I don't want that term to link anywhere, so I want to remove the link and just leave a plain rendered h2 tag.

Where is the best place to do this?  It feels like a presentation change, so should I do it in a preprocess function?  It also feels like a functional thing, so should I remove the link within a hook somewhere?

How is the best Drupal-appropriate way to do this?

If I understand your question correctly you can change it on the 'Manage Display' tab of your content type, make sure to select 'Teaser' at the top right

If you're using the build in article type it is at admin/structure/types/manage/article/display/teaser


Link static HTML, Javascript and CSS3 in a Drupal Site I am trying to have collaborative development of a HTML5 web app which people could navigate too through my drupal site. I was planning on putting the html, JS and CSS3 files in my sites/default/files folder and just passing a link. I am curious how i perform to things

How can I put an alias over the html file so i can have url mysite/demo
also I want to block people from reading my JS and CSS3 files so the source code is just not purely out in the open is there a way to do this.

I know inspect html on most browsers give you a lot but I do not want them to find my .js file and then request that and have my source code.

Any assistance or guidance would be very helpful

I think the best option for what your describing is to take a screen shot of the site and use that; as an image will not display the html/css/js. https://www.drupal.org/project/phantomjs_capture is the project I would use; this is a very odd request so in order to achieve this you'll have to do some custom coding.

If your looking to obfuscate the JavaScript by minification AdvAgg can help but it's not setup to fully obfuscate the JS as it will point to the source file by default (for GPL compliance). This could be changed; if you do decide to go down this route open up a request in the advagg issue queue and I'll add in a hidden option to allow this to happen.


Best place to include javascript in a field formatter? I've created a custom field formatter using hook_field_formatter_info() and implemented it using hook_field_formatter_view().

My formatter requires additional javascript though and at the moment I'm including it in hook_field_formatter_view() but I have a feeling there's gotta be a better place to do this.

However there is no hook_field_formatter_preprocess() (there is a formatter_prepare_view() though but it doesnt't seem right)

Any ideas?

Adding the JavaScript in hook_field_formatter_view() works just fine. Just also be sure to use #attached and not drupal_add_js() since that way your file is included in the render cache.

function mymodule_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];

  foreach ($items as $delta => $item) {
    $element[$delta] = // Blah blah blah add output for each $items in $element as a render array.
  }

  // Add the JavaScript file.
  $element['#attached']['js'][] = drupal_get_path('module', 'mymodule') . '/mymodule.field.js;

  return $element;
}


Passing PHP variables to JS file initiated from theme .info file I know it's perfectly possible to pass PHP variables to JS but what if the JS file is initiated from the theme.info file? Can you access it in template.php or? Please some advice..

Thanks!

You don't access the Javascript file in PHP, rather, you tell Drupal to send values to Javascript variables and then access those from your Javascript files. You would use drupal_add_js.

For example, in template.php add:

drupal_add_js(array('myModule' => array('key' => 'value')), 'setting');

Then in your Javascript file, you can access that variable as:

Drupal.settings.myModule.key


Adjusting Apache Solr bias based on content length? I have a site using the Apache Solr Search Integration module with a short-form content type that is getting weighted too highly in the Solr index. I've tried adding "Bias" to the other content types and leaving the short-form content type set to Ignore, but even with other bias settings maximized the short pieces still rise to the top. Looking at the particular items that appear at the top, it seems to be that multiple instances of the search terms in a short piece cause it to rank higher.

According to the help on the bias settings page, "Any value except Ignore will increase the score of the given type in search results." Is that a limitation of the Solr module or of Solr itself? Ideally, I'd like to decrease the relevance of the short type. What are my options for doing that?

Under bias setting you should be able to reduce the priority of the fields. So reduce the priority of the fields that is not much important, and increase the priority of the fields that you would prefer for solar to prioritize.

The settings can be found on: admin/config/search/apachesolr/settings/solr/bias

0.1 is the lowest and 21.0 is the highest rating.


Do I need hook_update_N if there are no database changes? I wrote a little module that provides a form and does some special processing of the submission.  There are no database tables involved. If I change the form or processing, how do I code the update? Do I still use hook_update_N if the module update doesn't affect the database?

Thanks!

If the changes are just code, (not db schema changes, content changes, variable changes, data changes in general), then you don't need an update hook, no.

Basic rule of thumb: will your code updates break anything for existing or new users? If not, you don't need an update hook.


Comments Notification Where is the comment notification when anonymous users send a comment?
I don't find any notification in dashboard, or other pages to approve comments.

The list of unapproved comments is on admin/content/comment.

Unapproved comments are the comments left from users without the permission of skipping the comment approval, which is given in admin/people/permissions.

In the site where I took this screenshot, authenticated users are allowed to skip the comment approval, which means that any user with an account is able to write a comment without it gets approved before to be visible to every user.


How do I go about putting standalone PHP files into Drupal 6? I want to add an extra cool PHP Class, where would I put it in Drupal, how do I make absolutely sure the code doesn't present a security risk, should I just make it into a module?

Your best bet would be to include it via a custom module, and to include it would be as easy as using module_load_include().

As for security, I would advise taking a look at the Drupal coding standards documentation, which is unfortunately tagged as D7 and I wasn't able to find the old D6 version, but generally following standards will help prevent some security issues.

Code not written exclusively for Drupal may not specifically work out of the box either, you may have to write a bridge for the code to integrate it better, otherwise you may need to re-write it completely.


Content not displaying formatting - removes HTML despite settings On any content I create the formatting shows in the WYSIWIG editor but does not show up on the rendered page. I have tried to put it into each filter format ( Full HTML, Filtered HTML, Plain text ) with no change. So to make it really clear what is happening: I create and article with the body set as

Test Content

More test Content

or

Test Content

More test Content

and save it. Upon viewing the rendered page at the node url all of my content is pushed together and the HTML tags are gone completely when viewed in the inspector

Test ContentMore test Content

Would be what I get out. The weird thing is that if I go into the editor for the content the HTML tags and/or line-breaks are still there.

url of node with issue:

http://cafemam.b.fgqa.net/node/3575

If text format is correct and filters are correct, verify that the display format of your both content types (Article & Basic Page) is not set to Plain text but Default (or Summary or trimmed, ...).

It is under Structure > Content Types > Basic page | Article > Manage Display > Body field (format column).


Export content types using features I am struggling with it, but I can't do it by myself. Google doesn't gave me links for tutorials other modules doesn't help me too.

I would like to export content types definition from Drupal site to another.

Could someone give me any hint how to do it?

Sure,

Install the features module and then you go to structure -> features

Click on "create new feature"

Give it a name and then on Edit component you can select what you want to export.
Select Content-type: node and you will see a list of all your content types, check the content types you want to export,( when you click the checkbox, you will see the ajax image wait till it disappear) and then click on download feature.
Version 7.x-2.x has got a better UI and it's possible to download it straight into your sites/all/modules/features folder if you give web server permission to write into that folder.

The feature you downloaded works like a module so upload the folder you downloaded into sites/all/modules/features, go to you module page and enable it.

You will find your content type with all the fields.

I suggest you to play with features module to understand all his potential.


get language on form alter I try to get selected language for specified node (I mean in edit form) on form alter with following snippet in MODULENAME.module

use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\Request;

function MODULENAME_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
    if ($form_id == 'node_trends_edit_form') {
        kint($form);
        kint($form_state->getValue('langcode'));
        kint($form_state->getValues());
    }
}

BUT    results for   kint($form_state->getValue('langcode'));           kint($form_state->getValues()); are NULL.

how can I get language selected for node on form_alter

The code to get the entity language is present in language_form_alter(), which you can take as an example to write your code.

  $form_object = $form_state->getFormObject();
  if ($form_object instanceof ContentEntityFormInterface && $form_object->getEntity()->getEntityType()->hasKey('langcode')) {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $form_object->getEntity();
    $entity_type = $entity->getEntityType();
    $langcode_key = $entity_type->getKey('langcode');

    // Your code goes here.

  }

If you are sure the edit form is for a content entity (such as a node), you could remove the part verifying that $form_object is a content entity object. I would leave it, but that is my personal preference.


How to disable stripping tags for View header? I have created an view and set its header to:

    Filters
    <select><option value="Select filter" disabled default">Select filter</option></select>

But when I access it (via block created from view and placed anywhere on website) I get:

    Filters
    Select filter

So how to prevent Drupal 8 from stripping those form tags?

Please got to the view you have created and follow the below steps :

Header > Add > Type "Text area" in Search
Select Text area > Add and configure header
Under the content insert

    Filters
    <select><option value="Select filter" disabled default">Select filter</option></select>

Dont forget to change the Text format  to Full HTML and click on save


Feed aggregator does not update RSS feeds when cron job is run (Drupal 7) I have several feeds setup in the Feed Aggregator ( admin/config/services/aggregator ) in Drupal 7.

I know that my cron job is running regularly - by checking admin/reports/dblog

But the when I look at the feeds list, the "LAST UPDATE" for each of them shows dates from over a week ago. If I do the update manually, i.e. click update items then the feed is refreshed and new items are available.

But why is the cron job not triggering the updates?

If you can't provide a reason then what approaches to debugging can I use to find and solve the root cause?

I have searched this site already and not found an existing question about this problem. I did find RSS feed not updating using feeds module but that question is about the Feeds module - which I don't use.

Yup, trying to solve my own question (again):

Similar problem here:
http://drupal.org/node/1115978

and the possible solution here:
http://drupal.org/node/1023190

Update

The above solution was about a database fix to do with feeds that have more than one category.

When I applied to patch I was informed that this was already in the version of aggregator.

So in summary the solution I gave above had already been applied.

However, another avenue to explore is cron job time out. In my situation I have a lot of feeds so it could be taking the job invoked by the cron a long time to update all of them.

Here is another possible solution to extend the time alloted to running a job triggered by cron, a cron job:

http://teqsnacks.com/2007/07/07/drupal-when-cron-jobs-do-not-complete-and-cron-jobs-tips/

To quote:

  Go to your settings.php file (under sites/default or wherever it
  is). At the bottom of it you will see a list of ini_set commands. Add
  the following to the list:

ini_set("max_execution_time", 60);

  The number at the end is the number of seconds a program can run
  before timing out. Setting it to 0 means "never timeout" which you
  should use very carefully, like on a development site where you have
  control over the server.

Update 2 - and likely solution and root cause

The cause of the problem likely stems from a corrupt database causing errors when the cron job is run. Details and remedy here:

http://drupal.org/node/1596220

Update 3

After following the above instructions you may still see the feeds not updating. Further things to consider:

Clear all caches
Check your site logs for cron job running successfully and new feed items being imported from the aggregator
If you are using a View (of type aggregator) to process the feed then you would probably need to sort the feed by descending so that the latest feed items appear first. To do this you will need to define your own date format (check the PHP option) for the Aggregator Feed Item Timestamp in the View sort criteria, so that the date is big endian i.e. YYYY-MM-DD hh:mm:ss. The current date formats offered aren't purely big endian and the sort won't work properly e.g. because day comes before month.


creating a custom report page with a table Drupal 8.9.6, I'm trying to create a custom module admin report page.
I have a custom sub theme of seven called wd_admin.
I made a page controller that generates a table as markup, but want to use a twig file to render the html, and can't figure out the theming.
It is using block.html.twig to render the content, and the first suggested template is block--wd-admin-content.html.twig. So I created it, and plumbed it in with hook_theme and hook_theme_suggestions_block_alter, but it affected the content on all admin pages, wrong move.
Seems like for this to work it would have to be specific to the page. What do I need to do to render this page, maybe a page.html template?

Yeah I think you're conflating a few different concepts and making everything way more complex than it needs to be.
If you all you want to do is render a particular custom template with your controller then you'd want to:
// In fun.module
function fun_theme() {
  return [
    'a_fun_template' => [
      'variables' => [
        'heading' => '',
        'activities' => []
      ],
    ],
}

// Then in your controller
public function yourRenderMethod() {
  $heading = 'Some fun activities';
  $activities = [
     'Rocket League',
     'Violin'
  ];
  return [
    '#theme' => 'a_fun_template',
    '#heading' => $heading,
    '#activities' => $activities,
  ];
}

// Then in a-fun-template.html.twig
{#
  Do whatever with your variables, like print them
#}

{{ heading }}

{% for activity in activities %}

{{ activity }}

{% endfor %}

EDIT: I think I figured out why you're looking at the block. All that that is is the "Main page content" block from the blocks page. This just renders the main content for the page, which in this case would be the contents of your controller's template. Now that said, what I wrote before was...
I really don't understand where the block is coming into play here, but I think you're misunderstanding that as well.
First, the default template suggestions are very general. block--wd-admin-content.html.twig is probably added by wd_admin to every admin block by default. That's why a template by that name would be used by all blocks in the admin area. Generally the longer the suggested template name, the more specific it is. Template suggestions that you add to hook_theme_suggestions_block_alter() will apply to all blocks unless you wrap the suggestion in conditional logic that says otherwise. If all you're doing is using a hook_theme template in a controller then you don't need this hook at all.


how do I delete a project release node I accidentally created a stable release for a module instead of dev. So now how do I delete the stable release node on drupal.org

Usually you can file an issue for webmaster to delete the nodes. But in this case they usually don't delete release node and only option is to create new release.

check: https://www.drupal.org/node/128614


How to use Rules to prevent the creation of nodes if certain conditions are true? I need this in Rules:

  When a node is being created (before the node is saved), and certain conditions are true, the user can't create the node, and an error message appears instead.

I have a rule that is working, and the error message is displaying. But the node is still created.

Is there a way to prevent node creation in rules?

Note:
I'm using Drupal 7. I selected the Action "Show error message" directly on rules.

Out-of-the Rules module-box, I think there is no solution to "prevent node creation in rules?" (as in your question). However, without using custom code and custom PHP in your Rules conditions or actions and without deleting the node after it got created, you may get it to work if you also use the Rules Forms Support module.
More details about Rules Forms Support (from its project page):

Rules Forms Support provides a Rules based method for controlling forms and their elements. The module can be used to alter any form provided by Drupal core or contributed modules. Change element titles, descriptions, weights, and more, or validate form data and set form errors. Rules forms saves time and cost by affording site builders the ability to monitor and alter forms without the need to implement a custom module.
For help getting started with Rules Forms Support, please see the module documentation.
Features

Activate events for form creation, validation, and submission on a form-by-form basis.
Target individual form elements or the entire form in conditions and actions.
Manipulate the attributes of a form element like title, description, weight, and more.
Validate the values of form elements during form validation.
Set form errors when rule-based validation fails.
Redirect users to a different page upon viewing or submitting a form.
Examine the attributes of elements in active forms with the element inspection tool.

Especially the "Set form errors when rule-based validation fails" should help to address your question.
More details about how to use this module can be found in the community documentation "Altering & validating forms".


Drupal 7 how many blocks in region? I need to know how many blocks in the region! is there any short way to do that ?
if more than one block in the region than I want to add custom class to region.

I think your best bet would be to use hook_preprocess_region() in a module or theme:

function MYTHEME_preprocess_region(&$vars) {
  // Make sure it's the right region
  if ($vars['region'] == 'sidebar_first') {
    // Get the count of blocks
    $count = count(element_children($vars['elements']));

    // Add the class if necessary
    if ($count > 1) {
      $vars['classes_array'][] = 'some-class';
    }
  }
}


Organic Group OG membership relationships I'm trying to display on a views, only the nodes which the user is part of the Organic group.

I have a field og_group_ref in my content type which relate to a group.

What I want is for each user, display only the one he his part of. It seems relationship is the trick but somehow I can't make it work .

So far I tried in Relationship:

 OG membership: OG membership from Node group

(OG membership from node group) OG membership: User from OG    membership

and to add in contextual filter:

(user from OG membership) User: Uid (with default value set to "user id from logged in user")

But it doesn't seem to work!

You just need to add OG membership: Group ID as a contextual filter,
click Provide Default: The OG groups of the logged in user
and under More at the bottom of the filter's settings,
click Allow multiple values.