Prevent the email registration module from appending the user ID as a suffix on new user's username

While looking at the project page of Email Registration, it reads:

  A username is generated and assigned based on the user name part of
  the email address and their user ID. Sites that want to create
  usernames in their own way can do so by implementing
  hook_email_registration_name.

And when looking at hook_email_registration_name(), we see how we can alter the username by returning a value.

So, what you need to do is:

Create a custom module (there is plenty of documentation for that on this site and the rest of the internet).
Implement hook_email_registration_name() (place this function in your module file and replace hook with your module name).
Have the hook return a new username.

So you need to put something like this in your module file:

function mymodule_email_registration_name($edit, $account) {
  $mail = $edit['mail'];
  $mail_parts = explode('@', $mail);
  $username = $mail_parts[0];
  return email_registration_cleanup_username($username);
}

This will return the first part of the email as the username. So john@gmail.com becomes john. bob@yahoo.com becomes bob. john@hotmail.com becomes also john... But that was already in use and Drupal does not allow duplicate usernames, so you have a problem. (And you discovered the reason this module by default appends a unique token to the username.)

You could solve this by implementing a small iterator. Appending 1, 2, 3 to every subsequent John but it would result in just as ugly usernames (and for the 100th john you had to do 99 database lookups making this slow).

So I'd like to propose to you Real Name. This nifty module will override the username display everywhere with the value of one or more other profile field. So you add a namefield to the registration, configure Real Name to use that field and the user will never know his username is john_123 because he will never see it.

I don't know your specific requirements and this might not be suitable for you, or if you can think of another way to enforce uniqueness, you can always use the hook and implement your own method. See what fits you :).


According to your comment:

  I don't want to create pages for the Files

The url file/%file is registered as menu item in file_entity_menu(). You can disable the page by implementing hook_menu_alter() in custom module.

Example

/**
 * Implements hook_menu_alter().
 */
function mymodule_menu_alter(&$items) {
  // disable the file entity page
  $items['file/%file']['access callback'] = FALSE;
}

Another question you mentioned.

  Can I redirect to home page for file url's?

You can override the page callback and add the redirection in it.

Example

/**
 * Implements hook_menu_alter().
 */
function mymodule_menu_alter(&$items) {
  // disable the file entity page
  $items['file/%file']['page callback'] = 'mymodule_file_callback';
}

function mymodule_file_callback($file) {
  drupal_goto('<front>');
}


How do I add images in pager for views nivo slider?

The module(views Nivo slider) does not support using images as pagers by default. If you want such functionality you would have to write a custom module to extend the views nivo slider module. So I would advise you to go back to using the views slideshow module to achieve that. Even the original plugin created by nivo slider itself does not support such functionality. See demo site


Integrate Webform.html.twig into existing template

Conceptually, you shouldn't be thinking about it as including templates in other templates. Other CMS'es are more "template based" so to speak, but Drupal isn't. Building your content types and pages in Drupal means telling Drupal (through configuration or in code) how to construct its render arrays. From there on, Drupal will figure out which templates to use and how to merge the resulting HTML of one template into another template.

So that's the theory... now what's the problem in your case? The most obvious reason I can think of, is that you added the field, but did not yet configure it to be displayed. To do so, make sure Field UI module is enabled and then go the "Manage Display" page of your content type. The URL will look like /admin/structure/types/manage/[type]/display where "[type]" is the machine name of your content type. If you see your field in the "disabled" part of the form, drag it upwards to make it enabled and save the form. (This is an example of the "through configuration" method I mentioned earlier.)

If the above does not solve your problem, please add more details to your original question.


How do I keep the cron from removing a poll from my front page?

