How to display a block to a specific user?

I would implement hook_block_view_alter() and remove the block's content when the uid is not the user you were aiming at. In this example we only show the block content for uid 2.

function hook_block_view_alter(&$data, $block) {

   if ($block->module == 'somemMdule' && $block->delta == 'someDelta') {
         global $user;

    if ($user->uid != 2) {
       $data['content'] = array();
    }
  }
}


How to show album title for 'album with no photos' in view

One of two ways:

1) Create a Header. Under Header (middle of page) create a Global Text. This will create a title for the View regardless of it's contents

2) Under Advanced, create a NO RESULTS BEHAVIOUR. This functions on the view as a whole, so that if there is not content to display at all, this will be displayed


Check for arg(2) to differentiate both paths. Arg() function docs.

In case user/1 arg(2) will be Null

Incase user/1/edit arg(2) will be 'edit'


Add Additional Submission Processing To "Create Node" forms

In Drupal 6, this was done in hook_nodeapi.

In Drupal 7, this is done in hook_node_update & hook_node_insert

hook_node_update($node)
This hook is invoked from node_save() after the node is updated in the node table in the database, after the type-specific hook_update() is invoked, and after field_attach_update() is called.

hook_node_insert($node)
This hook is invoked from node_save() after the node is inserted into the node table in the database, after the type-specific hook_insert() is invoked, and after field_attach_insert() is called.

there is also hook_node_presave($node) if you want to do something before its been save

More information on api.drupal.org & link to the D6 to D7 upgrade changes


How to add "rel=nofollow" to ALL external links?

Have you tried this module : Noindex External Links

Module let's you take full control of external links indexing. Pages could also pass HTML-validation.

  Features

  Two methods of indexing control:

  Wrap links with NOINDEX tag. NOINDEX tag is used to deny indexing part of page. Only Yandex and Rambler considers this tag but Google
  and others doesn't. There is also an attribute NOINDEX in meta-tag
  Robots.
  Add attribute rel="nofollow" to links. This link's attribute has no effect on indexing. Only Google really do not follow this links but
  others do. Attribute is used to say to search engine that links no
  longer constitute a "vote" in the PageRank system.


HTML tags in a block body are not rendred

It's rendering the block's content a plain text, not HTML, because you aren't setting the body field's format property when creating the BlockContent entity.

$blockContent = \Drupal\block_content\Entity\BlockContent::create([ 'type' => 'basic', 'info' => 'Why choose us?' ]);
$blockContent->body->value = '
&nbsp;

Lorem Ipsum is simply dummy text of the printing and typesetting industry.
';
$blockContent->body->format = 'full_html';
$blockContent->save();


Redirect node/id to node/path-auto-alias

Found my mistake, you can't have Check access to the redirected page enabled in the global REDIRECTS.


Why is it better to use event subscribers rather than hooks

You can see this from two perspectives. First of someone who is looking for a way to communicate with Drupal and so is using the hooks and events that exist. The second one is that of a developer who designs these APIs.

Drupal is in the middle of both, on the one side Drupal is a consumer of the Symfony API, almost every piece of code is placed in Symfony events, and on the other side Drupal provides APIs, in form of legacy hooks or custom Symfony events and other methods like plugins.

You probably didn't use one of the Drupal APIs, more likely a Symfony kernel event, KernelEvents::REQUEST. Then you are in the same position as a Drupal developer and this is not a question about hooks or events, because Symfony doesn't provide hooks.

Even if you were using one of the Drupal APIs, you wouldn't have much choice. You would have to select what is provided to you. Only if you design an API in your module to interact with other modules, then you can choose between an event or a hook.


Unable to create new user from Admin "New User" page ... Drupal 7

This is a core bug. You can read about it here. What you can do is to translate "Create new account" string or use String Overrides module.


Print list of attached taxonomy terms on search result items

You almost have it.  How I'd do it is like this.  First, in (I assume you are doing this already) hook_preprocess_search_results:

function YOURMODULE_preprocess_search_results(&$variables) {

  // the vid you are restricting your results to...
  // it is really up to you to define the logic of how
  // to determine this, but you could use a variable...
  $vid=variable_get('YOURMODULE_search_result_vid', 4);

  $taxonomy=$variables['result']['node']->taxonomy;

  if ($taxonomy) {

    $terms=array();
    foreach($taxonomy as $t) {
      if ($t->vid == $vid) {
        $terms[]=$t->name;
      }
    }

    if ($terms) {
      $variables['terms']=implode(',', $terms);
    }

  }

}

will, assuming no typos and brain fades on my part, produce a $terms variable you can access in search-result.tpl.php.

Now, for step 2, copy the default one out of .../modules/search to your theme.  The default D6 one basically looks like this, with the large intro comments removed:

  <a href="<?php print $url; ?>"><?php print $title; ?>

  <?php if ($snippet) : ?>

<?php print $snippet; ?>

  <?php endif; ?>
  <?php if ($info) : ?>

<?php print $info; ?>

  <?php endif; ?>

so in there, you can change it up basically like this:

  <a href="<?php print $url; ?>"><?php print $title; ?>

  <?php if ($snippet) : ?>

<?php print $snippet; ?>

  <?php endif; ?>
  <?php if ($info) : ?>

<?php print $info; ?>

  <?php endif; ?>
  <?php // THE NEW STUFF FOLLOWS... ?>
  <?php if ($terms): ?>

<?php print $terms; ?>

  <?php endif; ?>
  <?php // ...END OF THE NEW STUFF ?>

and with some CSS styling of your new search-terms class, be on your way.


Take a look at https://www.drupal.org/project/registry_rebuild

The documentation is there:

  How To Use Registry Rebuild With Drush

  This is the preferred technique, and it should work with multisite installs.

  You can just drush @none dl registry_rebuild-7.x and drush will download it into your .drush folder. (Alternately, you can obtain the package another way and copy the folder into .drush yourself.)

  Make a backup of your database.

  Clear Drush own cache with drush cc drush

  On a multisite install, either use correct drush alias, or cd into the site you're rebuilding, as in cd sites/mymultisite

  Run drush rr or drush @sitename rr for soft rebuild (default), or:
      To force aggressive rebuild from scratch run drush @sitename rr --fire-bazooka


AFAIK the features provided by the Demonstration site (Sandbox / Snapshot) module are the closest as per your requirements. It has the feature that allows you to take snapshots of your site, use it as sandbox and later (if you want) restore it back to any of the previous saved state.

This module allows you to take snapshots of your site. Whenever you need to reset your site to the state of a saved snapshot a click of your mouse will do so.
With cron enabled, a site can be automatically reset to a chosen snapshot in a definable interval.

Backup/archive of uploaded files and restore upon reset. To allow sandboxes for file related modules.
Journal module integration to show recent changes in snapshots.
Demo Reset security improvements to allow to demonstrate administrative functionalities more easily.

There is also a Demonstration Site Install Profile which allows restoration of the Demonstration Site module's database dumps during site installation.


Importing Webform Submission List (Text) with Feeds Tamper

I managed to find a solution on thejibe.

The Feeds Tamper setting I was looking for was "Rewrite".

In the last field, I added "Rewrite" and added tokens for each of the values separated by commas.

Following that, I added Explode.

I did a test import and had great success.

I hope this helps someone.


File Field related issue / How to hide file size information?

Copy your parent's theme file-html.twig and place in it your subtheme's /templates folder.
Remove line that has {{ file_size }}, example:
{{ file_size }}

Flush cache.


The answer is: you cannot do it in other way, because the view entity is search_api type.


How to make a specific template according number of nodes in a content type?

I don't know how to swap template files with panels I only know how to modify the layout based on condition, sorry. here's a small little snippet i quickly wrote to display a different template based on the number of nodes inside of the content type. This should really be done with a custom module but I don't have time.

Make sure templates are in template folder under your theme and named correctly.
Copy paste snippet below into your template.php file.

function YOURTHEME_preprocess_node(&$vars) {

if($vars['type'] == 'article'){
     // set content type
     $content_type = 'article';

     // Count number of articles in article
     $query = "SELECT COUNT(*) amount
               FROM {node} n ".
              "WHERE n.type = :type";
     $result = db_query($query, array(':type' => $content_type))->fetch();

     // get number of articles
     $articleCount = $result->amount;

     //specify template based on number of articles
     // one - is equal to _ and two -- is equal to __ for template file
     // No need to add `.tpl.php`
     if($articleCount == 1){
         $vars['theme_hook_suggestion'] = 'page__template1';
     }
     if($articleCount == 2){
         $vars['theme_hook_suggestion'] = 'page__template2';
     }
     if($articleCount == 3){
         $vars['theme_hook_suggestion'] = 'page__template3';
     }
     // ect.... you should make a dynamic loop here this is just basic logic.
   }
}

Modify code to your liking
Clear Cache


Is there any module for Restful API in drupal 7 with commerce

Both Drupal and Drupal Commerce support API integrations with mobile apps.

Look into the following:

Start with Services for basic web service support in Drupal.
Throw Commerce Services on top of it to expose Drupal Commerce entities.

There are a couple of good articles by Tyler Frankenstein:

Drupal Services Example
Build a Mobile App to Sell Products with Drupal
Sell products with a custom mobile app a Presentation with Scott Hooker (then Commerce Guy) at DrupalCon Austin


problem was that i didn't knew very well how menu hook worked
solution is:

foreach (commerce_product_types() as $type => $product_type) {
  $items['sell/' . strtr($type, array('_' => '-'))] = array(
    'title' => 'Sell !name',
    'title arguments' => array('!name' => $product_type['name']),
    'page callback' => 'commerce_product_ui_product_form_wrapper',
    'page arguments' => array(commerce_product_new($type)),
    'access callback' => 'commerce_product_access',
    'access arguments' => array('create', commerce_product_new($type)),
    'file' => 'includes/commerce_product_ui.products.inc',
    'file path' => $commerce_product_bp,
  );
}

didn't have to apend the path to function names, thought those where called by path for some reason..