I would highly recommend Elysia Cron, it allows fine grained control of crons provided by modules (ie poll) in which you can completely disable the cron of a specific module (or change the timing from the global setting for that specific module's cron; in your case, 1 hour), which seems like something you might need to try out.  See attached for an example settings screen on a D6 site (the checked boxes mean that cron is disabled).


Variables can be added and manipulated in preprocess functions just as with .tpl.php files.

Twig has a dump() command that can allow you to see the available variables.


How do web search engines handle view pages?

In the SEO world, this is known as Duplicate Content, and it's something you want to avoid as much as possible. [1]

This is dangerous territory for duplicate pages which can get you sandboxed by the search engines! [2]

in drupal you can reach same page with lots of links: node/123, node/123/, content/some title and ...

one solution is Global Redirect module


There no such thing as "node metadata", there are just fields.

So the easiest thing to do is to create a field (in the UI for example, you can then also export the configuration into your module), field_work_id or something, and in put in there with $node->set('field_work_id', $work_id).

You can do that in hook_node_presave(), but then you might not have an node ID yet for a node that is just being created and is already published. You could also use hook_node_insert()/hook_node_update(), but then you need resave the node and make sure you don't trigger a loop.

You can also save the work ID in your own table, or you can store the node together with the work ID in a way that allows you to do a lookup with a query.


One of the most common ways to move configuration data is to use the Features module.  However, this will move only configuration, not data (nodes/content).  Still, it's not too difficult to set up; you can take a look at this tutorial for an overview.

Moving data is much harder; the Migrate and Feeds modules are two common ways to do this but both are quite painful to set up and probably not worth the trouble.  For content, I just keep a list of the info in an Excel file and then cut and paste it in-- it's not a great solution, but in my case it saves a lot of time.


How does Drupal Commerce store Addresses for anonymous users

Commerce will always create a new user upon completion of the checkout process of anonymous orders. This happens in a rule named "Create a new account for an anonymous order":

admin/config/workflow/rules/reaction/manage/commerce_checkout_new_account

If you want to clone the order, then, just act after the aforementioned rule has executed by creating a rule with a higher weight.


Field for additional charge the drupal / drupal commerce way

You don't make the use case very clear, but sounds like you could use some of the existing price fields, fx unit price on product line items, but simple add the price with a custom component. That way the price would be viewable in the order overview, but when seeing the product cost you get the simple and correct value of $ x.xx.


Will assigning a name string to user #0 do any harm?

For the record: I've done it.  One issue immediately popped up during testing: If a user named "Anonymous" already existed, creation would fail (obviously).  After modifying the routine to check for existing users before updating, it worked.

Been running on several production sites for a week, and no problems so far. I'll report here if any problems occur.


pass result of Rules loop to variable to use outside loop

You may have success there using the "provides" key in hook_rules_action_info to provide a variable.

more info: http://drupal.org/node/878972


The taxonomy term status module is aimed at this use case.

There is an issue for that module regarding views exposed filters at https://www.drupal.org/node/1805882

Looking at that issue it is a little unclear the status of it. Some users say they have it working and others say they do not.
I would try adding your experiences to that issue and someone that has experience with that specific problem may be able to help you get it working.


Attach a handler to the "event" of autocomplete select with jQuery

I had a similar issue with a Drupal autocomplete field I had created, where I wanted the form submitted when an item from the dropdown was selected.

This blog post addressed the issue for me:  http://othermachines.com/blog/smart-autocomplete-navigation-drupal-7

The relevant JQuery code you'll want to look at on that page is this:

(function ($) {

  Drupal.behaviors.programmeSearch = {
    attach: function (context) {

      $('#edit-autocomplete-field').focus(
        function(){
          $(this).val('');
      });

      $("#edit-autocomplete-field", context).bind('autocompleteSelect', function(event, node) {

        var key = $(node).data('autocompleteValue');
        var label = $(node).text();

        // If matches found...
        if (key != '0') {

          // Set the value of this field.
          $(this).val(label);

          // Redirect user to entity path.
          window.location = Drupal.settings.basePath + key;
        }
        else {

          // If no matches, reset.
          $(this).val('');
          $(this).focus();
        }
      });
    }
  };

})(jQuery);

You probably won't need all of that code.  Whatever you want to happen on the select event, put in the condition beginning with if (key != '0') {


Add fields to form dynamically with ajax and retrieve values

Dont set any field #required to true.

 $form['markup'] = array(
        '#type' => 'markup',
        '#prefix' => '
',
        '#suffix' => '
',
    );
 $form['markup']['myfield'] = array(
        '#type' => 'textfield',
        '#size' => 12,
    );


Is there a hook that could manipulate the list of field items before the field is built?

What about hook_entity_prepare_form()? This simple example loaded an extra item into the form.
function mymodule_entity_prepare_form($entity, $operation, $form_state){
  if ($entity->bundle() == 'domain_groups') {
    $items = $entity->get('field_topic_access')->getValue();
    //just a hardcoded item for test purposes
    $demo_item=['topic_tid'=>'74','available_to_group'=>'1', 'publish_to_group'=>'0'];
    $items[] = $demo_item;
    $entity->set('field_topic_access', $items);
  }
}

There may be a more elegant solution but I could use this hook to show my inherited items and hook_entity_presave()  to remove inherited values before saving.


Just define 4 checkboxes and 4 textfields. If you use a bit of CSS you can get them to look like they're compound fields by floating left and clearing after the textfields. You might need to hook into the validate functions (using hook_form_alter) if you want these fields to be any smarter than that.


Suggest a new template file for a page node view

To use a different template file for the node being shown, you need to add a new suggestion in $variables['theme_hook_suggestions'] (Drupal 7), or $variables['template_files'] (Drupal 6). In both the cases, the variable is an array.

In a module, the hook to implement is hook_preprocess_page().

function force_preprocess_page(&$variables) {
  if (!empty($variables['node'])) {
    if ($variables['node']->type == 'mens-blog-post') {
      array_unshift($variables['theme_hook_suggestions'], 'page__node__mens_blog_post');
    }
    elseif ($variables['node']->type == 'womens-blog-post') {
      array_unshift($variables['theme_hook_suggestions'], 'page__node__mens_blog_post');
    }
  }
}

If you have a module called force.module, then your code is correct. The same code can be used for a theme whose short name is force; in this case, in its template.php file you add a force_preprocess_page() function.
In Drupal 6, your theme needs to also have the default template file (page.tpl.php), or the custom template is not going to be picked up. I didn't check if this is still valid in Drupal 7. (The only time I created a theme that was using a custom template file was in Drupal 6.)

I would rather check the variable $variables['node'] is not empty, as hook_preprocess_page() is called for every page served from Drupal, including the ones not associated with any node.


How to close (ctools) modal node/add form after submit?

ctools_modal_command_dismiss() will close the modal.

You can find more information on that command and ctools modals in general by installing the Advanced Help module and visiting /help/ctools/modal.


Loading a form via ajax is no different then loading any other page with ajax. The quick answer is that you should create a route to display the form and then call that route via ajax but for a detailed description you should take a look here: https://www.drupal.org/node/2046693


How to load a node title of different language?

You can load the translation separately with ContentEntityBase::getTranslation, e.g.:

if ($node->hasTranslation('es')) {
  $translation = $node->getTranslation('es');
  $translated_title = $translation->label();
}


I think you should check this link for solving your problem : how-to-theme-a-custom-block-in-drupal-7. Actually you can search for that type of question around here.


Webforms with subheadings that have their own fields

Basically I got away with just putting up a markup title. I thought it was really necessary to have field groups in order to make a valid web form since it was suggested to me. I guess like Andy said, nested fieldsets might have worked as well.


Rendering a generic file field containing an image

Check admin/config/media/file-types/manage/image/display/media_small and check that File is actually being displayed and not set hidden.


Assigning CSS classes to exposed widgets in a view?

Drupal – Theme the Exposed Filter in Views. Basically make a custom views-exposed-form.tpl.php file at your theme level that is specific to each of the widgets you have setup. You can then adjust the markup in each of the template files to include a unique ID to allow styling specific to each widget.


How to add 'Welcome {username}' in blocks with Drupal 7

Either in a block or in a custom module that adds a block, add the following code:

if (user_is_logged_in() == TRUE) {
    global $user;

    print "Welcome " . $user->name;
}
else {
    print "Please log in.";
}

This is more useful if you want CURRENT user information.  Possibly this as well for the user_is_logged_in function.


What is the correct order of disabling the default contact form on Drupal?

You may be able to use this (untested) approach in your hook_update_N() implementation:
function my_profile_update_8011() {
  $config = \Drupal::configFactory();
  $moduleHandler = \Drupal::service('module_handler');

  $mods_removable = [
    'lightning_contact_form',
    'contact_storage',
    'contact',
  ];

  // Read the configuration.
  $module_data = $config->getEditable('core.extension')->get('module');

  foreach ($mods_removable as $module) {
    if($moduleHandler->moduleExists($module)) {
      // Unset the modules you do not need.
      unset($module_data[$module]);
    }

  // Write the configuration.
  $config->getEditable('core.extension')->set('module', $module_data)->save();
  }

See this answer for additional info.


If you want a PHP headless web browser, you might look at Mink.

Gherkin/Behat seem to be getting some traction in the Drupal community and in the PHP community more broadly for Behavioral Driven Development.  Mink also supports browser emulation systems (like Selenium), which you typically need in order to interact with Javascript.


You should be able to do this with Views, I am pretty sure that is why the D7 port did not happen for Term Node Count (see: https://www.drupal.org/node/603868). A view can be cached so it will essentially store the value as that module did but it will update more frequently (or less if you want to set the cache up like that) and give more flexibility to where you can display the information. You can setup a view pretty easily for this:

This is just one way to get the information but the view will really depend on your use case for what you need the count for:

In Fields: add Taxonomy term: Name
In Relationships, add a Taxonomy term: Content with term
Add a contextual filter for Taxonomy term: Name
Choose 'Display a summary'
Choose 'Display Record count with link'.

Views is a very flexible module and chances are you are probably already using it, it will work for most all needs. You can also do this yourself in code pretty easily by doing the count and storing it statically then writing a update function that will update the term count every once and a while but it will cut down on flexibility but I tend to go for code if it makes sense.


There are three things that needs to be corrected, in your code.

You are using a foreach statement without any block; this means that that control statement is not doing anything.

foreach ($node->field_newsections['und']['0'] as $node_time);

You are using an else statement followed by a condition; or you use an else statement without condition, or you really meant to use the elseif statement.

else ($node_time == '108') {
  //...
}

You are using render() with $newcontent, which is set with a previous call to render().

$nodecontent = render($content);
$newcontent = preg_replace("/
]*?>/", "", $nodecontent);
$newcontent = str_replace("
", "

", $newcontent);

While render(), which returns a string, checks when the parameter it gets is a string, instead of an array, and it returns that parameter immediately, it is useless to call render() with the result of a previous call to render(), even if that string has been modified from any function to alter a string.

Also, as you said (in a comment for this answer) that you are using that code inside the "node.tpl.php" template file, that template file has already access to the $nodevariable that contains the node object for the node being shown. As the template file is only used for nodes, the following code is useless:

if (arg(0) == 'node' && is_numeric(arg(1))) {
  $node = node_load(arg(1));
  $user = user_load(array('uid' => $node->uid));
  // …
}

It is also unusual for a theme replacing the HTML content; that is normally done in a module.

Supposing that you are trying to use the last item in the $node->field_newsections['und']['0'] array (which seems a term array), I would rather use the following code:

$tid = array_pop($node->field_newsections['und']);
$node_time = $tid['tid'];

hide($content['comments']);
hide($content['links']);
$nodecontent = render($content);
$newcontent = preg_replace("/
]*?>/", "", $nodecontent);
$newcontent = str_replace("
", "

", $newcontent);

if ($node_time != '103') {
  print '
'. date('l, F j, Y g:ia', $node->created). '
';
}

print $newcontent;


How to create a content type based on users with entities?

So the thing is that u want to populate user fields with content from node, what you can do is enable module, hook_post_action, and after that use its hook "hook_node_update", and you will get user id (uid) from the user reference fields, u can load a user from that uid, using user_load, after that set required value of field, and use user_save function to save that user, If u are using profile2 for the user, then u can use profile2_load_by_user, profile2_save.


Should i use field.tpl.php or Display suite to add my own classes to fields?

It's matter of opinion, really. I'm using DS and it works fine, but it might have disadvantages later on, because I will have to export my settings to code with Features.

Also, DS isn't your only option - you can also try:

https://www.drupal.org/project/semantic_fields
https://www.drupal.org/project/field_formatter_class

and others. Which depends on your other needs - for example, are you planning to use DS multiple display modes handling?


A view that displays content with taxonomy term of current user?

You have the right idea!

You'll start with a View of "Lesson" content.

You'll then add a Relationship from the "Lesson" to the "School" taxonomy term, using the taxonomy term reference field configured on the "Lesson" content type.

Next, you'll add another Relationship from the "School" taxonomy term to the User entity type, using the taxonomy term reference field on the User entity. This is a reverse relationship; in the Views interface, it will be labeled something like "Taxonomy term: User using [name of reference field]". (My suspicion is that this is the part you're missing.)

Finally, you'll add a Contextual Filter "User: Uid", configured to provide a default value of type "User ID from logged in user". There will be a configuration option here to select the Relationship to use for this contextual filter, but at this point it should already be selecting the only User Relationship that is currently configured.


How do I change my blog title font size and serif typeface in views?

You may need to add a class name to the view to make it easier to specify the view
at admin/structure/views/view/[view-name]/edit -click-to- advanced click-to- CSS and create a name for the view, this will help to label the CSS.

Then:

If your theme has the option to change the font size and typeface, just change it in the theme. Adaptive theme can do this, https://drupal.org/project/adaptivetheme , for instance. If you only want one view to be different, this will not work.
Otherwise create a new subtheme and modify CSS as needed to change your view font-face and size. https://drupal.org/node/225125
An easier option: using the Sweaver module to interactively change CSS often without having to resort to editing any files, uses a GUI. https://drupal.org/project/sweaver . Be careful to only select that view.
Another easy option can use the CSS Injector, to create specific CSS to override existing CSS: https://drupal.org/project/css_injector and again, select the specific view element for title.


Node paths come through empty unless view result is programmatically changed

Put Show on field, then remove "title" field and add Path field

and if you want result be Absolute Url  on Rewrite secion Check Use absolute link (begins with "http://")


What hook can access every field label at once and change the label of one?

A guaranteed solution for all fields is hard. It depends on:

The field formatters you have chosen
the template files used

For a general approach try:

/**
 * Implements hook_preprocess_HOOK().
 */
function YOUR_MODULE_preprocess_field(&$variables) {
  if ($variables['element']['#field_name'] == 'YOUR_DEPENDENT_FIELD' && !empty($variables['element']['#object']->YOUR_DEPENDENCY_FIELD)) {
    // YOUR LOGIC IN RELATION TO YOUR_DEPENDENCY_FIELD
    $new_value = 'something';
    $variables['label'] = $new_value;
  }
}

Notes:

This will change the label display everywhere, not only on a
node display. Since you don't mention anything about view modes, I
guess the given solution is good enough.
Make sure you sanitize $new_value if you are showing user input.


Converting the post to all lower case would be pretty simple; you can implement your own filter like so:

function MYMODULE_filter_info() {
  $filter['allcaps_filter'] = array(
    'title' => t('Disallow ALL CAPS posts'),
    'description' => t('Rudimentary filter which converts all text to lowercase'),
    'process callback' => 'MYMODULE_allcaps_filter_process'
  );

  return $filter;
}

function MYMODULE_allcaps_filter_process($text) {
  // Attempt to make the first letter of the first word uppercase. This is very
  // likely to fail as the inputted string will probably be HTML.
  return ucfirst(strtolower($text));
}

Once you clear the caches you'll be able to add that filter to any text format you want.

It's worth noting that the description rudimentary in the comments is very, very apt...for example this will also convert any HTML attributes/tags to lowercase which might break embedded image paths etc. It might provide a good place to start though.

Constructing more naturally cased alternatives is going to be very tricky, mainly because you haven't just got text in there...you've got HTML as well. I can't think of a decent way to do this at the moment to be honest, short of importing the string into a DOMDocument and looping through every element, converting the text in chunks as you go.

I'd provide an example for that but I think you've got one ;)


Combine 2 contextual filters - taxonomy term ID from url and NID

I don't think you can do this with multiple contectual filters.

Sounds like you need relationships.

Use the contextual filter to get the current nid and show the fields for that node.

Then add a relationship between the node and its terms (you can limit this by vocab if need be) by adding the relationship "Content: Taxonomy terms on node".

Then add a relationship from the term to the parent term by add the "Taxonomy term: Parent term" relationship. This relationship should use the previous relationship.

The add a relationship from the parent term to the content that uses that term by adding the " Taxonomy term: Content with term" relationship. This relationship should use the Parent relationship.

Then you can do extra things like adding filters that use these relationships.

All these relationships can have the "Require this relationship" checkbox checked.

With some relationships you can end up with duplicate results.
One way to try to avoid this is go in the "Query options" in the "Advanced" part of the views configuration and check the "Distinct" checkbox.

Relationships can be confusing and they are hard to explain, but if you play around with them, once you understand them they are very useful.

Extra question
To answer your extra question of whether you can display the value of one field if it is there and if it is not then show another field in its place:

Yes, you can do that.
Depending on your requirements there are a couple of ways it can be done:

Exclude the secondary field from display and for the primary field check "Rewrite the output of this field" and use the tokens to print the primary and secondary fields out next to each other. This solution will only work if only one or the other of your fields will have a value. If there is a chance that both fields will have a value you will end up with both values printing next to each other.
Exclude the secondary value from display. Then in a custom module implement hook_view_pre_render() and you can check the $view->result to see if the primary field has a value. If it doesn't you can replace the empty value with the value of the secondary field.
Override the template for views_view_fields.tpl.php so that if the primary field is empty you print the secondary one. And don't print the secondary one. This could also be handled in the preprocessor function template_preprocess_views_view_fields() in your theme's template.php file.

Unfortunately I don't have time to give code examples right now.


I think you're looking for the Insert module.

Here is the description from the Project page on Drupal.org

  Insert is a utility that makes inserting images and links to files
  into text areas or WYSIWYGs much easier. It adds a simple
  JavaScript-based button to FileField and ImageField widgets. When used
  with ImageField and ImageCache, images may be inserted into text areas
  with a specific ImageCache preset.


Sort nodes based on the amount of tags that match a specific node tags

Check out Similar by Terms module. This Drupal module attempts to provide context for content items by displaying a block with links to other similar content. Similarity is based on the taxonomy terms assigned to content. Blocks are available based on similarity within each of the defined vocabularies for a site as well as a block for similarity within all vocabularies. There are two methods of sorting. 1) Based on the most number of matching terms. 2) Based on lest used terms.

Or you could use the Relevant Content module. This module provides two ways of referencing relevant content. Both of these methods provide configuration to filter for specific content types and vocabularies, limit the maximum size of the result and provide some header text. The result on both cases are a list of nodes which the module considers most relevant based on the categorization of the current page. This is achieved by finding other nodes which are of one of the allowed types and have the most number of terms in common.


I had a look at the CKEditor API docs and the other classes I might extend - it didn't seem to be any of:

CKEditorPluginButtonsInterface
CKEditorPluginContextualInterface
CKEditorPluginCssInterface

…though perhaps CKEditorPluginConfigurableInterface, if I wanted to configure the settings form per text format?

Then, I found a module called ckeditor_config, so I adapted it's plugin class, which extends CKEditorPlugin/Internal:

/**
 * @file
 * Definition of \Drupal\ckeditor_remove_elementspath\Plugin\CKEditorPlugin\RemoveElementsPath
 */

namespace Drupal\ckeditor_remove_elementspath\Plugin\CKEditorPlugin;

use Drupal\ckeditor\Plugin\CKEditorPlugin\Internal;
use Drupal\editor\Entity\Editor;

/**
 * Defines the "Remove Elements Path" plugin.
 *
 * @CKEditorPlugin(
 *   id = "remove_elements_path",
 *   label = @Translation("Remove elements path from CKEditor status bar")
 * )
 */
class RemoveElementsPath extends Internal {

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) {
    // Get default config.
    $config = parent::getConfig($editor);

    $config['removePlugins'] = 'elementspath';

    return $config;
  }

}