How can I make someone else group manager of a group I've created?

Change the author of the group node. Make it someone else than yourself.


How do I create a configuration menu with the selected section name?

I tested it with your code and you just have to change two little things in your custom_menu.adminmenu_section. The rest is ok. See below:

module.links.menu.yml

custom_menu.adminmenu_section:
  title: 'Configuration' <= change this to your section name
  description: 'Custom Menus Configuration section'
  parent: system.admin_config  <= change this to system.admin_config
  route_name: custom_menu.adminmenu_section


How to add class in current page link fields?

If the links are not part of the menu tree, then this can be tricky. Essentially you'll have to evaluate the href value to the current URL.

Otherwise, if they were part of the menu, you can look to the default menu.html.twig file and see in its items loop:

// code ...
{%
  set classes = [
    item.in_active_trail ? 'active-trail'
  }
%}

As it stands in your situation, you may want to do this in a preprocess and not the twig file itself.

function mytheme_preprocess_field(&$variables) {
  // code ..
  $url = Url::fromRoute('<current>');

  // loop field values, compare $url to value
  // if match, add 'orange' to class in the attributes
}

Then you would only have to worry about rendering the link fields in the twig, as the attributes part will take care of getting the class to the output.

I suppose another way of encapsulating this logic would be writing your own field formatter for this purpose.


It is correct to change unit_price of commerce_order_item programmatically under several conditions?

As a proof of concept a module with this functionality already exists. Unfortunately, it's not published yet because that requires a couple of final touches with a time frame allocated for this kind of work.

https://github.com/drugan/commerce_oiaddon

The price adjustment is taken from a pseudo-price field added to some entity type and then the order item price recalculated at the event of an order item added to or removed from a shopping cart. So I am not sure why you can't get the same result as in the commerce_oiaddon module. Just do the same as it shown in the example and it should work.


function announcements_user($account) {
  $header = array(
    'announcement' => array(t('Announcement')),
    'operations' => array('data' => t('Operations'), 'colspan' => '2'),
  );
  $rows = array();

  $result = db_select('announcements','a')
    ->fields('a', array('pid','value'))
    ->condition('uid', $account->uid)
    ->extend('PagerDefault')
    ->limit(5)
    ->execute();

  foreach ($result as $data) {
    $row = array();
    $row[] = l(truncate_utf8($data->value, 10, FALSE, TRUE), 'announcement/' . $data->pid);
    $row[] = l(t('Edit'), 'announcement/edit/' . $data->pid);
    $row[] = l(t('Delete'), 'announcement/delete/' . $data->pid);

    $rows[] = $row;
  }

  $form['announcements'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No announcement available.'),
  );

  $form['pager'] = array('#markup' => theme('pager'));
  return $form;
}

Query methods generally return the object for which they are invoked; this means that method calls can be concatenated as I did in  the code.
PagerDefault::limit() has a default limit of 10; if you don't call that method, the limit is the default value.
Strings that appear in the user interface should always be translated; the only strings that cannot be translated (which means, you cannot pass them to t()) are dynamic strings obtained from a function/method.
Drupal URLs should always be obtained from url() or l(). l() returns the HTML tag for links (<a>), while url() returns the relative or absolute URL for the Drupal path passed as argument.

For an example of function that does something similar, see blog_page_last(), which returns the last blog posted by a user.


Want to build a widget which gives price history on Drupal 7

I've just come across a module called Track Field Changes which may be ideal for you needs.

I found the documentation a bit lacking however but to get it to work I:

Install module
Visit /admin/config/system/track_field_changes and select your product node type
Save the configuration and then product will appear as a menu item in the left menu. Click it.
Select the price field and again save the configuration.
Create a new view that shows content of the type of your products.
Add the field called "Field Tracker: Value After (Value After)"

This will then show a log of all of your price changes. To then turn this into a graph check out the Views Charts module.


How to change the alias for the core forum landing page?

Why not just use the core path module:

http://example.com/admin/config/search/path/add


Can blocks created via the admin UI be cached?

https://www.drupal.org/project/blockcache_alter might be what you are looking for.


After many back and forths, I figured out the syntax for using multiple webforms (and this can be applied to NIDs).  The syntax would be:

http://yourwebsite.dd:8083//fillpdf?fid=61&webforms[0][nid]=33&webforms[1][nid]=19

You can increment the webform number and continue to add NIDs.  I am pretty sure that this syntax works with SIDs as well, but I have no need for anything other than the most current submission at this time.

Additionally, note that as of the writing of this... this does NOT work the production version (7.x-1.10) of FillPDF but ONLY with the development version (7.x-1.x-dev).


How to test any features that require authentication?

As mentioned in my question, it was pretty clear that Behat was failing to login, so I began to look for modules that might interfere with the login process.