Edit: And here's my module if anyone finds it useful.


What is the order of execution and redering of hooks and page components?

Consider looking at the X-ray module also. From its project page:

X-ray module gives a look at the skeletal structure of a site to help developers and site builders see how things work.
Features:

A technical summary is added to the help above the main administrative sections. For example, blocks, content types, and menus are summarized on Structure; themes on Appearance; etc.
A table of permission titles matched to their permission machine names.
A table of most* hooks which Drupal invokes (and when they are invoked) and that are available to be implemented.
The function and arguments producing each page you visit, displayed on that page.
The form ID of every form you see, displayed on the form.


Take a look at Webform Localization module

  The Webform Localization module provides multilingual features to the Webform Module. Special options in the webform and component configuration let you enable different ways to manage translation of forms and questionnaires.


Add block to form (before submit button)

You can do something like this:

load the block content manually
control the order of fields withj #weight option

example:

function my_form()
{
  $block = block_load(MODULENAME, BLOCKDELTA);
  $block = _block_render_blocks(array($block));
  $block_build = _block_get_renderable_array($block);

  $form['FIELD_1'] = array(
    ...
    ...
    '#weight' => 1
  );

  $form['FIELD_2'] = array(
    ...
    ...
    '#weight' => 2
  );

  $form['FIELD_3'] = array(
    '#prefix' => '
',
    '#suffix' => '
',
    '#markup' => render($block_build),
    '#weight' => 3
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'OK',
    '#weight' => 4
  );

  return $form;
}

if those forms are from other modules you can alter them with hook_form_alter(&$form, &$form_state, $form_id) function.

example:

function MYMODULE_OR_THEME_form_alter(&$form, &$form_state, $form_id) {
  // dpm($form_id);
  if ('user_register_form' == $form_id) {
    $form['actions']['#weight'] = 50;

    $block = block_load(MODULENAME, BLOCKDELTA);
    $block = _block_render_blocks(array($block));
    $block_build = _block_get_renderable_array($block);

    $form['fb_field'] = array(
      '#prefix' => '
',
      '#suffix' => '
',
      '#markup' => render($block_build),
      '#weight' => 49
    );
  }
}


How to trigger JavaScript/jQuery on AJAX-enabled ImageField submit?

I agree with DeeZone that .click() should work.

Try putting that code in a $(document).ready();

Drupal ajaxifies it's stuff on document ready so your code might be executing BEFORE the form gets ajaxified by Drupal.

$(document).ready(function() {
  $('#edit-field-image-und-0-upload-button').click(function () {
  alert('hi');
  });
});


The user #1 is special, in Drupal. It will always have all permissions, even the ones not explicitly set for the administrator role.

See user_access() source code.

  // User #1 has all privileges:
  if ($account->uid == 1) {
    return TRUE;
  }


Drupal commerce - passing attributes from one module to other

We already have a rule shipped with the drupal commerce core, which creates the user account on checkout process. It might be a good starting point for you in both ways how it is looping through order information to use in your custom module or you can modify the rule as per your requirement.

Rule is "Create a new account for anonymous user."


Error installing Theme on GoDaddy Drupal 8.4.5

Based on the two errors you noted:

"The website encountered an unexpected error. please try again later."
the file is over 2mb

It sounds like your web-hosting provider/CPanel account has a limit on file uploads set, and:

a) your Drupal Core update/upgrade wasn't completed successfully

b) you may not have a temporary directory configured properly for unzipping the theme archive.

Recommended course of action would be to:

finish your Drupal 8.4.5 upgrade (or perform a fresh install on GoDaddy).  If you're drupal core codebase was updated, be sure to go to update.php to ensure all Drupal database updates were applied.
Once Drupal Core has been updated and you can navigate the site/add test content successfully, unzip the theme codebase locally and upload the "nexus" folder to your Drupal site's /themes/custom/ folder using either GoDaddy's file manager, ftp, or via version control tools such as git.
With the theme folder manually installed to the server, flush the cache of your Drupal site; go to Appearance, select and enable the Nexus theme.


What to do in a case of plugin ID not found?

It looks like the error is coming from a missing plugin provided by the group_node module, which if I recall ships with the Group module. Try re-downloading that module to your codebase, and clearing your cache. If that doesn't work, uninstall the group_node module.


Daily cron job send email Webform submissions file

You could create a view that shows the days submissions, use the data export module to convert it to excel, filter it by day (currrent day). Use rules module to send an email (not sure how to attach it, may need to send link). Not sure if this would work exactly how you need it.


I found the issue. I found this stuck in the node template:

<?php if (!empty($node->field_white_paper_file['und'][0])){
  drupal_goto(file_create_url($node->field_white_paper_file['und'][0]['uri']));
 }?>


How do I in Drupal 7 hook into the status message update area after saving a node and it says "updated node" to be a link to that node

You can use hook_node_update() that responds to node updates. There you can add the link in drupal_set_message().

However you may get two status messages, a default status message and another the custom message you just created. For removing the default message you can use Disable Messages module.


Looks like you're just missing the column name for the field (tid).

Just before the return of the widget form function, try changing

$element +=  $widget;

to

$element['tid'] = $widget;


The admin/reports/status/php is actually the output of phpinfo() and it simply shows your PHP configuration summary.

https://stackoverflow.com/questions/3202872/php-serverserver-addr-variable-always-returns-127-0-0-1
suggests using this code to get the real IP:

getHostByName(php_uname('n'));


How can I add a caption to my navigation menu?

function MYTHEME_menu_item_link($link) {
  // Debug:
  // dpm($link);

  // Check menu item localization settings:
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }

  // Target the desired menu:
  if ($link['menu_name'] == 'primary-links' && $link['options']['attributes']['title']) {

    // Theme menu item description:
    $desc = '' .
      check_plain($link['options']['attributes']['title']) .
    '';

    // And title:
    $link['title'] = '' .
      check_plain($link['title']) .
    '';

    // HTML should be enabled:
    $link['localized_options']['html'] = TRUE;

    // Theme the menu item title as a link, then append the description:
    return l($link['title'], $link['href'], $link['localized_options']) . $desc;
  }
  // For other menus:
  else {
    return l($link['title'], $link['href'], $link['localized_options']);
  }
}

Place this into your theme's template.php
Don't forget to flush your Drupal cache at admin/settings/performace (D6)


You could use CSS:

#main-menu-links li.menu-276 a {
  background: url(path/to/img.png) no-repeat left;
  padding-left: 16px; /* Change depending on icon size */
}


As far as I can see, there isn't any PDO wrapper for MongoDB, and there isn't any code that allows to use MongoDB as database for Drupal, simply for the fact Drupal expects to use an SQL database engine, while MongoDB is not an SQL database. You cannot generally convert a static query into code that uses MongoDB.

The Mongodb module allows you to use MongoDB in those cases where Drupal is not expecting to get data from a database, although the default implementation uses database table. That is what happens for the cache, entity fields, and Drupal queue, for which a module can define a new PHP class to implement a different mechanism to store data.

Notice that the Mongodb module is not tightly integrated with Drupal entities, as it doesn't use any Drupal entity to work. It eventually allows you to store field data in Mongodb, but that is an additional module you can eventually use. If you are not interested to store field data in MongoDB, the main module (mongodb.module) still works, and can be used from the other sub-modules.


If you have some control on the Aegir instance, and 100% trust your users that have sftp/ssh access to your site, you could use the provision_customhtaccess module:
https://github.com/mlutfy/provision_customhtaccess

This makes it possible to have a "htaccess-custom" file in your sites/example.org/ directory that will get included in your vhost configuration. However, it is a big security risk if you do not trust your users. They can close a vhost declaration, open a new one, do many bad configurations, etc.

Alternatively, if you're going to write a new module, it seems pretty easy to add in the match_redirect module. There is a feature request open, so I am sure the community would appreciate. Worst case, you can offer the maintainer to sponsor the development:
https://www.drupal.org/node/2118233

You can see how drupal_match_path() does a match and use that to rewrite the target redirect:
https://api.drupal.org/api/drupal/includes!path.inc/function/drupal_match_path/7


How can I provide a checkbox to display name as 'anonymous'?

You can add one more text field to user entity, keep it hidden.While registering the user check if show as anonymous user field is checked save the hidden field value as anonymous else copy the user name field to hidden field.

You can do the above changes in hook_user_presave().

Finally add this hidden field to your user view, instead of name field.


How should I go about placing the content of a field from a content type into a block?

this can be possible by using views which is now in core in drupal 8

step 1 :: go to structure->views->add new views

step 2 :: Add new view ui will be opened

2.1.enter view name

2.2.under view settings select show content of type (the content type     whose field you would like to place in an block ex:your required content type)

3.only check the check box create a block under block settings

2.3.1.under BLOCK DISPLAY SETTINGS select the display format most likely
 (unformatted list) of fields

2.3.2 now save and edit and you are good to go...

step 3 :: now views ui is opened

3.1.on the top left hand side of the page under title

3.2. under fields select add (an pop up ui will open)

3.3. select type content ->select the field types of your content you want to display in your block ex-body and so on and so forth as required by you now apply and save..

3.4. configure field will now open configure as required..you can also rewrite the fields so better follow this link
rewrite fields

step 4 :: go to structure->blocks->place the block as per your required region->and find the block(it will be the same name as block name or view name unless changed)

4.1. place the block as per your wish there are many boundaries like selecting content type etc ...but for now select pages under visibility
leave the check box as default and inside pages type <front>
**remember to add less than and greater than sign as well

4.2.now save the block

step 5 :: in the block ui at the bottom also click save blocks and finally go back to the site

if all goes right you will see the content of a field from the content type in a block using views


Adding fields to user registration form for admins

You could use hook_form_alter to accomplish this

yourmodule_regform_alter($form, $form_state) {
    global $user;
    if($user->uid!=<whatever>) {
        unset($form['field_attended'];
    }
}

If you want to use permissions, you could create your own with hook_permission

function administer_attendee_permission() {
    return array('set attendee status' => array(
      'title' => t('Set status for event attendees'),
      'description' => t('Set the status for event attendees'),
     );
}

Then your form alter changes to

yourmodule_regform_alter($form, $form_state) {
    if(!user_access('set attendee status') {
        unset($form['field_attended'];
    }
}


Hm, if I understand you correctly you want to extend a fields schema. As far as I know, there is no easy way of doing this, e.g. there is no hook_field_schema_alter(). And the way that comes into my mind to achieve this is rather complicated and involves a lot of different hooks and logic that seems just bloated and error prone.

Instead I would recommend to create a new field type module based on the one that you want to extend, then alter this so that it suits your needs. Obviously this should only be done if you are still in the development phase of your site. If there is already any content this could do more harm than good, because you would need to migrate the content.

Another way, little elegant, but certainly possible is to create your proper storage solution for the information that you want to attach to the field(s) in question, meaning providing custom database tables and implementing the hooks described in field.api.php that you need for your use case.


File/function that is executed when I open node from view

You've two ways to afford the problem:
Site building way
If you're using a wiew of rendered nodes (usualy teasers) you can redefine the layout, tags, fields, etc. on admin/structure/types/manage/YOURCONTENTYPE/display/teaser

If you need more options try display suite and fences modules:
https://www.drupal.org/project/ds
https://www.drupal.org/project/fences

Developer way
Editing your view, on the "advanced" colum, "other section" you've the "templates" there the "Theme: Information" item.
There you've the name of the templates the view is using.
You can redefine then on your custom them.

EXTRA BALL: Common sense way
Probably a mix of two others are que best option


Your close, however, I think there are two changes you'll need to make.

You'll need to add $form_state['bundle'] = "visitor_sign_in"  to your $form_state array()
You'll need to pass an (object) $node as the third parameter to drupal_form_submit.

The changes might look something like this:

function visitor_email_staff_form_alter(&$form, &$form_state, $form_id){
  if ($form_id == 'visitor_sign_in_node_form'){
    $form['actions']['submit']['#submit'][0] = 'visitor_email_staff_my_custom_submit_handler';
  }
}

function visitor_email_staff_my_custom_submit_handler($form, &$form_state){

  $guestName = $form['field_visitors_name']['und'][0]['value']['#value'];
  $staffName = $form['field_tags']['und']['#value'];
  $visitorTitle = $guestName.' - '.time();

  $staffTaxonomy = taxonomy_get_term_by_name($staffName);

  foreach ($staffTaxonomy as $email) {
    $staffEmail =  $email->description; // email address
  }

  $form_state = array();
  $form_state['values']['bundle'] = "visitor_sign_in";
  $form_state['values']['title'] = $visitorTitle;
  $form_state['values']['field_visitors_name'] = $guestName;
  $form_state['values']['field_tags'] = $staffName;
  $form_state['values']['field_timestamp_in'] = time(); // timestamp
  $form_state['values']['field_timestamp_out'] = '';
  $form_state['values']['op'] = t('Save');

  drupal_form_submit('visitor_sign_in_node_form', $form_state, (object)$node);

}


maintain password value after failed login attempt

The password field doesn't use the "#default_value" property. This means that is not possible to pre fill the field with a default value as it is possible with a textfield field. As it is not possible to set a default value for the field, a password field is always shown empty.

It is what I would expect, especially when a validation handler returns an error for the entered password. If the password is wrong, I don't see any reason to pre fill the field with what previously entered, considering that what the user sees is something similar to "•••••" (or a group of asterisks).


AJAX form submit error when sending form to twig in hook_preprocess_page

The #ajax['wrapper'] replaced with #ajax['wrapper_selector'] that's why the form disappear see this issue:

Try with:

<?php

namespace Drupal\mymodule\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

class SubmissionForm extends FormBase {

  public function getFormId() {
    return 'mymodule_submission_form';
  }

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['#prefix'] = '
';
    $form['#suffix'] = '
';

    $form['mail'] = [
      '#title'    => 'E-mail',
      '#type'     => 'textfield',
      '#required' => TRUE,
    ];

    $form['actions'] = [
      '#type' => 'actions',
    ];

    $form['actions']['submit'] = [
      '#type'       => 'submit',
      '#value'      => 'Submit',
      '#attributes' => [
        'class' => [
          'btn',
          'btn-success',
          'use-ajax-submit',
        ],
      ],
      '#ajax'       => [
        // Change here the wrapper with wrapper_selector
        // 'wrapper' => 'submission-form',
        'wrapper_selector' => '#submission-form-wrapper',
      ],
    ];
    return $form;
  }

  public function validateForm(array &$form, FormStateInterface $form_state) {
  }

  public function submitForm(array &$form, FormStateInterface $form_state) {
  }
}


How to place a menu link in views footer?

You have created a view for recent news. Just add a footer to the view and then implement php l() function for your menu in the global text area of the footer.


I used a module called Smart Breadcrumb that builds breadcrumbs by using the url path and determining the title for each page. So far its Drupal 7 only.
https://www.drupal.org/project/smart_breadcrumb


Slideshow with images of a gallery ,at the end of the gallery next gallery images should start

There are a couple of things that you need to think about.

First, what do you mean by the "next" gallery? You will need that value to populate the link to the next gallery.

The slideshow can take an argument of the gallery ID, which will limit the images displayed to one gallery. You can then create another view which takes that argument and displays a field (which is a link to the "next" gallery).

You can filter by node type, order by whatever you want to order by, limit to display only one node (of type gallery), and, finally, filter by the same thing you are ordering by, but use the filter to limit the list to what is appropriate, ie, do not display nodes with node id greater than (or less than) or equal to that of the argument, so you don't get a duplicate.

Then you attach that view to the gallery view, and you have a link to the next gallery. You may be able to do something with an Ajax module if you don't want the page refresh.

I'm actually having a similar problem. The issue I'm having is that I want to display the latest gallery (my galleries have a CCK date field). I can do that, but I want to limit by gallery id. However, I won't have the gallery ID because I'm displaying the "latest" gallery, so I can't just do a simple filter by gallery id. I can sort by the date, but I can't seem to limit the results to the same parent gallery without the gallery id argument. Any ideas would be greatly appreciated.


Where can I alter the labels used on the login form?

Try this way by implementing hook_form_alter.

/**
 * Implements hook_form_alter().
 */
function YourCustomModuleName_form_alter(&$form, Drupal\Core\Form\FormStateInterface $form_state, $form_id){
    if ($form_id == 'user_login_form') {
        //- change label for username input
        $form['name']['#title'] = t('Your New UserName Label');
        //- change label for password input
        $form['pass']['#title'] = t('Your New Password Label');
    }
}


Need to redirect the homepage to a different url but keep the site live and accessible

They are many solution to redirect from the page.

If you are using Apache you can use .htaccess to redirect the front page to a different website. This would be the faster due that is on the server level. Here is more information about redirects on Apache.
If you are using Nginix here are some instructions
Another option would be doing it on the theme level. If have access to the theme you can write  sites/all/themes/YOURTHEME/page.tpl.php.

<?php
   if(drupal_is_front_page()) {
     header("location: http://www.RedirectPage.com");
     exit;
   }
?>

If you dont have access to the theme or to the server. The easiest way to have a redirect is by using the meta tag. You can add a block to the front page and add the following code.

     <meta http-equiv="refresh" content="10; url=http://www.RedirectPage.com/">

For more information about Redirect check this article.


Altering the view mode of rendered entities in a View Context via Ctools Plugin

I think you can bypass Views and get what you want with a content type plugin that does a query for the nids you are interested in, then passing that array to drupal_load_multiple(), then passing the result of that call to drupal_view_multiple().

drupal_view_multiple can take whatever view mode you want as a parameter, and will return a render array that you can just throw at whatever custom extra theming you need to do before displaying it.


How do I find out which Contrib module is compatible with PHP 7?

Sort of.

The PHP version isn't a required key for module .info files, and it's a minimum version of compatibility anyway. So a module could declare itself as requiring PHP5.6, but still work absolutely fine under PHP7. Or it could not declare a minimum version of PHP at all, and still work under PHP7. Or it could declare PHP5.6 as minimum, but not work at all in PHP7. You get the idea.

So yes, you need to check on a case-by-case basis to find out which will work under a specific version of PHP.


Using variable_get from DrupalWebTestCase

Just faced a similar issue. What I have found out is that in your DrupalWebTestCase child class you still have access to all variables defined in settings.php before calling parent::setUp(). Which means you can do something like this:

class MymoduleWebTestCase extends DrupalWebTestCase {

  public function setUp() {
    $mymodule_test_sftp = variable_get('mymodule_test_sftp');

    parent::setUp();

    variable_set('mymodule_test_sftp', $mymodule_test_sftp);
  }

}


Simplenews Scheduler - only send newsletter when attached EVA view contains results

did you find out a way to do it? In your example, using views_get_view will always return true, because even if the view has no result, the result of the function will be an object, so will not be empty. If you're using views_get_view, you will always have a <div> inside.
You should get the view, then do a preview and then check if there is results or not.

Like this:

 $view = views_get_view('view_id');
 $print_view = $view->preview('display_id');
 if(!empty($view->result)) {
   print $print_view;
 }

I would be happy to know if you found a solution to this because I will face the same problem in a couple of days, thanks!


How to disabled Statistics module for role or anonym users?

The statistics module doesn't provide that option, or an easy way to inject that logic at first glance.

If you're using the AJAX counting method, you can implement hook_js_alter() to change the settings that the module adds, specifically altering the path it sends the tracking AJAX request to. You can change that to a file controlled by your own module, and you can make the decision whether or not to save the record based on the current user in there (after copying the code from the stats module's own statistics.php file).

If you're not using the AJAX method, there are a few different ways you could attack it, but each are more of a pain than it's probably worth. If the AJAX version isn't an option, I'd recommend writing your own custom module that incorporates the existing logic from Statistics that you need, plus your new logic.

The other options are doing things like trying to remove the Stats module's implementations of hook_exit() and/or hook_node_view() from your own module, and re-implementing them. This is never a great approach as you have to re-visit your module every time there's a core update to make sure nothing's changed.

Or, you could maintain a patch to the core module. Usual caveats apply if you go down that route obviously.


How to send a push notification with Rules to specified user by grabbing UID from content field?

Use the button that says Switch to direct input mode. And verify if you can use any of the tokens shown there as the identifier you're looking for.

If no appropriate token is shown, then try to add an appropriate Rules Condition with Entity has field, to make the field you need available for further processing in the rule. That's also what is mentioned in the Rules UI when you're adding a "data comparison" condition: somewhere it says "The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type')". For a video tutorial that illustrates the importance of this Entity has field condition, refer to Data types and data selection, especially what is shown between about 13:30 and 17:30 in that video.

However, as per your "... content field ... from Content Type 'friends'*" (as in your question), the above may not be sufficient yet (= the appropriate token is still not shown). I.e from the label(s) it sounds that this could well be a multi value field (of type entity reference?). In that case you first need to add a "Rules loop" to iterate of the list of friends, so that inside that loop you can use a token related to the uid of the current list item being processed.

The above are just 3 of the typical/possible approaches to get access in a custom rule to some token you're looking for. There are others though, such as:

using Rules Action to "Fetch entity by ID", or
getting the Views Rules module involved,
etc.

Note: In case you're using the Push Notifications module, you may want to have a look at its community documentation related to Rules integration, especially this screenprint on that page seems pretty similar to what you're looking for (if you can reference the node:author token, it should also be possible to reference some other field of a node).


Using #states API with an image field as a control field

You should be able to do it with #states just fine. Maybe double check your input name or try something a little different depending on what the html for that element looks like. This is the code I am using that works.

 $form['field_hero_image']['#states'] = array(
  'visible' => array(
    ':input[name="field_image[und][0][fid]"]' => array('empty' => true),
  ),
);

This causes it to only appear if there is no value for the input fid. Pertinent HTML:

<input type="hidden" name="field_image[und][0][fid]" value="1088">
<input type="hidden" name="field_image[und][0][display]" value="1">
<input type="hidden" name="field_image[und][0][width]" value="915">
<input type="hidden" name="field_image[und][0][height]" value="450">

Note:

'visible' => array(
    ':input[name="field_image[und][0][fid]"]' => array('value' => 0),
  ),

may work just as well (untested)


How do I apply a patch with Composer workflow?

The issue is that composer is applying patches using git apply which is not working for packages that are not installed from source.

Therefore the solution is to install the packages from source. This way the package will fetch the package along with its repository (when available) thus enabling it to be patched.

So...

How to install/update a package from source

For new packages:

Use

composer require vendor/package --prefer-source

For existing packages

If your package is already installed then you need to delete it so that you can re-fetch it with composer install (there is no composer reinstall command). Do so and then use

composer install vendor/package --prefer-source

Set it as the default behavior

You can also set it up as the default behavior for the project in the config section of composer.json:

"config": {
      "preferred-install": "source"
    },

Update:

Set it as the default behavior for a specific package

In case you don't want to set your entire project to install from source, you can do so for a specific package only. To do so you need to specify the VCS Branch in the Version constrain of the package.

"require": {
        "vendor/package": "dev-branch#branch-hash"
}


How can CSS emulate content display with labels in one column and data in the other?

Field content supposed to live inside div.field-items, so you can set "width" or  "max-width" properties to div.field-items. Value of width/max-width should be same as or smaller than parent div.field width minus label width.


Checking for an Acquia Environment variable

The other question mentioned having passed that variable from a preprocess function to the template first. I guess that can be done using PHP's getenv then. Let me just try that out.

Yep, that works.

/**
 * Implements template_preprocess_page().
 */
function MYTHEME_preprocess_page(&$variables) {
  $variables['my_environment'] = getenv('AH_SITE_ENVIRONMENT');
}

Then continue in page.tpl.php.

{% if my_environment == "prod" %}
  // Javascript Analytics Code
{% else %}
  <!-- env is {{ my_environment }} -->
{% endif %}


Trying to enable clean URLs: The clean URL test failed

The file name should just be .htaccess, without the .txt extension.


In Drupal 8, you use the languageManager class to get the language code:

$languagecode = \Drupal::languageManager()->getCurrentLanguage()->getId();

EDIT: If you want to return NONE if the current language is the default language, you probably need to make a helper function:

$languagecode = \Drupal::languageManager()->getCurrentLanguage()->getId();
$default_languagecode = \Drupal::languageManager()->getDefaultLanguage()->getId();
if ($languagecode == $default_languagecode) {
  return "NONE";
}
else {
  return $languagecode;
}

helper function to ge it from settings

function getLanguagePrefix() {
    if($prefixes = \Drupal::config('language.negotiation')->get('url.prefixes')) {
      $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
      return "/". $prefixes[$language];
    }
    return null;
  }


Assigning a badge to a user using Flag, Badges and Rules

I would use the Goals module for this.

Create a 'Favorite node' task and a 'Favorited 3 nodes' goals.
Add an image to the goal. This is going to be your badge.
Create an 'Add to favourites' flag.
Create a rule that "records a task for goals" when a node is "flagged under 'Add to favourites'".
If you don't really need the User badges module, you can create an image field called 'Badge' for the users and use the following custom module (you can find more information here):

function MYMODULE_goals_completed_goal($goal_id, $uid) {
   $user = user_load($uid);
   $goal = goals_load($goal_id);
   $fid = $goal->goal_img['und'][0]['fid'];
   $img_title = $goal->goal_img['und'][0]['filename'];

   $edit = array();
   $edit['field_badge']['und']['0']['fid'] = $fid;

   user_save($user, $edit);
}

If you really need the User badges module, I think you can adapt the code a bit and everything should work fine.


It is more likely a Javascript / jQuery related questions rather then Drupal.

The button label and text is defined by the browser which you cannot tweak in Drupal. But with Javascript / jQuery, you can override and take over event for creating your own file upload button.

Since jQuery is included in Drupal, a jQuery library should be suitable for you. jQuery File Upload is one of the best library for this purpose.

I found there are 2 contrib modules. They are jQuery File Upload and jQuery Upload FAPI.


One solution here, that is slightly different from your question, is to use Views/Views Bulk Operations (VBO) & contextual filters on a custom View.

VBO contains an operation for bulk deletion. You can create a contextual filter for Content: Nid with the Allow multiple values option selected. If you've created a page view, that would allow you to navigate to http://example.com/my_node_delete_vbo_view/1+2+3 wherein you can view all the nodes you want to delete, select them all, then apply the Delete item VBO operation.

The only work involves taking your CSV, slicing it down to just the node column, and replacing the character delimiters.


Where are display settings for nodes stored in the DB?

With basic Drupal, the db table is field_config_instance, all in the "data" column.

With Display suite, you should also look at ds_fields, ds_field_settings, ds_layout_settings.

(Use drush sqlc for a mysql commandline, and then "describe ds_field_settings;" etc.)

This being said, you really want to look for API functions. Look at:

field_ui_display_overview_form_submit()
For display suite I'm not completely sure where you need to look.. But again, submit handlers are usually a good place to look.


All security announcements are posted to an email list as well. Once logged in, go to your user profile page and subscribe to the security newsletter on the Edit » My newsletters tab.

You can also get rss feeds for core, contrib, or public service announcements.


How do you edit the link count on /poll index page?

It's hard coded in poll module poll.pages.inc file...

function poll_page() {
  $polls_per_page = 15;

  $count_select = db_select('node', 'n');
  $count_select->addExpression('COUNT(*)', 'expression');
  $count_select->join('poll', 'p', 'p.nid = n.nid');
  $count_select->condition('n.status', 1);

  // List all polls.
  $select = db_select('node', 'n');
  $select->join('poll', 'p', 'p.nid = n.nid');
  $select->join('poll_choice', 'c', 'c.nid = n.nid');
  $select->addExpression('SUM(c.chvotes)', 'votes');
  $select = $select->fields('n', array('nid', 'title', 'created'))
    ->fields('p', array('active'))
    ->condition('n.status', 1)
    ->orderBy('n.created', 'DESC')
    ->groupBy('n.nid')
    ->groupBy('n.title')
    ->groupBy('p.active')
    ->groupBy('n.created')
    ->extend('PagerDefault')
    ->limit($polls_per_page)
    ->addTag('node_access');
  $select->setCountQuery($count_select);
  $queried_nodes = $select->execute()
    ->fetchAllAssoc('nid');

  $output = '
';
  foreach ($queried_nodes as $node) {
    $output .= '
' . l($node->title, "node/$node->nid") . ' - ' . format_plural($node->votes, '1 vote', '@count votes') . ' - ' . ($node->active ? t('open') : t('closed')) . '
';
  }
  $output .= '
';
  $output .= theme('pager');
  return $output;
}

Override the menu item using hook_menu_alter and change the callback as well as setting which you can see in first line of above function using a custom module.. Otherwise use views to build your own page which will display polls...


Add a term under a vocabulary when a content of particulr type is added

In short, "yes".

Using hook_node_insert() where you can assign a category term value programmatically. Note that this is an over-ride (hook) of the node creation process. Basically do a Googe search for Drupal 7 node creation programmatically", example: Guide to programmatic node creation in Drupal 7. Look for the details on "Term reference (taxonomy) field".

Note that this an advanced Drupal task that involves creating a custom module that's specific to your site. If you're not already familiar with this process of applying hook functions to alter default Drupal functionality then I suggest you do some research on basic Drupal requirements for custom module creation first.

Good luck and keep asking questions, you'll figure it out and might become a Drupal rock star in the process!


How to use a relative path for a theme's favicon

another idea for a workaround would be to overwrite the href property on runtime with hook_page_attachments_alter, somethng like this:

function MYTHEME_page_attachments_alter(array &$page) {
     foreach($page['#attached']['html_head_link'] as $k => $v) {
          if (array_key_exists('rel', $v[0]) && $v[0]['rel'] == 'shortcut icon') {
                  $page['#attached']['html_head_link'][$k][0]['href'] = drupal_get_path('theme', 'MYTHEME') . 'static/favicon.png';
          }
     }
}

or use the default favicon path (MY_THEME/favicon.ico), it will be taken, see this source:

// Generate the path to the favicon.
      if ($cache[$theme]->get('features.favicon')) {
        $favicon_path = $cache[$theme]->get('favicon.path');
        if ($cache[$theme]->get('favicon.use_default')) {
          if (file_exists($favicon = $theme_object->getPath() . '/favicon.ico')) {
            $cache[$theme]->set('favicon.url', file_url_transform_relative(file_create_url($favicon)));
          }
          else {
            $cache[$theme]->set('favicon.url', file_url_transform_relative(file_create_url('core/misc/favicon.ico')));
          }
        }
        elseif ($favicon_path) {
          $cache[$theme]->set('favicon.url', file_url_transform_relative(file_create_url($favicon_path)));
        }
        else {
          $cache[$theme]->set('features.favicon', FALSE);
        }
      }


Node access control based on users at the node edit page

You could use the Group module for this. This module allows any node to be "assigned" to some group. And then it depends how you configure the group roles (which are NOT the standard Drupal roles) about who has what kind of permissions.

For your case, create a group type named something like "Node Authors", and then create a "Group" for each user (using something containing the user's name as its label). And tune the permissions which come with the Group module (which are different from standard Drupal permissions!) to fit your needs.

After you enable gnode, a submodule of the Group module, you can assign any node to a group. In D7, you could simply do so at the node edit page: there is an extra form field on the node edit form which can be used to select the group that you want the node to be assigned to. However, in D8 this is no longer possible, for reasons explained in this comment, and which states:

  ... all content-to-group relationships are now fieldable and we therefore need to ensure the user is presented with the fields that were configured on said relationship. A simple auto-complete to select a group would therefore not work.

Therefor, in D8, this is what you have to do instead, as described also in the feature request "UI: more easily select group for a node":

Open the Groups list and click through it.
Select the appropriate Group.
Go to Group content.
Select "add group content".
Select which group content.

More info:

Refer to "What are the various roles supported by the Group module?" for more details about the supported roles.
Refer to my answer to "How to configure access to courses for teachers and students?" for a sample configuration.


How can I add language selection to the user profile in "my account" settings

The language setting is already present in the account settings page, I was misguided by the first part of the description "This account's default language for e-mails, ..." and skipped over the rest that read "... and preferred language for site presentation." doh!


How to set the Organic Group while saving a node based on the node's current language

Using Rules, you can add an event for when a new node is saved, add conditions for both content type and language and then use an action for assigning the OG's nid to the og_group_ref field.

Use set a data value if cardinality of the node is set to 1 or add to list for more than 1.

Without rules or code, I would have a new node link in each organic group and prepopulate the language and og_group_ref fields.


This isn't the "Drupal way" to do this, but I accomplished a successful quiz results migration by making a few compromises and doing things in an unorthodox way. If anyone can build upon this and add a new answer with the correct way accomplish, I would be delighted!

The compromise I made was not allowing users to view their old results, just their score. I also decided not to use the certificate and created a view page instead for individual scores to make a certificate that way. (See this SE Post for my issues with Certificate.) This killed 2 birds with 1 stone.

Steps I followed for a successful migration trial on the test website:

Add quiz_node_results table to new database:

mysql> insert into drupal.quiz_node_results (result_id, nid, vid, uid, time_start, time_end, released, score, is_invalid, is_evaluated, time_left) select result_id, nid, vid, uid, time_start, time_end, released, score, is_invalid, is_evaluated, time_left from drupal_web.quiz_node_results;

Replaced NID of quiz results with new quiz nid, run once for each quiz (there were 18 quiz nodes):

mysql> update quiz_node_results set nid = replace (nid, [old quiz node ID], [new quiz ID]);

Removed "view quiz results" from Gradebook view (custom view I built for showing results).

Please comment with foreseeable issues with this method.


Custom node template with related node teasers

A valid "view_mode" should work with node_view and that approach looks reasonable.

However, if it's proving problematic, you can also use Views with views_embed_view

e.g

print views_embed_view('viewname', 'display_id', $node->nid); // node id contextual filter


address dependent locality field not shown

i must be blind... right under the doc i was reading i see

The Commerce Guys addressing data set only includes subdivisions that are required for addressing.

so this field is not included because it is not needed for an address.


It seems like the sample.views.inc file does not get loaded during the access-check (as the registry already cached the information which callback it needs to execute).

So you can just move sample_access() to the file sample.module and the callback works.


I finally found the reason for this weird problem: my comments' template contained a misplaced global $user;. I don't know why this causes trouble, but at least it's fixed now. Hopefully, this can get people with a similar problem on the right track to find a solution.


The proper way is in a preprocess function and this does exist for the menu template. The reason is caching. In the preprocess function you can check if the caching metadata is in synch with the additional information you add to the twig.

In case of the language, you might get this working in a Twig function, because many templates are already cache dependent on the language, but not with other information like (for example) information from the current user.

This is an example for the menu preprocess function from the Bartik theme.

/**
 * Implements hook_preprocess_HOOK() for menu.html.twig.
 */
function bartik_preprocess_menu(&$variables) {
  $variables['attributes']['class'][] = 'clearfix';
}


Unable to remove label field from the registration form

Actually the can be changed using this code:

$form['field_company_name']['widget'][0]['value']['#title'] = $this->t('WHATEVER');


How to validate node field for minimum length for a custom content type?

hook_form_alter() would alter your node edit form to define a custom validate handler.

function custom_module_form_alter(&$form, &$form_state, $form_id){
   ...
   case 'form_id': //applying this check will help to restrict only on certain content type form
      $form['#validate'] = 'custom_validation_handler';
   break;
   ...
}

And when this validation handler is invoke upon submitting the node form it will validate the field value in following logic.

function custom_validation_handler($form, $form_state){
   if(strlen($form_state['values']['field_id']) < 200){
       form_set_error('field_id', t('message about validation error'));
   }
}

If form_set_error() is invoked the form will not be submitted and will be back with validation error message.


How to make hook in custom module to execute only on condition

Let the hook be called, but put your operations(that your hook executes) inside your required condition.

function mymodule_modulename_alter($parameters) {
  if ($condition) {
    // Your code.
  }
}


Create any number of paragraph fields in a multiple value field on node create form

Instead of adding the multi value field items after the form is built you can try to do this on the entity before the form is built:

/**
 * Implements hook_ENTITY_TYPE_create() for 'node'.
 */
function mymodule_node_create(\Drupal\node\NodeInterface $node) {

  if ($node->getType() == 'my_content_type') {
    // get taxonomy terms
    $query = \Drupal::entityQuery('taxonomy_term');
    $query->condition('vid', "my_voc");
    $tids = $query->execute();
    $terms = \Drupal\taxonomy\Entity\Term::loadMultiple($tids);

    $count = count($terms);

    $i = '1';
    foreach ($terms as $term) {
      $paragraph = \Drupal::entityTypeManager()->getStorage('paragraph')->create([
        'title' => 'Paragraph ' . $i,
        'type' => 'my_paragraph_type',
         // more field data
      ]);
      $node->field_features_para[] = $paragraph;
      $i++;
    }
  }

}


Encrypt module; Is there a way of using db_query() on encrypted values?

You can see from your DPM that your encryption method is returning an array containing several different values. You can't use an array for a database field value it would need to be a string in this case. So you need to use just the  encrypted hash string from that array in your db_query e.g.

array(':email' => $email['text'])


If I understand you correctly, you should be doing this

$form['style']['fixed_navbar'] = array(
    '#title' => t('Fixed Navbar'),
    '#default_value' => variable_get('fixed_navbar', 1),
    '#type' => 'checkbox',
);


Panels variant selection rules using query string in the URL

You can accomplish using query strings in panels if you use php code for your selection criteria.

Something along the lines of

$url_comp = explode('/', request_uri());
$desired = $url_comp[2];
check_plain($desired);
if ($desired == "page?querystring=1") {
return true;
}

will provide you with the access check on whether or not to show the panel variant. Check_plain may be called incorrectly in the code above but including some sort of check to make sure your querystring is clean would be very advantageous to prevent any sort of security issue.

You may need to adjust the position of your desired path above. url_comp[0] will return empty, url_comp[1] from your example above would return mypath and url_comp[2] would be page?querystring=1

I came up with the idea for this approach from the comments on https://api.drupal.org/comment/18449#comment-18449


If you can't do all that with the superuser (typically admin, user ID 1), checking permissions won't help, since that account has a "pass all permissions" check on nodes, modules, users, etc.

To figure this out, you can try a few things:

Go into the database and check if your admin user really has uid 1 (in the users table)
Check modules (custom modules, specifically) to see if any of them deny access to any admin pages


how to add 'OR' operator in views sort criteria

What do you mean add OR? There is no such condition in sorting. You can have different sorting levels. Add multiple values in the view's ui sorting criteria and then re-arrange properly.


Entity reference with ddf, dynamic dependent fields

DDF is a complex-looking module but there are only a few areas where you might make a mistake.  Try enabling the submodule "DDF Entity Reference" on the modules page if you have not done so already.  If you are still having problems after enabling the submodule, post here and I'll take another look at your entity reference view setup.


First understand entities, attributes, bundles and fields:

Node and User are entities. Both have a unique identifier. For Node it is nid, for User it is uid. Entities have attributes associated with them. These are the fields that you will see in the Node or Users table in the database. For instance, Node has author, data published etc, and User has name, mail etc.

Between the attributes of entities there are links, for instance: Node has an author, which is just the uid key of the User entity. In other words via a SQL join you can get from the one to the other. This is what Views do when you add a user relationship on the node view to bring in the extra information of the user table.

Bundles have fields. A bundle is an entity type with additional fields attached. For instance, Article is a bundle of entity type node. Article has all the attributes of Node, and it also has an image field. If you look at the Node table there is no image field on it. The image field is created as its own table,   field_data_field_image. In this table there is a field entity_id which contains the nid of the node it belongs to.

When you add a field that is not part of the node entity (node table) but part of the bundle (ie Article) to Views, Views will do a SQL join to get that field
into the display. Therefore Views is bringing in a relationship for you, nl. the relationship between the entity and the field.

When you install Entity reference you can add a field to an entity that will reference another entity. For instance, you add an entity reference field to an Article that can reference Basic Pages.

In the database you have now added a new field as a separate table which points to the node, of type article, as its parent container, as well as to the node of type Basic Page as the referenced node. It looks like this:

To add it to Views you need to include the relationship manually as an Entity Reference. There will be two possibilities:

Entity Reference: Referenced Entity - A bridge to the Content entity
that is referenced via field_reference
Entity Reference: Referencing entity - A bridge to the Content entity
that is referencing Content via field_reference

which is just the direction of the relationship. If I have the article in my View and I want to include the Basic Page, then it will be Referenced Entity. If I have the Basic Page and I want the Article, then it will be Referencing entity.

Views will bring in this relationship via two joins, the first to bring in the field belonging to the Article, and the second to bring in the Basic Page node that is pointed to by the entity reference field (the order depending on the direction)

NOTE that you can bring in even more relationships in a chain-like fashion. You may have a node whose author user has an entity reference to a profile type node that has a Taxonomy Tag etc.


Drupal 404 redirect to a custom PHP file

Ofcourse there is a module for this too.. !!!
Search 404 Module would help you achieve this

Instead of showing a standard "404 Page not found", this module performs a search on the keywords in the URL
It also has Support for Custom Text and Title to be displayed in search404 pages


In Drupal 7, What is a good approach to copy the image from one imagefield to another imagefield?

You should only use one image field, and then setup 3 image styles at:

  admin/config/media/image-styles

For each image style you can define a number of different actions, like cropping. When displaying the image you can use theme_image_style()

This is a part of Drupal core and can be extended by e.g. ImageCache Actions.


In a theme, you just declare the mytheme_links__main_menu() function in the template.php file. (Replace mytheme with the actual name of the theme.)

In a module, you declare the mymodule_links__main_menu() function, and implement hook_theme() to define the theme function. (Replace mymodule with the actual name of the module.)

The argument passed to the function are the same passed to theme_links().

$variables: An associative array containing:

links: An associative array of links to be themed. The key for each link is used as its CSS class. Each link should be itself an array, with the following elements:

title: The link text.
href: The link URL. If omitted, the 'title' is shown as a plain text item in the links list.
html: (optional) Whether or not 'title' is HTML. If set, the title will not be passed through check_plain().
attributes: (optional) Attributes for the anchor, or for the  tag used in its place if no 'href' is supplied. If element 'class' is included, it must be an array of one or more class names.

If the 'href' element is supplied, the entire link array is passed to l() as its $options parameter.

attributes: A keyed array of attributes for the UL containing the list of links.
heading: (optional) A heading to precede the links. May be an associative array or a string. If it's an array, it can have the following elements:

text: The heading text.
level: The heading level (e.g. 'h2', 'h3').
class: (optional) An array of the CSS classes for the heading.


limit view result to only commented nodes

You don't need to code something here with powerful Views module.

First, add relationship “Comment: Comments of the node” to current View.
Then in “Query settings” check “Distinct” option. Now you have list of nodes which have comments.
Add contextual filter “Comment: Author uid”, set default value to “User ID from logged in user” and don't forget to check option “Exclude” in MORE fieldset.

Note that this solution works only for current logged in user.


How to create a page view of two content type in Drupal 7

Here's how you do it: Once you've created your view, selecting either one of your content types:

Under "filter criteria", click the filter called "content type (= YOUR_CONTENT_TYPE).
Select "is one of", and then select all the content types you want to include.
Click Apply (all displays).
Save the view.


Drupal 6 CCK fields export/import in between environments

Take a look at the Features module. Exporting your CCK fields as a feature set creates a new module in which the fields are defined in code. You can then deploy the code to another server and enable the feature there. Every time you make a change you export the feature again to update its code, deploy it, then revert it on the other server.

Features is very useful, but takes some practice to get used to its limitations and quirks. Once you get past that point it'll save you a lot of time.


There is a module for that: https://www.drupal.org/project/module_missing_message_fixer

And you can try drush or devel according to the doc here https://www.drupal.org/node/2487215

Use Drush

drush sql-query "DELETE FROM key_value WHERE collection='system.schema' AND name='module_name';"

When done, clear the site's caches (e.g. drush cr).
Also make sure that the CMI folder is cleansed of the broken uninstalled module. There may be some yml files left over and / or some system config. (this is all not the best way to do things as a FYI. However with Drupal 8 being so young, things don't go as planned always).

Use Devel

Enable Devel module and go to /devel/php. This will allow you to run some PHP code and you can execute the following:

$query = \Drupal::database()->delete('key_value')
    ->condition('collection', 'system.schema')
    ->condition('name', 'module_name')
    ->execute();


Want to allow a form on another domain to submit registration to a drupal form

I mean, it has to be possible, because if you don't turn on spam filters you'll get a bazillion fake accounts from automated bots. I'd play around with posting the values from your first site's form using drupal_http_request, something like:
drupal_http_request($second_site_url, array('method' => 'POST', 'data' => $querystring_from_form_values))


How do I bulk delete all content posted prior a chosen date?

Using the Views Bulk Operations (VBO) module, you can:

Create a VBO view
Add a filter (could expose it) for content "Post date" less then required date
Add a bulk operation to "Delete item"
Save the view

With the view you just created, you can then bulk delete the selected nodes.


Multiple Drupal Commerce line items in the database but one in the order page

I finally found out how to do what I want.
The last commerce line items are in the field_data_commerce_line_items table. The commerce_line_item table seems to contain all the commerce line item revisions.

SELECT SUM(quantity)
FROM {commerce_line_item}
INNER JOIN {field_data_commerce_line_items}
    ON {field_data_commerce_line_items}.commerce_line_items_line_item_id = {commerce_line_item}.line_item_id
WHERE order_id = 388

I don't know if it is documented somewhere.
However, it is what I found by reading the source code and the SQL queries.


Blog entries and blog listing page are different content types?

One way to do this is to use the Pathauto module to automatically set your blog URLs.  Set URLs for content of type blog to be blog/[node:title]; then, on the blocks configuration page, you can simply set the pages to be blog and blog/*, which will then show the block only on your blog pages and index but nothing else.


How do I make an object available as a token?

Yes, by making your token a dynamic token in HOOK_token_info() and using the provided name during HOOK_tokens() to dynamically create your replacements.

Example

function HOOK_token_info() {
  ...

  $tokens['mycustomtoken'] = array(
     ...
     'dynamic' => TRUE,
  );

  ...
}

function HOOK_tokens($type, $tokens, array $data = array(), array $options = array()) {
  ...

  if ($type == 'mycustomtoken' && !empty($data['node'])) {
    $node = $data['node'];

    foreach ($tokens as $name => $original) {
      if (isset($node->{$name})) {
        $replacements[$original] = $node->{$name};
      }
    }
  }

  ...
}


Maybe the Webform module is sufficient in your case?

With Webform you can create forms and form components from an UI. When a submission has been made from a user you can setup mails that should be sent.


You have a typo in your statement. It should be:

$block['content']['#attached']['css'][] = drupal_get_path('module', 'mymodule') . '/mymodule.css';

Also, be sure to clear the cache after you add statements like this to your code.


How to show the content of a group on the group page when using the Group module?

To show the content of a group, you need to create a view. The Group module provides Views 'relationships' to any node's parent group.

With that, these are the steps required:

Create a view about content.
Add a relationship to the parent group.
Add a contextual filter on the group's id (gid).
Create a page, a block, a content pane, etc (whatever fits your needs).

Below is an export of a (simplified) view created (in Drupal 7) using the steps described above:

$view = new view();
$view->name = 'group_content';
$view->description = 'Show all nodes that belong to a specific group';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Group content';
$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'] = 'Group content';
$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,
  ),
);
/* Relationship: Content: Parent group */
$handler->display->display_options['relationships']['parent_group']['id'] = 'parent_group';
$handler->display->display_options['relationships']['parent_group']['table'] = 'node';
$handler->display->display_options['relationships']['parent_group']['field'] = 'parent_group';
/* 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;
/* 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: Group: Group ID */
$handler->display->display_options['filters']['gid']['id'] = 'gid';
$handler->display->display_options['filters']['gid']['table'] = 'groups';
$handler->display->display_options['filters']['gid']['field'] = 'gid';
$handler->display->display_options['filters']['gid']['relationship'] = 'parent_group';
$handler->display->display_options['filters']['gid']['exposed'] = TRUE;
$handler->display->display_options['filters']['gid']['expose']['operator_id'] = 'gid_op';
$handler->display->display_options['filters']['gid']['expose']['label'] = 'Group ID';
$handler->display->display_options['filters']['gid']['expose']['operator'] = 'gid_op';
$handler->display->display_options['filters']['gid']['expose']['identifier'] = 'gid';
$handler->display->display_options['filters']['gid']['expose']['required'] = TRUE;
$handler->display->display_options['filters']['gid']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
  6 => 0,
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'group-content';


module_invoke to create user search block not working

The search block only works for the default search type. From search_box_form_submit():

$info = search_get_default_module_info();
if ($info) {
  $form_state['redirect'] = 'search/' . $info['path'] . '/' . trim($form_state['values'][$form_id]);
}
else {
  form_set_error(NULL, t('Search is currently disabled.'), 'error');
}

The third parameters you're passing ('content_search', 'user_search') are ignored. Presumably your default search type is content and that's why you're being redirected to the content search in both forms.

You can build the correct search form pretty easily though:

$content_form = drupal_get_form('search_form', NULL, '', 'node');
$user_form = drupal_get_form('search_form', NULL, '', 'user');


Git with Drupal 7 multi-site, naming directories

You don't need to consider a whacky git-based solution to this, Drupal has you covered.

Just uses aliases in sites.php, and use whatever method you like (assume-unchanged in the index, .gitignore, whatever) to keep sites.php out of the repo.

So on your local machine your sites.php might contain

$sites['website-one.dev'] = 'website-one';
$sites['website-two.dev'] = 'website-two';

And on a remote server:

$sites['website-one.staging'] = 'website-one';
$sites['website-two.staging'] = 'website-two';

And prod:

$sites['website-one.com'] = 'website-one';
$sites['website-two.com'] = 'website-two';

All the while, your sites live in 'website-one' and 'website-two' respectively; no need for tricks.

If you don't want to consider a Drupal-based solution, and still want to use git, I'd advise taking this over to Stack Overflow where such a question would be on-topic.


I would approach this differently. Using PHPMyAdmin or a Database viewer program, I would look at the Database for the paragraph fields table. Then just export table from D7 as a CSV file.

In D8, fill out 1 node paragraph values, just so you get the table structure, and export table as CSV.

Then with excel (or Libre office Calc) copy and paste values from one CSV to another.

Import CSV to D8 Database.

Clear the cache to see changes.


For taxonomy terms :
It is possible, simply delimit your values with commas in your taxonomy field CSV column, and in the Feeds mapping, select "Search taxonomy terms by: Term name" and "Auto create"

Make sure your Drupal field allowed number of values is set to Unlimited (or > 1)

For files:

your file is external and given a URL, feeds will download it and store it
your file is already stored locally then the URI must be either

a stream wrapper (e.g.: public://import/myfile.pdf)
a relative path from your docroot
an absolute path on your system


Allow non-admin users to view an EntityForm submission

By creating a new permission maybe ? Then create the access page via an menu item with the new permssion you created
Give this permission to non authenticated users then.


How to create custom module for admin area in drupal 8

Main question is "how to have a module show up in admin area".

Create your custom module
Create your custom route in the "your_module.routing.yml" - file

Example:

your_module.admin_settings:
  path: '/admin/config/your_module/import'
  defaults:
    _form: '\Drupal\your_module\Form\ImportForm'
    _title: 'Import XYZ'
  requirements:
    _permission: 'administer site configuration'

Define the link in the "your_module.links.menu.yml" - file

Example:

entity.your_module.admin:
  title: 'Import XYZ'
  route_name: your_module.admin_settings
  description: 'Import XYZ'
  parent: system.admin_config_system
  weight: 100

... thats it!
In step 3 this line is the important part:

parent: system.admin_config_system

If you need a menu entry in "structure" you can use:

parent: system.admin_structure

Just read other xyz.links.menu.yml - files to find different parent-path.


Is your js file even working?

Is your JavaScript file jQuery?

In Drupal, you wrap your jQuery code like this

(function ($) {

    //code goes here

})(jQuery);

For Example:

(function ($) {

    $(document).ready(function() {
         $(".button").click(function () {
             $(this).next('.content').hide();
         });
    });

})(jQuery);

Not sure if you did this already.

Did you also add the frugaloop js to your module? Putting it on the libraries folder doesn't do anything unless you call it.

Use the function drupal_add_js to call it.


Custom Region doesnt render at the same position

You can override the block template use by your position (block--menu.tpl.php) directly in your theme folder. By default, the render of your menu must use block.tpl.php from the block module.

I recommend you to have a look at the Working with template suggestions page, and to enable the Theme debug mode to see witch template are used for your block menu.

After, to modify the Classes and the ID of your menu, I recommend you to work with template_preprocess_block hook to modify the block object before the render print it.

You can also have a look at the theme_menu_tree hook, to be able to modify a wrapper of the menu tree, depending on conditions (menu names).
There is also a THEMENAME_menu_tree__MENU_NAME possible method, that work only for one specific menu.


I had the same issue and I managed to solve it by finding the following issue/patch: https://www.drupal.org/project/page_manager/issues/2921404#comment-12526453


In Taxonomy View, how do I get the count of relationships associated with that term

You can solve this two ways:

You can create a view of nodes, create a relationship to their taxonomy term, and display the terms. This will only display terms that can be pulled up through a node by views.
You can keep your taxonomy display and add a relationship. Add "Taxonomy: content with term" and the check the box labeled "Require this relationship". This will give you duplicates so you also need to go down to "Query Settings" and check the box for "Distinct".