It turns out that we are using the module AntiBot (https://www.drupal.org/project/antibot) and when we disabled this module, we were able to run tests that involved successfully logging into Drupal.


The value of a formated text field is a structure with a value and a format property. Because the body is a formatted text, you likely need to use its value property. Tho get the formatted body value, you will need to use

$wrapper->body->value->value(array('sanitize' => TRUE))


To make a correct format you can make use of #default_value

See here

  Description: Format a date selection box. The #default_value will be
  today's date if no value is supplied. The format for the #default_value and the #return_value is an array with three elements with the keys: 'year', month', and 'day'. For example, array('year' =>
  2007, 'month' => 2, 'day' => 15)


Can Ckeditor use relative paths for images?

You should always use relative paths in your content to avoid the problem you now have.

If it was me I would fix the links in the database so they are all relative. You can do so with sql queries like this:

UPDATE field_body_data
SET body_value = REPLACE(body_value, 'http://example.com/', '/')
WHERE body_value LIKE '%http://example.com/%';

Followed by:

UPDATE field_body_data
SET body_value = REPLACE(body_value, 'http://example.com', '/')
WHERE body_value LIKE '%http://example.com%';

There are two to catch the case you might have a path to the home page without a trailing slash.

You would have to do this for any text area field that might contain a hyperlink.

The Pathologic module will also help you around this issue.
You add the pathologic input filter for your relevant formats, then configure it with your old domain name.
Also add the domain name /
This will make it change relative paths to use their alias, like /node/10 to be /node-path-alias

That last feature with the aliases is very useful.

See https://drupal.org/node/257026 for more info on configuring pathologic.


How to load image from Custom Module with javascript?

drupal_get_path() is a PHP function so you cannot call it in your JS.

To use the result of that function in your JS you would need to call the function in your PHP and then add the output to the JS on the page. You can use Drupal.settings for this. For example:

// Settings to pass to our JS.
$settings = array(
  'loaderImgPath' => drupal_get_path(
    'module',
    'alx_infinite_scroll'
  ) + '/images/ajax-loader.gif',
);
// Add to the JS settings.
drupal_add_js(array('alx_infinite_scroll' => $settings), 'setting');

Then you can use something like this in your JS:

Drupal.behaviors.alxInfiniteScroll = {
  attach: function (context, settings) {
    var imgPath = settings.alx_infinite_scroll.loaderImgPath;
  }
}

I recommend reading some of the documentation on Drupal's JavaScript APIs as it goes over this. For example:  https://www.drupal.org/docs/7/api/javascript-api/managing-javascript-in-drupal-7

To do that though you need to add the above PHP code somewhere.
In your case you are loading your JS in the info file, which means it will load on every page.
I would advise against this unless you actually need your JS to run on all pages, but if you do want it on all pages you could use something like hook_page_build().

In that case since you are dealing with the page render array you can use the #attached method of adding JS and JS settings that is referred to on the documentation page I linked above.


drupal_http_request doesn't just return the response data, it returns an object.

Return value

object An object that can have one or more of the following components:

request: A string containing the request body that was sent.
code: An integer containing the response status code, or the error code if an error occurred.
protocol: The response protocol (e.g. HTTP/1.1 or HTTP/1.0).
status_message: The status message from the response, if a response was received.
redirect_code: If redirected, an integer containing the initial response status code.
redirect_url: If redirected, a string containing the URL of the redirect target.
error: If an error occurred, the error message. Otherwise not set.
headers: An array containing the response headers as name/value pairs. HTTP header names are case-insensitive (RFC 2616, section 4.2), so for easy access the array keys are returned in lower case.
data: A string containing the response body that was received.

For example, you can check

// This is the actual response data.
drupal_set_message($result->data);
// if there's an error, it'll  be in here
drupal_set_message($result->error);

or, if using the devel module

dpm($result);

In your case, you might just need:

if (empty($result->error) {
  $errors['item_1'] = json_decode($result->data);
}else{
  // An error occurred, log, show msg etc...
}


The Updated date field is a core property (node.changed) of Drupal nodes, representing when it's database record changed. You'd probably have to do some core hacking to rework this property to change only when fields change.

As an alternative, you might want to consider a module like Track Field Changes which logs when specified fields are changed and provides Views integration.


Do I need to build out CCK fields before migrate_d2d_ui?

I eventually concluded that the answer to this question is 'yes' and ended up persisting my content structure (content types and field definitions) in features so it could be easily replicated when some errant step in the migration corrupted the database.


How to Use Exposed filter of Taxonomy term with depth in Taxonomy View

But problem in my case is that I am using views of type Taxonomy, here I don't get option in Filter "Taxonomy Term: Has content with depth".

You can bring that option into scope if you add a Relationship of "Taxonomy term: Representative node" or "Taxonomy term: Content using MY_VOCABULARY" and general any relationship that will join the node (or other Entity) table with the taxonomy table.


Taxonomy Filter with parents and child of select parent dropdown`s

the hierarchical select module is the correct solution for this purpose, why it does not work with you?

Setup steps:
1- add the module folder to sites/all/module
2- go to modules page and enable hierarchical select
3- add new field (Term reference) into your content type with (Hierarchical Select) widget type.


How to convert Mutual User Relationship to Reciprocal?

I found the issue... I had to update the Relationship IDs in the database for the originally-Mutual relationships because they shared the same RID, thus making each RID unique. The one-way/reciprocal relationships do not/cannot share the same RID.


VIews Proximity Search Fields as Separate Block?

If you are using drupal 7 You have an option to expose the filter as a block. and you can display the block in any region as you do all the other blocks. You would find this option under the advanced section in the views.

Please check the screenshot below


There is a module for that, try Email Registration, from module description:

  Allow users to register and login using only an email address. Users can then log-in using their email address and password for authentication.

  A username is generated and assigned based on the user name part of
  the email address and their user ID

is avilable in D7, D8


Add taxonomy field to a bundle programmatically

First create your field

$field_name = 'field_manufacture';

$field = field_info_field($field_name);
if(!$field){
  $field = array(
    'settings' => array(
      'allowed_values' => array(
        0 => array(
          'vocabulary' => 'manufacture',
          'parent' => '0',
        ),
      ),
    ),
    'field_name' => $field_name,
    'type' => 'taxonomy_term_reference',
    'module' => 'taxonomy',
    'active' => '1',
    'cardinality' => '1',
  );
  field_create_field($field);
}

Then create your instance(s)

$node_types = array('page','whatever');
foreach($node_types as $type){

  $instance = field_info_instance('node',$field_name,$type);
  if(!$instance){
    $instance = array(
      'label' => 'Manufacture',
      'widget' =>
      array(
        'weight' => 3,
        'type' => 'options_select',
        'module' => 'options',
        'active' => 1,
      ),
      'field_name' => $field_name,
      'entity_type' => 'node',
      'bundle' => $type,
    );

    field_create_instance($instance);
  }

}

if you do var_export the return from field_info_field and field_info_instance of an existing field, you can see how the field arrays are structured & use this structure when creating new ones.


How to add jQuery code only to the node add/edit page?

First, you need to convert your script to be a behavior. Drupal will call defined behaviors, so document ready is not necessary.

Second, you can add this script to specific form pages with drupal_add_js and hook_form_alter.

Use hook_form_alter to hook into node add and node edit forms. You can do a check on the $form_id argument to ensure it is a node form.
Use drupal_add_js to add your script file.

Example:

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if (preg_match('/node_form/i', $form_id) {
    drupal_add_js(drupal_get_path('module', 'my_module') . '/script.js');
  }
}

This file will only load when these forms are built, so, you can also remove the line that is checking the window href in the javascript.

The code above is untested, but a general start in the right direction. This code can be placed in a custom module, or, if your admin uses the same theme, you can place it in the template.php of the theme. I strongly recommend a simple custom module.

Edit

I believe the form id is preprended by the content type in 6. So, to isolate it to one content type:

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'content_type_node_form') {
    drupal_add_js(drupal_get_path('module', 'my_module') . '/script.js');
  }
}

Or you can use hook_form_FORM_ID_alter to target specific forms too:

function mymodule_form_content_type_form_alter(&$form, $form_state, $form_id) {
  drupal_add_js(drupal_get_path('module', 'my_module') . '/script.js');
}

Where content_type is the name of any given content type (article, page, etc).

Example behavior (mymodule/script.js):

(function ($) {
  // you can define multiple behaviors

  Drupal.behaviors.mymodule_behaviorname_one = function(context) {
    // this code should fire automatically when the page has loaded
    console.log('Hello!');
    alert('Hello!');

    // attaching to an element
    $("a", context).click(function(e) {
      e.preventDefault();
      alert('You clicked a link.');
    }
  }

  Drupal.behaviors.mymodule_behaviorname_two = function(context) {
    // this code should fire automatically when the page has loaded
    console.log('Behavior 2');
  }
}(jQuery));

More on JS in Drupal (there are some examples in here for 6.x): https://www.drupal.org/docs/7/theming/working-with-javascript-and-jquery


Add a content type as a select list when creating a new user

If you use/add the Content Profile module, you can use it to create a profile for each user. In that profile content, you can have a field that is a node reference back to the Location type you mention.

  This module builds user profiles as content (aka nodes), which opens the opportunity to use all the powerful modules for content for user profiles too, e.g. the Content Construction Kit (CCK). It's intended to be simple and useful, but extensible by further modules.

  Content profiles can be restricted to certain roles; the module also supports separate content profiles for different roles.


check
http:localhost/formexample

Back-end admin panel menu :

$items['admin/structure/formexample'] = array(
    'title' => 'View the sample form',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('formexample_nameform'),
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM
  );

used this code


CSS aggregates generating but not loading (core and AdvAgg), but JS aggregates load fine

It turns out that there is a "Development Extension" that is a part of the Omega theme settings. I had it enabled for a couple of the features it provides, but unchecking it caused the aggregates to start loading like normal. Guess having that enabled is what broke the aggregation. Hopefully this ends up helping somebody else eventually.


How to delete content of sheetnode spreadsheet field?

Solution I found was to not save the data in the first place. Will make debugging harder, but here it is:

function hottopicsresearchsheet_node_presave($node) {
  // Check that the nodes of the type I need and process data...

  // Clear data.
  if (!empty($node->field_spreadsheet[$node->language][0]['value'])) {
    unset($node->field_spreadsheet[$node->language]);
  }
}


'Search Form' block I would like to add a link called "Advanced Search" below the existing Search box

You could either use the hook_block_view_alter to add the link, just like you say. Or you can implement the search-block-form.tpl.php in your theme and add the link in the template file.


Feature creation of Print module for path to print stylesheet

You also need strongarm enabled to export the path variable. Then it will be available as print_css variable.


Apache Solr Search Integtation and the Default Drupal Search Form

I'm assuming Drupal 7.

This is a limitation of the way core Search is implemented in D7. Try the Custom Search module; it can somehow change the way search paths are handled, although I have not used it.
One tab would be for core search, and the other for Apache Solr search. Go to /admin/config/search/settings and disable all search modules except Apache Solr, and also set it as default. Now the only available search path will be the one set up at /admin/config/search/apachesolr/search-pages.
I cannot replicate this on my Apache Solr & Drupal 7 setup. In general, to change strings that are hard coded into modules, use the String Overrides module.


Classify content in Views based on distinct values

I haven't done this myself, but off the top of my head...

On the node type, I would add a CCK Colour Field to allow the person adding the node to determine a colour for that node. (Then in the content type setting, manage display and hide the colour field).

Then in views, you can add the colour field, and exclude from display.

Then in the same view, add the node reference field you wish to change the colour for (for example node title colour or background colour). (Make sure the colour field is first in the list of view fields)

Then in the view admin, click on advanced, and click "Theme Information". Find the field you wish to override (something like views-view-field--title.tpl.php).

Then copy the field.tpl.php file from the theme folder in the views module folder, and place it in your themes template folder, renaming the file views-view-field--title.tpl.php

You can then place your own php in that template file, around the default $output variable, something like...

$color = $row->{$field->color_field};

<div style="color:<?php print $color ?>;">
<?php print $output ?>
</div>

I think that's what you mean? Please let me know if I have misread the question.


Creating a Testimonials Content Type and making it work as it should

You can give anonymous users the permission to create content of that type. And you can set the default publishing setting to unpublished (They can't change that unless they have the required permission).

For the theming part, if you are using the admin theme for the node add/edit forms, then you'll have to disable it for that content type. You can do so with a bit of custom code and implement hook_admin_paths() and return 'node/add/content-type' => FALSE path. This will override the definition in node_admin_paths(). Because for a path to be considered as an admin path, there needs to be an entry that returns TRUE and no entry that returns FALSE.


Linking two different content types with Views

Suppose we have 2 content types A and B and want to display the content of content type B which have a field reference ie both A and B both have a common field.
then:

We simply add B to the Filter Criteria of the view.
Add an nid of A using Contextual Filter in the advance Options.
Add a relationship of B in reverse order in the relationship field in advance options.


How to show year/months in archive block?

Use the Views module, then add the creation date of the blog to your views fields; it will be displayed.

Create a new view that shows only nodes whose content type is blog
Select the format you want
In the fields section, add the title and other fields you want to display
Add the date field
Save it; you should get what you wanted


How to count entity references from same field in different entity types?

Firstly, create a users view of the format: table with aggregation options with the following fields:
- Company ref.
- Team ref.
- User name.
Then go into the table's settings and add a group and compress function to the first field, and count to the others. Optionally you can use the tally members function and you'll get team names with counts displayed between parenthesis.

Secondly,.. well this is simple but depends on how much you are comfortable with php.

Create a views_preprocess_view (either that or _views_pre_render) function in your theme or in a custom
module.
Install and enable devel and use dsm() in your function to print the resulting array of your view.
Use entity field query to get a list of your companies.
Compare your views results array with the entity field query results to figure out what is missing from the list.
Add it to the view with 0 or dashes for counts.


Shopping cart views are not show product links

Try to edit the shopping cart views, go to
admin/structure/views/view/commerce_cart_form/edit/default

On the Fields Setting Make sure there is Display path field, exclude from display. see the Global: Custom text, and you must inlcude the Dsiplay path field token there


I wrote a function to get rid of unwanted elements

function removeUnwanted($j)
{
    unset($j['link']['load_functions']);
    unset($j['link']['tab_parent']);
    unset($j['link']['router_path']);
    unset($j['link']['page_callback']);
    unset($j['link']['page_arguments']);
    unset($j['link']['title_callback']);
    unset($j['link']['title_arguments']);
    unset($j['link']['theme_callback']);
    unset($j['link']['theme_arguments']);
    unset($j['link']['access_callback']);
    unset($j['link']['access_arguments']);
    unset($j['link']['tab_root']);
    unset($j['link']['to_arg_functions']);
    unset($j['link']['in_active_trail']);
    unset($j['link']['delivery_callback']);
    unset($j['link']['description']);
    unset($j['link']['localized_options']);
    $j['link']['href'] = drupal_get_path_alias($j['link']['href']);

    foreach ($j['below'] as $key => $r) {

       $j['below'][$key]= removeUnwanted($r);

    }
    return $j;
}


I install ultimate cron and I saw that errors

The issue isn't Ultimate cron, per se. It's your custom bla module; it's running some function called bla_clean() that's building a Delete SQL query with broken syntax. When executed, it's producing the error.

You're using the NOT IN operator incorrectly. Here's a post that demonstrates a NOT IN within a query.


Is it possible to have nested divs in content fields on a view?

Just exclude from display all your fields.

Then, at the end, create a Global text area, where you can use tokens from your excluded fields.


How to prevent accidental clicks in the Save button when saving a node?

Finaly I got this  using these 2 modules:

http://drupal.org/project/hide_submit (to prevent clicking the bottom using jquery)

and

http://drupal.org/project/node_limit (just for browsers with javascript disabled) This allowed me to set a time interval limit to post new nodes.


Is it possible to load different versions of the same module?

I'm afraid this simply isn't possible without hacking at Drupal core and the Views module(s) in ways I can't even imagine.

As you know Drupal will only ever let you have one version of a module installed at any one time, and there's no mechanism to 'swap' a module based on a condition (such as the current URL).

Conceptually this would be almost impossible for quite a lot of reasons; the most obvious that jumps to mind is the fact that one version would have to be uninstalled before the other could be enabled, thus destroying all of the data that exists for the first version. By the time you 'swap' back to the other version, you've lost all of your original Views data.


Have you got correct permissions for anonymous users to access the resource ?

testing.dev/drupal8/admin/people/permissions
under the RESTFul Web Services ensure that Access GET on Content resource is ticked for Anonymous User. Clear cache and try your request again.

Also you might not have the format type exposed for that resource in your rest.settings.yml file. This file sets the supported_formats and auth. Here is what is should look like in your case:

resources:
  'entity:node':
    GET:
      supported_formats:
        - hal_json
        - json
      supported_auth:
        - cookie


How to print out usernames using EntityFieldQuery

Since user_load_multiple() returns an array of user objects you need to use the '->' in order to access them.

$output = '';
foreach ($users as $key => $value) {
  $output .= "index: $key; name: $value->name<br />";
}
return $output;


Getting JQuery Masonry to work with Drupal 7 Views

There's actually a Masonry module now

  Makes the jQuery Masonry plugin available to Drupal as a library.


PHP is a shared nothing architecture. That has its advantages and disadvantages.

One disadvantage is that it's not easy to do something like this. There isn't much of a state that can be stored somewhere.

I did some quick tests and when logged in, then the boostrap seems to take about ~17% of the total time and more than 50% of that is actually loading all the .module and .inc files. That's not something that you can store in memcache. Also, it doesn't seem to matter much if I use memcache or the database cache.

I tried to get some results when having the page cache enabled, but Xhprof doesn't seem to return reliable results then; the whole thing simply seems to be too fast. But even then, the biggest part involves executing init/exit hooks and loading files it seems. I found an interesting issue there: It looks like the User module is seriously slowing down the cached page response because it triggers the registry due to the entity controller in the .module file.

That said, David Strauss showed some experimental work in Copenhagen where he created a memory snapshot after bootstrapping and then returning to that once the page was served. He did use Drupal 6 for that. After looking at the numbers above, I imagine that the performance gains of doing this in Drupal 7 would be quite a bit smaller. One reason for this is that the database connection is lazy loaded (And you can get quite far in the bootstrap when using e.g. Memcache before you need to execute the first query) and there's a lot that is cached.

What's really bad in Drupal 7 is the render layer with these huge arrays and endless recursions and loops. That one pretty much undoes all the performance work that went into Drupal 7. Let's see how it looks in Drupal 8, if Twig makes it into core.

Lastly, about the mentioned advantages. One large advantage is that memory leeks are rather irrelevant because everything is freed after each request. I've seen many Java applications where memory usage constantly increases and need regular restarts.


google alerts RSS feed on homepage feed module

You should only need Features and Views if you enable the Feeds News module. I think you can import from an RSS feed without that (by changing the Fetcher and Parser settings). However, IIRC, the Feeds News module does automatically create a View interface for you that manages all the feed items from a specific source so it can be handy.

Your setup sounds similar to one I implemented in D6, and it works well for the client. Once the items are imported, use Views to customize the output: a Views block can be configured to show the desired number of posts, titles as links, etc.

You may also want to implement VBO to manage the publishing of the feed items from your administrative page.


How do I implement hook_finder_goto_alter()?

Hooks 101

hooks should be created in a module. The module which they are called from should be enabled.

So in the first instance you will need to create a .info and a .module file with the correct information in.

Then to implement a hook you must use the module name.

So the example code above would work if the php code is in a module called test which was enabled.

So hook_menu() in a module called test.module would be a function called test_menu()

Secondly hooks will only be called when invoked, some get invoked rarely when for example building the menu system, and others are invoked when specific actions happen. You will need to read up on the documentation for the hook in question to find out more.

The same goes for parameters and return values, each hook is different. So the documentation is important there.

So a general checklist for hooks.

Is the hook in a module?
Is the module enabled?
Is the hook named the same as the
module?
Is the action which is calling the
hook being called?
Have I cleared the cache?
Am I using the hook in the correct way?


Why does Drupal url alias field allow apostrophes and passes validation?

Use hook_form_FORM_ID_alter() to add your own validation function to node edit forms. In this validation function you'd check for characters that you want to allow/deny, and throw a form_set_error() on that field if there's a problem.


How to access fields for the Registrant settings (RNG)

But how can I access these fields?

As I'm sure you are aware, you can add the fields here at

Administration > Configuration > RNG > Registrant settings > Manage fields (/admin/config/rng/registrant/fields)

  I can see my registrants on the Registration List, but I can't see the additional fields.

The registration list page is simply a page provided by Views. There are a few ways to edit the view, including the quick edit button which appears on the right side of the page. On the view, there is already a pre-made relationship from event entity -> registrant entities -> identity entity. The fields added to any of the entity types, including the registrant entity type, should be automatically available by using the standard Views add field button.

  I also have no idea how to add the content to these fields?

Before of 1.2, there was no edit registrant entity form (or view registrant entity). Adding field values programmatically to registrant entities is also fully supported using the standard Drupal entity API.

I have created an issue for RNG which can be used to discuss this kind of feature: Add a way to view and edit registrants entities


Upload Image in system_theme_settings form using Zen on Domain Access System

The form needs to be able to find system_theme_settings() when getting rebuilt via ajax.

form_load_include($form_state, 'inc', 'system', 'system.admin'); inside of theme-settings.php hook_form_system_theme_settings_alter() should do the trick.


User generated review site where users are matched when they review products similarly

This should be achievable using some combination of Flag, Fivestar, and Views. You can use Views to find users that match criteria based on the current user. You shouldn't need any PHP, in theory at least.


Trying to create a link in a custom module

#markup is used for content that has already been rendered. As the caller seems to be expecting a render array, you can just return it directly:

return $endpoint->toRenderable();


I think because of overriding 'base' property, change it to 'node_content'

  using the "base" return component of hook_node_info() as the function
  prefix. For example, poll.module defines the base for the Poll content
  type as "poll", so during creation of a poll node, hook_insert() is
  only invoked by calling poll_insert().


Prevent indexing the article content after 15 lines.

Anything is possible :)

You can write a custom module to alter the behaviour of search api.
In the search api module directory there is a file search_api.api.php, which gives information on the functions you can use to alter its behaviour.

For this you would make a custom data alteration like this - replace modulename and ModuleName with the name of your module (case sensitive).

This part goes in your .module file:

/**
 * Define available data alterations.
 *
 * Registers one or more callbacks that can be called at index time to add
 * additional data to the indexed items (e.g. comments or attachments to nodes),
 * alter the data in other forms or remove items from the array.
 *
 * Data-alter callbacks (which are called "Data alterations" in the UI) are
 * classes implementing the SearchApiAlterCallbackInterface interface.
 *
 * @see SearchApiAlterCallbackInterface
 *
 * @return array
 *   An associative array keyed by the callback IDs and containing arrays with
 *   the following keys:
 *   - name: The name to display for this callback.
 *   - description: A short description of what the callback does.
 *   - class: The callback class.
 *   - weight: (optional) Defines the order in which callbacks are displayed
 *     (and, therefore, invoked) by default. Defaults to 0.
 */
function modulename_search_api_alter_callback_info() {
  $callbacks['modulename_character_limit'] = array(
    'name' => t('Character limit'),
    'description' => t('Limit the number of characters that get indexed for a field.'),
    'class' => 'ModuleNameCharacterLimit',
    'weight' => 100, // Probably better for this one to run later than others so they get to run on the full content before you trim it. Can still be reordered via the UI though.
  );

  return $callbacks;
}

This goes in a file named modulename_processor_character_limit.inc that goes in a sub-directory of your module called 'includes':

<?php

/**
 * @file
 * Contains ModuleNameCharacterLimit.
 */

/**
 * Processor for limiting the number of characters of a field that are indexed.
 */
class ModuleNameCharacterLimit extends SearchApiAbstractProcessor {

  public function configurationForm() {
    $form = parent::configurationForm();
    $form += array(
      'char_limit' => array(
        '#type' => 'textfield',
        '#title' => t('Character limit'),
        '#description' => t('The maximum number of characters of the field that will be added to the index.'),
        '#default_value' => $this->options['char_limit'],
        '#required' => TRUE,
        '#element_validate' => array('element_validate_integer_positive'),
      ),
    );

    return $form;
  }

  protected function processFieldValue(&$value) {
    // Chop unwanted characters from the value.
    $value = substr($value, 0, $this->options['char_limit']);
  }

}

This goes in your module's info file:

files[] = includes/modulename_processor_character_limit.inc

This will add a data alteration you can configure via the search api UI where you do things like configure the HTML filter.
You can set the number of characters to limit indexing to for our fields. - In your case, set to 15 and away you go.

(Full disclosure - I haven't tested this :))

[Edit]

As per your comment below, if you want to remove all text after a specific string (in this case "The below lines are confidential" you can do away with the char_limit setting and have a setting where you configure the text to check for (I'm calling it search_text) then change the processFieldValue() function to be:

protected function processFieldValue(&$value) {
  // If the text is found anywhere in the value.
  if (($pos = strpos($value, $this->options['search_text'])) !== FALSE) {
    // Cut off everything after that.
    // The $pos is the start of the string so if you want to also
    // exclude the string itself use $pos, otherwise to include the
    // string use $pos + strlen($this->options['search_text'])
    $value = substr($value, 0, $pos);
  }
}

Note that strpos() will return the position of the first occurance if the string occurs multiple times, which I would think is what you would want in this case.

See PHP string functions for more info on these and other string manipulation functions.


I am new to coding so anyone should feel free to correct are add to this.

Your theme is placing the content on a page using a file called page.tpl.php. It may be found in your subtheme folder or in the parent them folder. This file is responsible for assembling the HTML code that actually displays your page.  The file is a text file and is easy to open and edit (not as easy to understand if you are not familiar with HTML and PHP.  I am using Fusion themes, so there may be some difference, but if you search for 'menu' you will find the part of the template that generates the menu.  There you will probably find a HTML command to 'clear' or a Class definition that will include the clear command.  This command is telling the browser to push further content in the region, such as your block, to the next row.  To change this you will need to make an override page.tpl.php file (copy the parent theme file into your subtheme directory and remove the command. If the command is in the CSS file, you will have to alter the CSS file containing the class definition.

I do not recommend doing this if you are not yet familiar with coding in Drupal (do a bit of research first).  Good luck.


Alter field instance settings form on admin/structure/types/manage//fields/node../storage

Here is an example -

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mymod_form_field_storage_config_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

  $form['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable'),
      '#description' => t('If enabled then this module will alter the field settings.'),
      '#default_value' => $form['enabled'],
  );

  $form['#entity_builders'][] = '_my_additional_form_field_storage_submit';
}

/**
 * Entity builder.
 */
function _my_additional_form_field_storage_submit($entity_type, Drupal\field\Entity\FieldStorageConfig $fieldStorageConfig, &$form, \Drupal\Core\Form\FormStateInterface $form_state) {

  if ($form_state->getValue('enabled')) {
    $fieldStorageConfig->setThirdPartySetting('my_additional_settings', 'enabled', $form_state->getValue('enabled'));
  }
  return true;
}


How to show the values on the bars of a stacked bar graph in 3D?

Option 1 - Try another chart type

I recommend you experiment a bit with some of Forena's other Supported chart types, as documented within the "FrxSvgGraph" section of the "Custom Renderers"chapter (located with /reports/help.renderers#frxsvggraph of your site, and similar to this online equivalent).

More specifically, you seem to be using frx:type="StackedBar3DGraph". I think you will get way better results (to show the corresponding values) if you try with some of the other chart types, especially these ones:

MultiLineGraph
GroupedBarGraph
GroupedCylinderGraph

Option 2 - Add specific SVG Graph settings

If using another chart type is not what you want (= it has to be a Stacked Bar Graph in 3D), then you need to find the appropriate SVG Graph setting(s) (there are dozens, if not hundreds, of them ...) and pass such setting(s) as extra FRX attributes.

In that case, you may want to use some of the SVG Graph general settings. I haven't experimented with them, but I think you may want to try with these settings:

show_data_labels, which is a boolean (default = false), to "display labels for bars, markers or pie slices". In Forena, if you want to set this option to true, you'd specify it in your frx file like frx:show_data_labels="yes".
any of the settings starting with data_labels_... (there are dozens of them ...), to tune the data labels, like their fonts, positioning, etc.

Note: SVGGraph data labels explains some of the options related to labels, and how to use them.


How to hide blocks based on content type or for specific nodes?

The answer very much depends on how the nodes you want to show only bodies of are different from all other nodes of same content type.

I see two possible solutions:

Create a new content type and convert all the nodes you want to it. Then you can specify in blocks visibility settings not to show blocks on the nodes of that content type and create a new template for this content type in which only body is printed.
Another way is to give the context module a try. The context module provides a much more flexible way to control blocks visibility so you can specify different contexts for your normal nodes (and assign blocks to this context) and your no-blocks nodes with no blocks assigned.

I'm sure there must be other ways to accomplish this, but these two are the first things I thought of :)


Best place to include javascript in a field formatter?

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

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

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

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

  return $element;
}


Drupal 7 multisite domain without www. not working

Rename the folder to example.com, create a 'sites.php' file in /sites, then add the following:

<?php
$sites = array (
  'www.example.com' => 'example.com',
);


Do not import configurations if already exists

Move them to config/optional instead.

In that case, they will only be installed if they don't exist yet and if all their dependencies are met.


Is it possible to use drush migrate-import to import custom fields?

I am currently working on a similar migration and had a similar problem. In my case the custom fields were part of the Profile2 module in D7. I installed the D8 Profile module and added a patch that fixes the Profile2 import

https://www.drupal.org/files/issues/2018-05-16/profile-migrate-from-profile2-D8-2957256-4.patch

After that, the custom fields were automatically created, populated and linked to the correct user.

Not sure if that is what you need.


Gaining access to hooks in contrib modules: Webform Validate

Webform Validation can help you in this regard. And there is a way to define custom validation rules too through hook.


If you select the content link on the 'show' line in the format section of the block definition (first column), you can switch the format to fields and then the available fields can be added.  You may want to view the video learning series at nodeone.se called "Taming the Beast' for more on how to use Views.


Implement a custom PHP library into a custom block module?

drupal_add_library() is for Javascript/CSS libraries; Drupal doesn't have a similar registry for PHP libraries/classes.

To include a file inside a module in your installation, use module_load_include() e.g.

module_load_include('inc', 'mymodule', 'mymodule.pages');

For all others just defer to the standard PHP functions (include/require, etc.)


Extract Admin OG members from basic page with views

I found the solution by doing the following

In Relationships

OG membership: OG membership from Node
(OG membership from node) OG membership: Group Node from OG membership
(Group node from OG membership) OG membership: OG membership from Node group
(OG membership from node group) OG membership: User from OG membership
(OG membership from node group) OG membership: OG Roles from membership

In filters

(OG Roles from OG membership) OG user roles: Role Name (= administer member)

The idea was to select the roles from the OG membership of the Group.


How to show two dropdown select lists using a single ajax call in form api .?

I'm not sure exactly. But if you just want to show some FAPI elements based on the condition that radio is X or Y .... I would just use #states in the D7 FAPI api.


Distribute configuration to several sites

So .. found more details on it.

With
drush config-list | grep news  I can get all configurations that are named with news. Those can be exported into a Module / YAML file and moved to another installation, or rather copied and enabled.

More information on that: http://nuvole.org/blog/2014/jul/15/packaging-and-reusing-configuration-drupal-8

So that would make Features in D8 quite unnecessary - depending on the use case, very good.

It might be reasonable to use config-merge but I'm not sure about:
If I'd do a Full Export, I'd only be able to use this on Cloned sites (like Staging/Live). But in my case I'd do an initial clone or a profile and would only like to pass on functionality (like features) and that might not work with config-merge?


how to get email of welcome messge with drupal 7?

Follow below steps to solve problem !

Check your server smtp log or mail log
Check your spam folders in mail box.
Make sure smtp or mail server are up & running in your hosting server or local server.
Check drupal recent log entries for any errors related to same !


Ok, I have solved the issue and this might help someone in future. I was dealing with a form which was actually a collection of various small forms. Each small form had various text fields and submit handler. So, when reloading a small form using AJAX I was setting $form_state['rebuild'] = true, this in process rebuilt the whole form in the back. But AJAX callback only rendered a small part of form into the wrapper. So, when I pressed the button again there was post error as Drupal was expecting values in new rendered form whereas it got a mixture of Old and new form.
    It happens because Drupal while rendering a form into HTML adds id to it, e.g., id = edit-save but when we rebuild it without reloading the page, it changes to something like id = edit-save--2 and which keeps on to increment every time it's rebuilt.
    So, if your form needs rebuilding, reload the whole form else set $form_state['rebuild'] = false and that should allow subsequent AJAX calls without any post error.


Does entity_save() trigger the update event?

Assuming you're asking whether or not entity_save() invokes hook_entity_update(): no, it doesn't.

The controller class (or save callback function) for an entity type may well invoke it (for example node_save() does), but you can't rely on it for an entity type without checking the code first.


How to get all rows from a database table?

DatabaseStatementBase::fetchAssoc fetches the next row and returns it as an associative array.

$query = db_select('voting_nomination_counter', 'v');
$query->fields('v',array('uid'));
$result = $query->execute();
while($record = $result->fetchAssoc()) {
  print_r($record);
}


Is there a module that makes Taxonomy tags like they are on stackexchange sites?

Active tags will give you the look & feel of stackexchange's tags but won't provide the nice description and suggestion list that SE sites have.


I've used Feeds and Menu Export/Import to migrate Joomla sites to Drupal a few times. It's a little tedious but it works.

I think the next time I have to migrate  Joomla site to Drupal I will use the Joomla to Drupal module. It doesn't appear to be regularly updated but looks like it should work for Joomla 1.5 and less. I don't think it will be useful for Joomla 2.x and up though.


How to find out if a default image is used in content?

i added a filter criteria on photo:fid(photo is field name for image) not equal to the name of default image and it worked. i hope this will help you


How to get list of sites with module enabled using drush?

The drush command for this is:

drush @sites pml --type=theme --status=enabled --yes | grep bootstrap

That's for the bootstrap theme, for a module it would be something like this

drush @sites pml --status=enabled --yes | grep pathauto


Render comment parts individually with Panels/Page manager?

There's no out of the box solution for doing this today.

If you look at a file like ctools/plugins/content_types/node_context/node_links.inc you'll see how it's done for nodes and their links. The other files in the same directory do the same but to different pieces of nodes. For historic reasons, there's a lot of Node specific content in there.

Today it should be possible to generalize the same approach onto all entities, but as far as I know, that hasn't happened anywhere.


Prevent embedded video appearing above image overlay


How to override field collection field title?

Maybe just a typo. It should be ['value']['#title'] = .... Also you'ld rather use LANGUAGE_NONE instead of 'und'.

$form['field_ingredientsf'][LANGUAGE_NONE][$k]['field_steps'][LANGUAGE_NONE][0]['value']['#title'] .= $x;


The data_parser_plugin: json always expects an array with numeric keys as item_selector, there is no way you can get around this requirement in YAML. If you want to use a single object as item_selector, you have to create your own data_parser_plugin.
I've already had that problem in a previous object and creates my custom plugin and used my custom data_parser_plugin: single_json_object in YAML instead.
file MY_MODULE/src/Plugin/migrate_plus/data_parser/SingleJsonObject.php
<?php

namespace Drupal\MY_MODULE\Plugin\migrate_plus\data_parser;

use Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Json;

/**
 * Obtain JSON data for migration.
 *
 * @DataParser(
 *   id = "single_json_object",
 *   title = @Translation("Single JSON object as root")
 * )
 */
class SingleJsonObject extends Json {

  protected function has_string_keys(array $array) {
    return count(array_filter(array_keys($array), 'is_string')) > 0;
  }

  protected function getSourceData($url) {
    $source_data = parent::getSourceData($url);

    if ($this->has_string_keys($source_data)) {
      $sequential_array = [];
      $sequential_array[] = $source_data;
      $source_data = $sequential_array;
    }

    return $source_data;
  }
}


120 blocks in one regions seems to be excessive, you may want to attempt to consolidate them into a custom block and use context to set those.  Also may want to look at creating multiple regions that reside in the same area


Drupal clean URLs not working from subdirectory

Problem in drupal Clean URL, To Enable drupal clean url in subdirectory un comment the following line in .htaccess file.

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  RewriteBase /

for more refer the blog Enable drupal clean url in subdirectory or subdomain


Programmatically update field collection data in custom entity

Please use below code for update existing field collection data

//$item_id load item id from your node
//enter_update_field_mechine_name replace with your field name
  $field_collection_value = field_collection_item_load($item_id);
  $field_collection_value->enter_update_field_mechine_name['und'][0]['value'] = 'update text here';
  $field_collection_value->save();

This code worked for me
Thank you


Use the Drupal for Facebook module. It's not the easiest thing to setup in the world, you'll have to read the docs carefully. One of the features is publishing site content to a Facebook Wall.


How to block users to accessing Drupal website if javascript is not enabled?

It is not possible, not in the way you think of. Workflow is:

Server gets HTTP request.
Drupal process that request and returns HTML.
Browser runs JavaScript, or does not.

As you can see, server never knows if JS is there. If JS is on, you can send AJAX request, but if it's not, you can't do anything at this point.

You have three options:

Graceful degradation - this is what I would recommend. Use modules and write code that will simply not fail if JS is not there. It may look differently, that's OK, but should look good and work all right. I recommend these articles: Fault tolerance, Unobtrusive JavaScript
Use HTML <noscript> tag. It will not hide the rest of your site, but it will tell your users what is happening. This method can be used together with 1st one. Related Q&A: How to Add noscript in head tag (Thanks Wtower for link)
Output a page with "Please enable JS in your browser!" message and immediately load real content with AJAX. That's the only way I can think of to make your site work like you want it to, but it is so wrong, on so many levels... Remember, some bots may be unable to index your page if you don't have JS enabled, your users with JS on would see message while waiting for real content anyway, and so on. And while Google can read JS-generated content now, Bing and other search engines apparently still cannot.


this could be done, but I think it's too broad for the Q&A approach of Drupal Answers. In general, if I was to try this, I would start with this:

add an integer field to the user (to track number of content types)
using Field Permissions, hide that field from anyone but admin

  The Field Permissions module allows site administrators to set
  field-level permissions to edit, view and create fields on any entity.

create a role with the appropriate permissions to add content types
if permission allows viewing the content type list, use Rules to check that url against role to ensure new 'content type moderators' cannot access the list and redirect with a message

  The Rules module allows site administrators to define conditionally
  executed actions based on occurring events (known as reactive or ECA
  rules). It's a replacement with more features for the trigger module
  in core and the successor of the Drupal 5 workflow-ng module.

override the hook_form_alter() to check the integer value of the hidden field on content type creation, redirect or show message if user is at limit
override the form submit() function to increment the integer value of the hidden field on content type creation, and create perhaps a custom block, menu entry or other element to allow the user access to edit the content type later on


Change the code in the module from the front end of drupal

I'm not sure there is a module for this, but this thread begins to touch on how to create your own module admin page.
How to add module to admin/config page?


It is safe to store custom information in the data field of a commerce_order or commerce_line_item entity?

Yes, you can do that.

That information is commonly used to store context or other information. For instance, you can use the $order->data to store transaction IDs or other relevant information that you might want to use later on in the lifecycle of the order. In some cases, $line_item->data might store remote keys or other information related to that line item specifically.

Just be very careful that you don't store something in there that you wouldn't want to otherwise store in your database: credit card numbers or other things that you wouldn't want if your security were ever compromised or a database backup fell into the wrong hands.


Why doesn't Drupal use my block.tpl.php?

Most likely you just need to clear Drupal's caches.

Template file implementations are cached in the theme registry so you need to clear it for new files/theme functions to get picked up.

You can do so either at http://mysite.com/admin/config/development/performance or by using Drush.


The Drupal way of handling and translating Dates is through Configuration > Regional and language > Date and time formats, as Hudri mentioned in his comment.

The same date and time Pattern between languages

What you should do depends on what pattern you want your date to be in English, if it should also be 'd F Y' as in Dutch. If yes, then you should edit the relevant Date format through the interface. Content types use Medium as default for the “Submitted by” so edit that to keep things simple.

I expect you'll have the date and time related terms already translated into Dutch, so you'll get oktober and not October on the Dutch side.

Different date and time Pattern between languages

If you want the Pattern of the same Date format to be different between laguages, for example you want English to be “10/16/2017” with Dutch “16 oktober 2017” you need to translate the Date format Pattern.

What is important to mention is that you need to have the Configuration Translation module enabled to be able to translate Date format Patterns. This will add the Translate link to the Operations button drop-down:

This enables you to have a different Pattern for different Languages under the same Date format.

Don't forget to Flush cache if you don't see the changes on existing content!

Code manipulation

The format_date() is Depricated, more info: Date formats API changes, public function DateFormatter::format.


How do I alter the options in the add menu link checkbox in the node edit form?

$form['menu']['link']['menu_parent'] is the form array select box for the menu selector widget. $form['menu']['link']['menu_parent']['#options'] contains the key/value pairs for the menu select box.

In your given example, you can use unset($form['menu']['link']['menu_parent']['#options']['my_uneeded_menu_id_option']); to remove your  unneeded menu items.


Output node reference field data in page.html.twig

Module names are all lowercase or underscore. Your preprocess function name must start exactly with the same name as your module/theme. Never uppercase.

function mymodule_preprocess_page(&$variables) {
  ...
}

And there is no $hook parameter in this case, the _page function name suffix already declares this function as a specific hook only for the page hook type.


There may be a problem with the PHP version.

See HERE

  This function has been DEPRECATED as of PHP 5.3.0. Relying on this
  feature is highly discouraged.


How can I add a direct link to the edit account settings page in a menu?

Try this module menu_token , it allows to use tokens in menu

  Menu Token module provides tokens, that could be used in title or in path of menu items (links). For example, if you create a menu item with path: "user/[current-user:uid]", the url will be changed "on fly" to: "user/1" (assuming you are user 1).


How to add options to a select list of a content type?

It sounds like using a taxonomy would be more appropriate here. Taxonomies allow lists and terms can be automatically created from user input, in this example something like the Select (or other) module would be of use. Details from project page:

  Provides a new Forms API element which is a select/radios/checkboxes element that has an 'other' option. When 'other' is selected a textfield appears for the user to provide a custom value.


How to filter view with date field by today's date?

Based on the comments, it seems like you already have an answer, so I'm posting it as such.

A regular date filter already has support for doing a check for field_birthday == now. You can granularity, such as hour, day, week, and even do simple arithmatic, "now + 1 day" and similar.


Good god Batman. That was incredibly frustrating. Here's a guide to getting xhprof working. (Note: I am very new to Linux. I'm not sure if the permissions I use are safe, or whether there is a better way of doing it. I'd only do this on a test environment.)

IMPORTANT: It won't tell you anything about how to interpret it. I have no idea how to, I'm just happy it works.

Getting XHProf Working

1. What operating system are you running?

Mac or Linux?

It's possible.

Windows?

Probably not. To run xhprof on windows you have to have a compiled dll. There's a link to one in this thread, but I always had compatibility issues with it when I tried to use it on XAMPP.

I think it was compiled with a different version of Apache.

2. Getting it working on Ubuntu

It's possible on Mac. Here are two useful links:

http://www.lullabot.com/blog/article/installing-xhprof-mamp-and-php-52-mac-os-106-snow-leopard
http://www.midwesternmac.com/blogs/jeff-geerling/getting-xhprof-working-well

But I haven't done it. I managed to get it working on Ubuntu Server 13.04, although I think any recent version of Ubuntu Server would work.

I set-up my server on VirtualBox. VirtualBox is free but it might take a bit to learn how to set it up.

3.Installing XHProf

I'm going to assume we have a fully functioning Ubuntu Server.

First we need to install pear. We'll use this to install XHProf.

sudo apt-get install pear

We follow this up with phpdev which is also needed.

sudo apt-get install php5-dev

If these commands don't work and I've got them wrong, just go straight ahead with:

sudo pecl install -f xhprof

Ubuntu will tell you what you're missing and give you the prompt to install it. Once you've got all the dependencies install xhprof.

You might get an error on installing xhprof, it'll try to download the beta and fail. In that case try:

sudo pecl install -f xhprof-beta

Hopefully xhprof is now installed.

Now we need to configure it. Open your php.ini which is at /etc/php5/apache2/php.ini
and add the following two lines under the extensions section:

extension=xhprof.so
xhprof.output_dir="/var/tmp/xhprof"

The second line sets the output directory. If this folder doesn't exist you'll have to create it.When you've done that reboot apache using

sudo service apache2 restart

4. Checking if XHProf is running

Now we need to check if that worked.

Test 1:

Enter php -m

If you see xhprof in the list you're good to go. If not, don't worry, try this instead to check if it's working:

Go to your webroot /var/www/ and create a php file with only:

phpinfo();

Save it as phpinfo.php. Open this in your browser and you should see PHP information. Search for xhprof and if you see this then it's running.

5. Getting it working with Drupal

I couldn't get it working with the Drupal module. So instead I'm going to tell you how to get it working with the devel module.

First some config that I borrowed from here. I didn't really follow this part, but it works so gift horse and all that.

Create a new config file with the following command:

sudo nano /etc/apache2/conf.d/xhprof.conf

and insert the following code.

alias /xhprof_html "/usr/share/php/xhprof_html/"

Then we possibly need to create a symlink to our xhprof_html folder. So just in case set this:

ln -s /usr/share/php/xhprof_html /var/www/xhprof_html

This will create a folder in your webroot that points to the existing xhprof file. Then in your browser you can open http://mywebsitehere.com/xhprof to see all the runs you've made.

Then restart apache. Now it's time for a little devel config. Go to the devel settings, enable xhprof and set:

xhprof directory = /usr/share/php

XHProf URL = /xhprof_html

Now at the bottom of each page you should see a little link to xhprof.

And clicking it should take you to a page that looks like this. You're done. Congratulations!

If that didn't work and you're getting run errors it's probably because Drupal doesn't have permission to write to the tmp folder that we set earlier so enter:

sudo chown -R www-data /var/tmp/xhprof

And hopefully that works. We're done. Hoorah!

Unless you want graphing functions. Thankfully that's as easy as:

sudo apt-get install graphviz
sudo service apache2 restart

And now you should have graphing functions. Hopefully that helps!


How do you use Drush to import a bunch of users via a csv file from the command line terminal?

It works with this:

awk -F "," '{cmd="drush -y ucrt " $1 ">> output"; system(cmd)}' users.csv

But it wouldn't work if you have thousands of users as it takes at least a second to create one. And also I can't seem to see the output when the user account is created. Not sure why "output" isn't working. But overall it works if you need to do it like that.

-F stands for field separator
The single quote starts the awk language
cmd is the command variable u designate
system is where you run the variable cmd
users.csv is the file.


Main menu is hidden from unauthenticated users

Follow Below things:

1) Make sure that in admin/people/permissions "View published content", "view own Unpublished Content are "Unchecked" for the "anonymous user".

2) Still if you are getting those "Disclaimer and Policies" menu links. i) Create a new menu and add those links in to that menu. While adding links Give the Parent menu link to "Main Menu". and save the menu. ii) Then admin/structure/block, configure the menu block: Give the permission to access only to Authenticated User and save the block

or,

If you are assigning main menu (as block) to region, you can control it's visibility by "Visibility settings". If you are rendering it in .tpl.php file then you can do it like this: Example (bartik's page.tpl.php):

<?php print theme('links__system_main_menu', array(

  'links' => $main_menu,

  'attributes' => array(

    'id' => 'main-menu-links',

    'class' => array('links', 'clearfix'),

  ),

  'heading' => array(

    'text' => t('Main menu'),

    'level' => 'h2',

    'class' => array('element-invisible'),

  ),

)); ?>


Have a look at template_preprocess_panels_add_content_modal() and $vars['categories']. You should be able to override the category names there.

Edit:

Ahh, yes, I forgot about hook_ctools_content_subtype_alter(). That's more elegant :)

From the documentation:

  This hook can be used to add things like 'render last' or change icons
  or categories or to rename content on specific sites.

In the example below the category "Fielded panes" is changed to "New category name".

/**
 * Implements hook_ctools_content_subtype_alter().
 */
function MYMODULE_ctools_content_subtype_alter(&$subtype, &$plugin) {
  if ($subtype['category'] == 'Fielded panes') {
    $subtype['category'] = 'New category name';
  }
}


Is there a implementaion of the foundation framework for panels?

There is ongoing work in the Zurb Foundation Theme to implement Panels support.

It look's like there has been some progress, I'd check that discussion out first and foremost; then have a look at the search for Panels in that module. There might be more...


How to reorder the date in a view expose filter?

Got the settings Home » Administration » Configuration » Regional and language


Can I store a computed field as a field of a Content Type?

The Concat Field module looks like it can do what you want. From the README:

  This module provides a new field type that allows you to select other
  fields from that content type (or any bundle), and it will concatenate
  their display values into a single field on save.

  The example use case is then using the field as an exposed filter in a
  View.

Or you can write some code to do it via a custom module that calls the hook_node_presave function. In your content type definition, create the fields you want, and set their display type to Hidden. Then, in your function, set the values. See the answer to this question for more info:

How to use hook_node_presave to change field's value

Edit:

While it looks useful at first glance, the Concat Field module is very limited. You can't change the order of the fields, and it requires patches in order to generate any kind of output.

Another option would be to use the Token Field module. With this module, you can create a field into which you can enter tokens. This will give you a lot more flexibility - you can place the fields in whatever order you want, and specify punctuation or other characters around them.

2nd edit to answer updated question

  Token Field suggests that it might be nice if one could define a field
  "without needing to know any PHP" but the samples on this page
  indicate otherwise.

My interpretation of the Token Field page is you only need to know PHP if you want to use conditional tokens, and that's what the sample code illustrates.

  Will this be possible (without PHP) if I install Token Field?

In theory, yes, but the only way to know for sure is to try it. If you're worried about compromising your site or database, install Token Field on simplytest.me and set up your content type there.


How to move block from a region inside of hook_preprocess_node?

I think you should send render of the block not an array of block entity.
View Method return an array.

Try with renderer service like the following:

/**
 * Implements hook__preprocess_HOOK().
 */
function mymodule_preprocess_node(&$variables) {
  $node = $variables['elements']['#node'];
  if ($node->bundle() == 'page') {
    $block_entity = Drupal\block_content\Entity\BlockContent::load(12345);//BLOCK_ID
    $block_view = \Drupal::entityTypeManager()
      ->getViewBuilder('block_content')
     // Change here default by your block view mode
      ->view($block_entity, 'default');
    $variables['mycustomblock_variable'] =\Drupal::service('renderer')->renderRoot($block_view);
  }
}


How do I set a variable to the value of a field another field?

This is something better suited for preprocess in my opinion (I don't like a lot of conditional etc logic in twig files):

$variables['node_video'] = NULL;

if ($node ... field_a has value) {
  $variables['node_video'] = // set to render element for field a in 'content';
}

if ($node ... field_b has value) {
  $variables['node_video'] = // set to render element for field b in 'content';
}

Then in twig:

{% if node_video %}
  {{ node_video }}
{% endif %}

Basically, if this variable is not null, it should point to one of the $variables['content']['field...'] items from the preprocess code, then render it. {{ node_video }} in this case is the equivalent of {{ content.field_name }}, to spare a lot of IF/ELSE/OR stuff in Twig.

But what is likely easier is leveraging Media and Media Youtube with Media Video and using one field. That should scale. Imagine you want to add Vimeo, Twitch, or other supported Media sources in the future, you would have to keep expanding on this code.


how to show teaser view of my content types in search result page in drupal 7

You can use template_preprocess_search_result for that

function MYTHEME_preprocess_search_result(&$vars) {
  $node = $vars['result']['node'];
  if ($node->nid) { // here you load the teaser if the result is a node
    $vars['teaser'] = node_view($node, 'teaser');
  }
}

You can make a template file to customize the result: https://api.drupal.org/api/drupal/modules!search!search-result.tpl.php/7.x


I don't know your themes output but maybe you could try to edit the style of

#user-register-form {

}

It would be helpful to see the website with the user-register-form.


What is the purpose of Views "Attachment", "Content pane" & "Context"?

The Attachment option is to create yet another view that you can attach before and/or after any of the displays on your current view.

An example of its use is if you enable the taxonomy views the taxonomy pages are overwritten by the view and if you were to add a couple of extra fields like images, description, etc to your taxonomy term you can the use an attachment to display it as the header of each taxonomy page.

The EVA module extend this functionality by allowing you to attach views to content types and other entities.

The other two I have never use, but:

Here is an explanation about "Content pane":

http://drupalize.me/videos/basics-views-content-panes


How to set up drush on Cloudways / Digital Ocean?

I'd recommend trying the official Drush installation instructions.  Note that the first recommended installation method is to download the phar, which you might find easier to get working than the Composer-based instructions.

The GoDaddy instructions (at the time of this writing) recommend installing the latest unstable version of Drush. This is not recommended unless you are planning on frequently updating Drush, in which case you are better off installing via git rather than downloading an archive.


Hey if you have any idea about drupal form alter then go with http://api.drupal.org/api/drupal/developer!hooks!core.php/function/hook_form_alter/6.

hope this will help you.


How to validate the headers of a csv uploaded with cck filefield?

Just got this too work:

/**
 * The validation for the stocklist.
 *
 */

function stocklist_validation($field) {
  // variable for error messages
  $errors = array();

  // do some processing on the field / file
  $filepath = $field->filepath;

 // Open the file

      if ( $handle = fopen($filepath, 'r') ) {
        $line_count = 1 ;
        $first = TRUE ;
        if ( $line = fgetcsv($handle, 4096) ) {

        // Validate the headers
         if ( $line[0] !== 'something' ) {
            $errors[] = t('Please ensure the files 1st column has the something in it. Including something as the heading.');
         }

    if ( $line[1] !== 'somethingelse' ) {
            $errors[] = t('Please ensure the files 2nd column has the somethingelse in it. Including somethingelse as the heading.');
         }

        fclose($handle);
      }

           else {
        $errors[] = t('Unable to open uploaded file !filepath.', array('!filepath' => $filepath));
       }
      }
// in case of errors, return error messages

          return $errors;
}

The first function didn't need changing...

In the second function, it was the fopen() that needed changing. Secondly, like an idiot I just realised that the "valid" file was actually tab delimited... Doh! Would be nice to be able to accept those files too. As some software saves csv files in that format, such as the one I clearly used, OpenOffice.


How to disable/turn-off drupal 7 caching permanently, to not to mess with module's operations?

As per Suppress caching (for development), you can add the following to your settings.php file

if (!class_exists('DrupalFakeCache')) {
  $conf['cache_backends'][] = 'includes/cache-install.inc';
}
// Default to throwing away cache data
$conf['cache_default_class'] = 'DrupalFakeCache';
// Rely on the DB cache for form caching - otherwise forms fail.
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';

I'd recommend you don't just blindly add that, though. Instead, take the time to think what you do need to cache, and what you don't need to cache, and come up with a proper strategy. For example, it's hardly likely that you need rebuild the cache of hook implementations on every single page load, regardless of how highly available the site is.


Correct way to massively change node author

It sounds like your Administering a Drupal site (not just a content moderator) -- but a site administration / developer.

Your code is fine. I recommend using Drush and calling your code as $ drush php-script massively-change-node-author.php from the command line. This way there is no timeout issues and you don't need to worry about using the Batch API and stuff like that.

Running code from php-script and drush performs a FULL BOOTSTRAP of drupal by default, and if needed you can pass a user argument to run the script as (faking a logged in user of $user) by using --user=1 for instance. For example: $ drush php-script --user=1 massively-change-node-author.php.

EDIT:

To avoid out-of-sync errors between node and node_revision table it's recommend to use node_load() and node_save() on the Nodes you want to update. Eg,

global $user;
foreach ($node_ids as $nid) {
  $node = node_load($nid);
  $node->uid = $user->uid;
  node_save($node);
}

Getting the list of node ids you want to affect, I leave as a task for you. The issues such as timeouts, using batch api etc -- are all still gone when using Drush. The logic is very similiar just using the better drupal API rather than direct database updates.


Sure! I would recommend you:

Create a taxonomy called "global_sku" ... Amazon calls their psuedo sku "ASIN" ... which is just a number that ties all the "product displays" to one page.
Now ... on your product displays, you could create a taxonomy reference to global_sku's
And then add some Views that will bring in related products based on the taxonomy.


Installing Drush on Mac OS 10.13 (High Sierra)

Drush 9 only supports one install method. It requires that your Drupal
  8 site be built with Composer and Drush be listed as a dependency.

See http://docs.drush.org/en/master/install/

There it's recommended you start your Drupal 8 project with Composer. Then add Drush as local dependency to your project and use this local Drush to do things.

$ cd drupal
$ composer require drush/drush
$ vendor/bin/drush cr

Using the Composer template for Drupal projects Drush already is listed as a dependency.

$ cd ~/Sites
$ composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction
$ cd some-dir
$ cd web
$ ../vendor/bin drush si

Additionally you then can install the Drush Launcher which will replace the global drush command with a wrapper that always automatically finds and executes the local Drush in every directory.

If all of this is no option for you you might want to have a look at Having multiple Drush instances for different core versions where I show how you'd still be able to install a global Drush quite easily.


Images in content type: reusing and limit

Use the FileField Sources module to allow you to select new or existing files through additional means, including:

Re-use files by an auto-complete textfield
Attach server-side files uploaded via FTP
Transfer files from a remote server (cURL required)

4. Select existing files through the IMCE file browser

Also, to raise the limit of uploaded images from 10 to more, edit your image field settings and set the "Number of values" to "unlimited"


Here is what I understand with the current Drupal 7.32.  The behaviour of the i18n in Drupal heavily depends on the settings, so I mention the way I am fairly familiar with.  If your settings are different, the behaviour can be different.

First, i18n_menu must be enabled, as well as i18n_node (I understand some people prefer Entity translation, whose behaviour must be different, but I don't know about it).

Second, give "URL" with "Path-prefix" the top priority at /admin/config/regional/language/configure.  Also, personally I much prefer to explicitly set the path prefix for the default language (usually English, "en") at /admin/config/regional/language/edit/en.  In default it is Null and that is I found quite confusing due to its inherently asymetric nature.  Having said that, it is up to each developer, obviously!

Third, "Translation mode" at /admin/structure/menu/manage/main-menu/edit is the key.  In default, it is "No multilingual options for menu items".  Obviously that is no good for translatable menus.  Choose either of the following two options, that is, (1) "Translate and Localize." and (2) "Fixed Language."

I think the second option (2) suits the most sites, unless the menu stractures for all the supported languages in the website are identical.  If you choose (2), simply create another menu, say, "Main French Menu", tick the "Fixed Language" as French, and place it in the area you like in the block configuration /admin/structure/block

If you choose the first one (1) "Translate and Localize", you then will see "TRANSLATE" tab (near the top) in /admin/structure/menu/manage/main-menu/edit (for the main menu, for example) and can now translate each link from the "translate" column (right-most?) at /admin/structure/menu/manage/main-menu.

Now, there are more than one option, entirely depending what you want to achieve on the menu.  For example, suppose there are a node "Hello" and its French translation node of "Bonjour" (they are two different nodes, say, nodes 1 and 2, respectively).  Would you like to provide the two links for both "Hello" and "Bonjour" in the menu (when viewed in either language)?  Or, would you like to provide the link for "Hello" for the English mode/readers, and that for "Bonjour" for the French mode?  (Such is the complexity of multilingual sites...)

Suppose you prefer the second option.  As an example, prepare a single menu link for "Hello/Bonjour" in the main menu; that is, the plan is, "Hello"-menu linked to "Hello"-node(=1) appears if viewed in English, and "Bonjour"-menu linked to "Bonjour"-node(=2) appears if viewed in French.

First you create the "Hello" menu link, linked to node 1.  Second, via the above-mentioned "TRANSLATE" tab in /admin/structure/menu/manage/main-menu/edit, you input the translated title as "Bonjour", and don't forget to change the link to Node=2 to make "Bonjour"-menu correctly point to the French "Bonjour" article.

Now if you view a different French node ("Au revoir" for example) in French (the path-prefix must be /fr/), you will see the menu of "Bonjour", which is linked to the French "Bonjour" node.  If you see its English translation ("Good Bye") in English mode (the path-prefix must not be /fr/), the menu above is "Hello", which is linked to the English "Hello" node.  Job's done.

The thing is, I think it is simpler to set the path-aliases for each content (a single path alias for a set of nodes for all the translations), and basically to give up using the form of node-type links like /node/2 entirely.  In the above-mentioned example, say, suppose you set the path-alias of artilce/hello for the node 1 (English; don't set a different path alias for the node 2, French, as it would add a confusion).  Now by accessing /fr/artilce/hello, you can see the node of "Bonjour" with the French menu.  However, if you access /fr/node/1, what you will see is the English "Hello"-node(=1), while the menu above is French one "Bonjour".  It is because the node=1 is written in English, while you are viewing the content in the French environment, which forces the menu to be in French (if you have enabled localising, other parts like user-menu become also French, but not the main content).

For some people, that may be what they want.  For example, a French shopping site may offer an English interface for shopping-basket etc, while they can't be bothered to translate the description of each item to sell.  I am guessing that is why the i18n in Drupal is designed like this.

Finally, you may want to "Flush all caches" frequently, while you modify the settings, to make sure any change you have made is reflected to what you see.


Is deactivating modules safe regarding settings?

It's impossible to say from here. Theoretically yes.
It depends on the module - a specific module could easily clear its variables in hook_disable(), or hook_uninstall(), or not at all. You'll have to check the install file for each module you disable to see how it will affect what you're doing.

It sounds very much like you have two copies of the image_desaturate_formatter module in your Drupal install though; that could account for the error.

Regarding server logs - your host should give you access to these (I've never come across a host that would deny you access to your own logs, it's criminal!) so give them a call, they might have valuable information in them.


How to add {less} files to Omega HTML5 subtheme?

Install the LESS module and then in your custom-html5.info file just add your LESS CSS files like you would normally add stylesheets:-

stylesheets[all][] = css/custom-html5-alpha-default.less

The module will detect the LESS files (those with a .less file extension) and process them so that they are output as standard CSS.

Processing the LESS files on the server rather than via the browser using JavaScript will give the end user a better experience and ensures that the look of your site isn't dependent on JavaScript. If you really must include the less.js file then perhaps you could consider using the drupal_add_js() method in your template.php file.


What is the "correct" way of reporting problems detected by sanity checks, or catching exceptions?

In core Drupal try-catch blocks are pretty rare, because code is consistent, and core (boldly) assumes that code in contrib and custom modules will be good, too. One core function simply won't send malformed data (like non-objects where object is expected) to another - and won't expect another code to send inconsistent data to it. So try-catch would only slow things down. On the database side, and on the user input side, checks are performed all right. This, of course, is by far most recommended approach. If you can make sure your data is coherent, do it. Don't call Entity API at all if you haven't ensure you will not cause EntityMalformedException.

The only place it's not possible is a border between Drupal and other systems (including database and http connection). There, you need to put safeguards up. Your points are correct then, but you need to add one more:

Call watchdog
Set message for admin
Tell your user that what he think he did might have not happened. For example, if your code failed to delete a photo user really, really need to have taken down and you won't tell him, he may be disappointed. In some situation, you may also find yourself in legal trouble.
And only now proceed


Entity Browser Widget for Video Embed Media Entity

I could not find any way to implement an 'Add New Video' widget to an Entity Browser.

There is a solution using Inline Entity Form. https://www.drupal.org/project/inline_entity_form

With Inline Entity Form, you can have an entity creation option, or add existing entity option.  You can then use an Entity Browser for selecting existing entities, and leave the adding of new entities up to Inline Entity Form.

It's quite a clean User Interface / User Experience once implemented: