texts: Programmatically add node translation drupal 7 ( Entity translation )

texts:
I need to create multilingual node programmatically in Drupal with entity_translation.

No problem to create the node, but I have no idea how can I create the translation ( + field translated).

I don't want to create another node, just translate it (same nid).

My language is FR , I need translation in EN and DE.


texts:
I'm using an AJAX form to match multiple values of a field to an other entity, to do so i've implemented the example we have in the ajax_example ( https://api.drupal.org/api/examples/ajax_example!ajax_example_graceful_degradation.inc/group/ajax_degradation_example/7 ), see ajax_example_add_more*

It is working great (except i would prefer being able to remove the field i want and not always the last one but we can't have everything).

When i submit the form, my chosen values are saved in database and the page is refreshed. The problem is that the form became empty, i might have multiple names for one fieldset and now i only have one empty textfield.

If we continue with the ajax_example, what i can do is this :

$myValues = variable_get('my_var', '');

And on this part add a default_value (let's assume that in my $myValues['name'] there is the list of the names)

$form['names_fieldset']['name'][$i] = array(
      '#type' => 'textfield',
      '#title' => t('Name'),
      '#default_value' => $myValues['name'],
);

In the case where i add only one name, it will work. But if i have multiple name, it will only display the last one.

Do you know how can i do to recreate all the form as it is store in the db ?

Thanks by advance

[EDIT]

Thanks to sareed, i found the way to do so. I'll show the modification to ajax_example_add_more. In the example there is only one fieldset, in my work there is x fieldset so i will add $fieldsetName to know which one :

Change :

 if (empty($form_state['num_names'])) {
    $form_state['num_names'] = 1;
  }

By

     $myValues = variable_get('my_var', '');
     if (empty($form_state[$fieldsetName]['num_names'])) {

          if(isset($myValues[$fieldsetName])) {
            $form_state[$fieldsetName]['num_names'] =
              count($myValues[$fieldsetName]) > 0 ? count($myValues[$fieldsetName]) : 1;
          }
          else {
            $form_state[$fieldsetName]['num_names'] = 1;
          }
      }

AND

  for ($i = 0; $i < $form_state['num_names']; $i++) {
    $form['names_fieldset']['name'][$i] = array(
      '#type' => 'textfield',
      '#title' => t('Name'),
    );
  }

TO

  $form['names_fieldset']['name'][$i] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => isset($myValues[$fieldsetName][$i]) ? $myValues[$fieldsetName][$i] : '',
  );


texts: How do I resolve a PDO exception (SQLIte) error while deploying on Azure?

texts:
I'm deploying a Drupal site to an Azure App (do not have any choice in the matter, so no point suggesting other environments) and do not have access to it directly (no SSH) as it is a infra-structure as service sort of thing. Long story short is that I deploy it via github. I'm using Sqlite and all works fine on my local environment. However when I do push it to Azure via Github, I get the following error: PDOException: SQLSTATE[HY000] [14] unable to open database file in lock_may_be_available() (line 167 of D:\home\site\wwwroot\includes\lock.inc).

I have changed all files and folder permissions (for test purposes I even set all to 0777) and it did not work.

Any ideas on how to get this setup working?


texts: Exposed filter selectbox dropdown for a textfield

texts:
I have a textfield for one of my content types and there are many unique results for it. I am trying to create a View of this content type of this textfield as an Exposed Filter with a list of all the unique results from this textfield. Views by default only gives you a textbox for you to search through these results, but if you don't know what to look for, it doesn't work too well.

How would I expose this textfield of all the unique results in a selectbox in a view?


texts: I'm constantly getting logged out of my account

texts: I have a weird issue on a test server where I get constantly logged out. What could cause that?


texts: Can I implement a role based access to menu items in content creation?

texts:
Example:

role A is authorized to publish under specific taxonomy terms. When he activates "provide a   menu link" I would like to restrict the parent items available to certain menus. How can I do that?

Thank you!


texts: Allow customer to change Quantity in cart

texts:
On my site it's not possible for customers to edit the quantity field in the cart view.

How do I allow that? I can't find a permission setting for this anywhere.


texts:
I am trying to import View from one Drupal 7 Environment (from local to
pantheon one) and got this error:

- Field handler views_entity_commerce_order.operations_dropbutton is not available
- Unable to import view.

Any ideas what is going on here ?


texts:
I have used hook_drush_command to create a new drush command. This is my custom code for creating drush command.

/**
 * Implementation of hook_drush_command().
 */
function mymodule_drush_command() {
  $items = array();
  // Name of the drush command.
  $items['list-site-users'] = array(
    'description' => 'Print the list of users in the site',
    'callback' => 'drush_get_site_users',
  );
  return $items;
}

function drush_get_site_users() {
  $query = db_select('users', 'u');
  $query->fields('u', array('name'));
  $result = $query->execute();
  while($record = $result->fetchAssoc()) {
       print_r($record['name']);
  }
}

After this I have exceuted drush cc all and drush cc drush for clearing drush. Then I have executed my custom drush command drush list-site-users command, but it is throwing the below error.

  The drush command 'list-site-users' could not be found.  Run drush
  cache-clear drush to clear the commandfile cache if you have
  installed new extensions.

My drush version is 5.10.0


texts: Hide "Your name" field in comment form from everyone except admin

texts:
What I want to achieve is to hide the "Your name" field in comment form from all anonymous and authenticated users but visible to users with the admin role.

I was able to use CSS to hide the field, but it also hides from admin.

Please is there a way to selectively hide the field to anonymous and authenticated users but not to administrators?


texts:
I'd like to add a taxonomy term to the list of CSS classes for a div with the id "primary" on a modified Bartik theme. I know the change needs to happen at page.html.twig or something derived from that, but I'm having a hard time determining how the preprocess page and the twig function together.

Based on this example: How do I theme a taxonomy term page?

I've added the following information to a theme file:

use Drupal\taxonomy\Entity\Term;

function MYTHEME_theme_suggestions_page_alter(&$suggestions, &$vars) {
  if (\Drupal::routeMatch()->getRouteName() == 'entity.taxonomy_term.canonical'$
    $term = Term::load($tid);
    $suggestions[] = 'page__taxonomy__' . $term->getVocabularyId();
  }
}

And added a new twig called page--taxonomy--TAXONOMYTERM.html.twig where I added "taxonomy-TAXONOMYTERM" as a class to the div I'm looking to alter:

 <div id="primary" class="{{'taxonomy-TAXONOMYTERM ' ~ 'content-area col-sm-' ~ primary_col }}">

As far as I can tell, according to the example this should work. But in reality, the term isn't showing up when I look at an article with the appropirate taxonomy term.  What am I doing wrong?  Is there a better way to attach the taxonomy term to a div class?

Thanks!


texts: Trigger whenever a user uploads an image

texts: I would like to enable certain actions to occur whenever a user uploads an image, namely movement to s3 and adding an entry in the db for site and metadata purposes. What would be my first steps in accomplishing this?


texts: Does the SimpleTest method drupalGetMails() prevent actual emails from being sent?

texts: During a SimpleTest, does the data intercepted by drupalGetMails() continue to your systems mail transport agent or is the actual send suppressed?


texts: Checklist for drupal developers to be ready for drupal 8

texts: As Drupal 8 will be using symphony framework, what will be the best learning path for developers to get ready to adopt for Drupal 8.


texts: Why is Drupal prepending 'node' to the link URL?

texts:
I am working on a Drupal site. My issue is that when a link is created either by using the url() or the base_path variable, it works OK on local development environment. But when the very same code is put on the server, the URL prepends node string in the path .

E.g. the path is <drupal site>/latestnews. The generated path is <drupal site>/node/latestnode and when clicked, it shows the page not found error. However I would like to mention that the links work fine (i.e generate correct path) when clicked from the home page.

Any help would be appreciated. If it can help, am using Pantheon hosting for testing.

UPDATE

menu link generation code is as under. (the  code can show my proficiency in drupal :) )

function GetMainMenuItems()
{
    $menu = menu_tree("main-menu");

    $keys = array_keys($menu);

    $count = count($keys);

    unset($keys[$count-1]);
    unset($keys[$count-2]);

    $items = array();

    foreach ($keys as $key) {
        $temp = array(
            'title' => $menu[$key]["#title"],
            'url' =>   url($menu[$key]["#title"])
        );
        $items[] = $temp;
    }
    return $items;
}


texts: I am working on a drupal site and One of the functionality of my site is to have an ideation platform. Can I make a distribution work seamlessly within my drupal instance ?


texts: How to use entity_metadata_wrapper for users particulary in hook_user_presave

texts:
For node I can use the entity_metadata_wrapper like below

function mymodule_node_presave($node) {
  $ewrapper = entity_metadata_wrapper('node', $node);
  $ewrapper->title->set('new title');
}

However how can I use the entity_metadata_wrapper for users. I want to use entity_metadata_wrapper in hook_user_presave.

function mymodule_user_presave(&$edit, $account, $category) {
  ???
}

this variant works for me:

function mymodule_user_presave(&$edit, $account, $category) {
  $edit_object = (object) $edit;
  $ewrapper = entity_metadata_wrapper('user', $edit_object);
  $field_telefon = $ewrapper->field_telefon->value();
  $ewrapper->field_telefon->set($field_telefon.'123');
  $edit = (array)$edit_object;
}


texts: How do I set a visibility rule for the individual menu block items?

texts:
Is there a way of setting visibility of menu items itself based on the URL?

With the Panels module, we can set visibility of the panel section based on the URL or other rule. How can I set that kind of rule for individual items of a menu block?

For example, the menu block has the following items: Item-1, Item-2, Item-3, Item-4. If the URL is node/,  display all items; if the URL is node/string-1,  display Item-1, Item-2, Item-3; if the URL is node/string-2, display Item-4, item-5, Item-6.


texts:
I'm getting this error. The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection

I'm using Lightning 2.1.6.
I set up a media upload field on my page content type using reference to content/ reference media. It also uses the media browser to upload images. This field allows a single image upload. I get the error when you try to upload an image. And the image doesn't get added. If i allow multiple upload instead of single the error goes away. Also If I disable the "Interface Translation" module the error goes away and the images can be uploaded.


texts: how to solve Notice: Undefined offset: 1?

texts:
I used the following function to alter menu (hook_menu_alter)

function _term_account(){
  global $base_url;
  global $user;
  $account_id = custom_get_user_account_id();
  $tesr = explode('_', arg(3));
  if($tesr[1] == $account_id){
    return true;
 } else {
    return false;
 }
}

function custom_menu_alter(&$items) {
  // Works fine.. So every user has he's own and only vocabulary return true..
  $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/list']['access callback'] = '_term_account';
  }

and it works fine.. but.. when i go to reports/dblog in my site.. i have over than 30 row of same error

  Notice: Undefined offset: 1 in _term_account() (line 277 of
  ../public_html/sites/all/modules/custom/custom.module).

Is there something wrong in the function?


texts: What is the recommended method for programmatically editing or inserting values into the field_data_* tables?

texts:
I'm using Drupal 7.7

I'm working on a module to programmatically add users to an Organic Group.  I'm using og_group() and og_role_grant(), but the user is not given full access without also having their group_audience field set correctly.  So, my end goal is really to do just that.  I cannot find any OG functions that will perform that function, so I'm asking, generically, if there is any Drupal-approved method of writing data into that table.

I've tried using field_bundle_settings(), but I can't get that to work, and I'm pretty sure it won't ever work.

my code is below:

<?php

$settings = array(
    'group_audience' => array(
    'entity_id' => $user->uid,
    'group_audience_gid' => $gid,
    'group_audience_state' => '1',
  ),
);
field_bundle_settings("user", "user", $settings);

thanks


texts: Check if user can edit node with certain ID

texts:
I need to know a function or a way to find out if a user can edit a certain node.

For example I have the nid 200 and the user foo has logged in, I want to check if he is able to edit node/200.

Thanks


texts: I’m using Drupal 8.5.4 and I have installed the Advanced CSS/JS Aggregation module. I’m trying to install the Waypoints plugin without success via the module: jQuery waypoints (still on alpha1 for D8). Is there a way to simply install the plugin manually?


texts: How do I prepopulate the value of a taxonomy term reference field on the node creation form?

texts:
I'm using an approach similar to the one taken in this question.  The difference is that I have a taxonomy term reference field in the user profile that I want to use to prepopulate a custom content type.

To prepopulate a text field on a custom content type with a value from the user profile, I have added this code to a custom module:

function MYMODULE_form_MYFORM_node_form_alter(&$form, &$form_state, $form_id) {
 // test if node for has been assigned a NID. If not then populate fields with default data */
  if (empty($form['nid']['#value']) && (!isset($form['#node']->op))){
    global $user;
    $user_fields = user_load($user->uid);
    //set age
    if (isset($user_fields->field_acc_age['und'][0]['value'])){

      $form['field_ad_age']['und'][0]['value']['#default_value'] =  $user_fields->field_acc_age['und'][0]['value'];
    }

However, when attempting to prepopulate a taxonomy term reference field from the user profile to the custom content type, the above code doesn't work; there is no error, but the value is not carried across.  I assume this is because term references are stored differently in the DB, but I don't understand how to change the code to make it work.


texts: Converting referenced product into product display node?

texts:
I have a content type of "Product of the week" where an admin will choose 3 products and save this, from here a view pulls in the following information:

FILTER CRITERIA:

Content: Type (=Product of the Week)
Content: Published (Yes)

FIELDS:

(Hidden) User: Picture
(Hidden) Content: Body
(Hidden) User: First
Name Global: Custom Text

Here is where it gets tricky. I need to pull in the following information grouped together:

Product Image
Product Title (Linked to go to the product display for the product)
Formatted Price

No matter how I work it, I cannot figure out how to reliably get these fields. I can use a referenced product entity but this causes the link to reference the /admin/ page for the product, not the product display link.

I can create a separate view to get the product display information easily, but is it possible to then pull that into this table?


texts: Commerce line item fields - getting value

texts:
I have a custom line item type that has a List(Text) field. When I do this:

$line_item = commerce_line_item_load($lid);

I get an object that contains the value, but not the label of the selected option.

$line_item->field_ring_size[LANGUAGE_NONE][0]['value'] // returns 2 instead of, say, Large

How can I get the value's label instead?

I've tried using field_info_instance to get all values, as follows:

$info = field_info_instance('commerce_line_item', 'field_ring_size', 'ring_setting');

...but this does not return the values as far as I can see. Similarly, I've tried field_get_items, but this gives me the key back again.

How can I get the value (or a list of all values) instead of the key?


texts: How to validate exposed autocomplete to select values from list only?

texts:
I have custom module with the following code, but I have no idea to validate the exposed auto-complete field to select values only from the list. Any ideas on how to validate the exposed auto-complete field ?

function advanced_form_alter(&$form,&$form_state,$form_id) {

if($form_state['view']->name == 'propertyseach') {

$form['bed']['#options']['All'] = t('Bed'); // overrides <All> on the dropdown
$form['section']['#options']['All'] = t('Type'); // overrides <All> on the dropdown
$form['bath']['#options']['All'] = t('Bath'); // overrides <All> on the dropdown
$form['furnished']['#options']['All'] = t('Furnished'); // overrides <All> on the dropdown
$form['frontprice']['min']['#title'] = '';
$form['frontprice']['max']['#title'] = '';
$form['frontprice']['min']['#attributes']['placeholder']= t('Min.Price');
$form['frontprice']['max']['#attributes']['placeholder'] = t('Max.Price');
        $form['frontprice']['min']['#size'] = '10';
        $form['frontprice']['max']['#size'] = '10';
        $form['frontprice']['min']['#maxlength'] = '10';
        $form['frontprice']['max']['#maxlength'] = '10';

$form['community']['#attributes']['placeholder'] = t('Enter Location (City or Community )');
$form['#validate'][] = '_your_custom_validation';
}
    drupal_set_message($form_id);
        }

function _your_custom_validation($form, &$form_state){
  //validate stuff, using form_set_error()
}


texts: How to build a block on form submission?

texts:
I know how to build a block using these functions :

hook_block_info()
hook_block_configure()
hook_block_save()
hook_block_view()

But on a form submission a few information is saved into DB and based on those information one block must be created.  how do I can build a block in that way?


texts: Stop from going to node on content creation

texts:
I would like for when I add of piece of content for it to stay on the admin back-end.. right now it forwards the user to the created node with a message saying it's been created, but the rest of the admin interface disappears so it's difficult to get back to adding more, and certain content types look very strange in that view.

I looked at actions/triggers, but I don't see a way to distinguish between content types, and I wouldn't want comments and user posts to forward to the admin interface so I don't see that as a solution.


texts: Dynamic Content Type? (field appears based on previous taxonomy choice)

texts:
I want to show/hide a field based on a taxonomy choice (in the content admin side of things).

Though having this field attached to every item of this content type does add overhead; I suspect it contributes to the easiest solution for a dynamic field.

I like the idea of dynamic fields, where only certain instances of an entity would have/need them, however, this seems like it could be quite an undertaking. (or my Drupal imagination is lacking today)


texts:
I'm working with entities and, in trying to troubleshoot another issue, I noticed that hook_schema() is called twice each time the module is installed. This happened even with a bare bones test module containing only a hook_schema() definition. My questions are:

Is it normal for hook_schema() to be called twice on module installation?
Why would hook_schema() be called twice on installation?


texts:
In Drupal 8, I don't understand how build a "hierarchical" form.

I have this sample form

...
public function buildForm(array $form, FormStateInterface $form_state) {
    $form['description'] = array(
        '#type' => 'fieldset',
        '#title' => t('Main description'),
    );
    $form['description']['subfirst'] = array(
        '#type' => 'textfield',
        '#title' => t('subfirst'),
    );
    $form['description']['subsecond'] = array(
        '#type' => 'textfield',
        '#title' => t('subsecond'),
    );

    $form['content'] = array(
        '#type' => 'fieldset',
        '#title' => t('Main description'),
    );
    $form['content']['subfirst'] = array(
        '#type' => 'textfield',
        '#title' => t('subfirst'),
    );
    $form['content']['subsecond'] = array(
        '#type' => 'textfield',
        '#title' => t('subsecond'),
    );

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',
    );
    return $form;
}

public function submitForm(array &$form, FormStateInterface $form_state) {
    dpm($form_state->getValues(),"getValues");
}
...

When I submit my form, my form_state->getValues() return :

The form_state->getValues() contains only the ['content']['subfirst'] and ['content']['subsecond'] values...
That means I must use uniques labels with the form api ? I find it weird...

Then, I change my form :

$form['content']['subfirst'] become $form['content']['totosubfirst']

$form['content']['subsecond'] become $form['content']['todosubsecond']

The new code :

public function buildForm(array $form, FormStateInterface $form_state) {
    $form['description'] = array(
        '#type' => 'fieldset',
        '#title' => t('Main description'),
    );
    $form['description']['subfirst'] = array(
        '#type' => 'textfield',
        '#title' => t('subfirst'),
    );
    $form['description']['subsecond'] = array(
        '#type' => 'textfield',
        '#title' => t('subsecond'),
    );

    $form['content'] = array(
        '#type' => 'fieldset',
        '#title' => t('Main description'),
    );
    $form['content']['totosubfirst'] = array(
        '#type' => 'textfield',
        '#title' => t('subfirst'),
    );
    $form['content']['totosubsecond'] = array(
        '#type' => 'textfield',
        '#title' => t('subsecond'),
    );

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',
    );
    return $form;
}

And when I submit my form, my form_state->getValues() return :

I get the four values. But, they are in the same hierarchical level. How I use the form api for have a form_state like this :

'description' => 'subfirst' => string(3) "AAA"

'description' => 'subsecond' => string(3) "BBB"

'content' => 'totosubfirst' => string(3) "CCC"

'content' => 'totosubsecond' => string(3) "DDD"

?

I want get a hierarchical form_state because after I want create a custom function like :

foreach element in description
  do that
foreach element in content
  do that
...


texts:
My requirement is to update some params in the script for a some specific nodes. If a set of nodes is attached to an X content type, it should take some params in a script. For this purpose I am running a cron job every 10 min as new contents can be attached to that X content type. In this cron job, I am fetching all nodes belonging to X content type and also from these nodes, I am getting set of nodes attached to each X node. I am storing the corresponding param value for a node in the cache using the function cache_set().

cache_set(node id, X node id, MY_CACHE_NAME, CACHE_PERMANENT)

But the problem is that some nodes are not taking the param sometimes. I think that it is setting the cache, but in the cache table something wrong is happening. But when I run 3 or 4 times the nodes which were not taking param started taking. I am not getting what is happening that cache table.

I am not getting where it is writing to the database. How can we test the problems related to these caching?

I am clearing the corresponding MYCACHE  before every cron runs.

hook_cron {
  cache_clear_all('*', MY_CACHE, TRUE);
  take_params();
}

What am I doing wrong?


texts: How can I add template suggestions by UUID?

texts:
I'm looking for a solution to migrate content between environments (dev->staging->production) and currently I think I'll use UUID and Node Export (as far as I see UUID Features is still in alpha and isn't recommended by the community).

Sometimes I want to use template files or hooks (e.g. theme_preprocess_node) specific to a node created on my dev and then to upload the changes to production - this thing is impossible with the use of nids, but must be possible with uuids.
Is there any way out of the box to add theme_hook_suggestions by uuid, or do I need to implement it on my theme?

Thanks.


texts: Change the Default " - Choose -" text in Ctools Jump menu?

texts:
I've created a Ctools jump menu in a block in a module. The default text which Ctools provides for their jump menu is "- Choose -". Is there a way to change this in the module? I'm guessing it should happen somewhere in this line of code but not quite sure how to do it;

$form = ctools_jump_menu(array(), $form_state, array($url => t('Classified Ad'),$url2 => t('Places'),$url3 => t('Facility')), array());


texts: How to resolve the SMTP not connect to server drupal?

texts:
I have used the SMTP Module for sending mails and done all the configuration according to this link(URL: http://www.symphonythemes.com/drupal-blog/configure-drupal-smtp-gmail).

But I could not send a mail. The error is like phpmailerException: SMTP Error: Could not authenticate. in PHPMailer->SmtpConnect().

Please help me, How to sort out this issue.


texts:
A site where the site owner put off having updates done has been compromised with ransomware. This situation brings up a lot of questions. A Google search has not produced any answers. The server is on a university system where they lock things down pretty tight.

Are there any stats on the ransomware infection rates for Drupal sites, esp. compared to other systems?
What is the most common part of a Drupal site to be the hole for a ransomware compromise, ie. specific module, Drupal core, login function,  Apache server function?


texts:
This is the error shown in reports/status.

  Your system or network configuration does not allow Drupal to access web pages, resulting in reduced functionality. This could be due to your webserver configuration or PHP settings, and should be resolved in order to download information about available updates, fetch aggregator feeds, sign in via OpenID, or use other network-dependent services. If you are certain that Drupal can access web pages but you are still seeing this message, you may add $conf['drupal_http_request_fails'] = FALSE; to the bottom of your settings.php file.

What do I need to configure to prevent this error?

My website works well, but this error causes some problems, for example with the Quicktab module.

As you can see Tab Content disappeared and Tab Weight is changed to the select list. What do I need to do to fix this?

Besides that, I have other sites on this server; none of them has reported this error.


texts: How can I clear the Menu cache after saving some configuration?

texts:
I'm in the process of creating my first D7 module, partly based on the tutorial found here. My module creates (among other things) a public page to show some content, and it also has a configuration page (in the Drupal admin) that allows the user to choose the path at which this page must be displayed (e.g. "mypage" or "content/mymodule" etc).

My problem is that saving this value through the configuration form is not enough: you also have to clear the Menu cache, otherwise the old path remains active, and the new one gives you a "page not found" error.

I need that to occur automatically every time this value is changed (or every time the form is submitted). I tried using menu_rebuild() in my validation function, but it's obviously not the right place, because it is triggered before the new data is saved, and so the menu is rebuilt with the obsolete data.

How should I proceed if I want the Menu cache to be automatically cleared after the data has been validated and saved?

Here's my implementation of the pages, via hook_menu:

<?php

/**
 * Implements hook_menu().
 */
function mymodule_menu() {
  $items = array();

  // config page
  $items['admin/config/services/mymodule'] = array(
    'title' => 'mymodule',
    'description' => 'Configuration for the mymodule module',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('mymodule_form'),
    'access arguments' => array('access administration pages'),
    'type' => MENU_NORMAL_ITEM,
  );

  // public page
  $m_title = variable_get('mymodule_title', 'Mymodule');
  $m_title = $m_title ? $m_title : 'Mymodule';

  $m_path = variable_get('mymodule_path', 'mymodule');
  $m_path = $m_path ? $m_path : 'mymodule';

  $items[$m_path] = array(
      'title' => $m_title,
      'page callback' => '_mymodule_page',
      'access arguments' => array('access mymodule content'),
      'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

/**
 * Page callback: mymodule settings
 *
 * @see mymodule_menu()
 */
function mymodule_form($form, &$form_state) {
  $form['mymodule_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title displayed on the mymodule public page'),
    '#default_value' => variable_get('mymodule_title', 'Mymodule'),
    '#required' => TRUE,
  );
  $form['mymodule_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path for the mymodule public page'),
    '#default_value' => variable_get('mymodule_path', 'mymodule'),
    '#required' => TRUE,
  );
  $form['#submit'][] = 'mymodule_form_submit';

  return system_settings_form($form);
}

/**
 * Add a submit handler/function to the form.
 */
function mymodule_form_submit($form, &$form_state) {
  drupal_set_message(t('TEST: The form has been submitted.'));
  menu_rebuild();
}

/**
 * Implements validation from the Form API.
 *
 * @param $form
 *   A structured array containing the elements and properties of the form.
 * @param $form_state
 *   An array that stores information about the form's current state
 *   during processing.
 */
function mymodule_form_validate($form, &$form_state) {
  // page path validation
  $m_path = $form_state['values']['mymodule_path'];
  $m_path_db = variable_get('mymodule_path', '');
  if ($m_path_db != $m_path) {

    if (drupal_lookup_path('source', $m_path) || menu_get_item($m_path)) {
      form_set_error('mymodule_path', t('This path is already used.'));
    } else {

      // attempting to validate path value
      // see: http://drupal.stackexchange.com/questions/167923
      $m_path_parts = explode('/', $m_path);
      $has_invalid_chars = false;
      foreach ($m_path_parts as $key => $part) {
        if (urlencode($part) != $part) {
          $has_invalid_chars = true;
        }
      }
      if ($has_invalid_chars) {
        form_set_error('mymodule_path', t('This path contains invalid characters.'));
      }
    }
  }
}

?>

Edit: more code provided.


texts: How do I pass a variable from a custom module to its template file?

texts:
I need to know the simplest method to pass variable from custom module to its template file.
I have created the custom.module and placed custom.tpl.php in the module folder.

function custom_menu(){
  $items = array();

  $items['custom'] = array(
    'title' => t('custom!'),
    'page callback' => 'custom_page',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function custom_page() {

    $setVar = 'this is custom module';
    return theme('custom', $setVar);
}

i have added theme function but it is not working, can any one suggest me what is wrong with this code

function theme_custom($arg) {
  return $arg['output'];
}

function custom_theme() {
  return array(
    'Bluemarine' => array(
        'variables' => 'output',
        'template' => 'Bluemarine',
     ),
  );
}


texts:
I add a simple text as view header but it is not exists in translatable text in admin/config/regional/translate.

In Drupal 7 we could even translate unformulated views header and footer with the following steps:

Go to admin/config/regional/i18n/strings
Check "full HTML" in "Translatable text formats" section
Go to admin/config/regional/translate/i18n_string
Click on Refresh strings

Has this feature been removed form Drupal 8? (I don't think so.)
How can I translate view header and footer simple text?


texts: I created a content type called "Automobile" and that has the following fields: "Model," "Manufacturer," and "Year." When I go to "Dashboard > Content > Find Content," the search does not offer me controls to "find all automobiles between the year 1990 and 1995 with the model Caravan."  How do I configure Drupal to allow such queries?


texts: Change form submit #access as a result of ajax callback

texts:
I have a form that requests some information first, then pre-populates other fields before a final submit.  I'm trying to change the #access value for the buttons on the form.  Both of the code snippets below come from the same form builder function.

Considering:

$form['actions'] = [
  'id_lookup' => [
    '#type' => 'submit',
    '#title' => 'Submit',
    '#value' => 'Lookup ID',
    '#ajax' => [
      'callback' => 'my_module_populate_id_info',
      'wrapper' => 'id_info',
      'method' => 'replace',
      'effect' => 'fade',
    ],
  ],
  'submit' => [
    '#type' => 'submit',
    '#title' => 'Submit',
    '#value' => 'Register for Event',
    '#access' => FALSE,
  ],
  '#weight' => 100
];

The above code provides two buttons, one which triggers the ajax callback (see below) and the other which will submit the final form.

The below code adds additional fields (they're all disabled) with information pre-populated.  Everything works as expected, I just want to change #access on id_lookup to false and on submit to true, it's not working.  I originally tried to just change the value, but I couldn't get that to work either.

if (!empty($form_state['values']['id'])) {
  $user_info = my_module_signup_get_id_info($form_state['values']['id']);
  $ldap_user = FALSE;
  $existing_user = FALSE;
  if (isset($user_info['ldap_user'])) {
    $ldap_user = TRUE;
    $first_name = $user_info['ldap_user']['givenname'][0];
    $last_name = $user_info['ldap_user']['sn'][0];
    $job_title = $user_info['ldap_user']['title'][0];
    $organization = $user_info['ldap_user']['department'][0];
    $email = $user_info['ldap_user']['mail'][0];

    $form['id_info']['first_name'] = [
      '#type' => 'textfield',
      '#title' => 'First Name',
      '#required' => TRUE,
      '#prefix' => '

',
      '#suffix' => '

',
      '#disabled' => TRUE,
      '#default_value' => $user_info['ldap_user']['givenname'][0],
  ];
  // ... some other fields
  // Try to change the #access on the actions
  $form['actions']['id_lookup']['#access'] = FALSE;
  $form['actions']['submit']['#access'] = TRUE;
} else {
  $form['id_info']['no_user'] = [
    '#type' => 'markup',
    '#markup' => '
No user was found for that ID
',
  ];
}

}

Everything works as expected except the access on those buttons - what am I doing wrong?


texts: Setup custom required field validation for a field in custom form

texts:
How can I setup custom required field validation message for a text field in my custom form. I tried below code. But it is not working. It always showing 'Please fill out this field'.

$form['first_name'] = [
  '#type' => 'textfield',
  '#title' => $this->t('First Name'),
  '#default_value' => $this->store->get('first_name') ? $this->store->get('first_name') : '',
  '#required_but_empty' => $this->t('Please enter First Name'),
  '#required' => TRUE,
];


texts: Can't get Varnish working properly, not caching anything. (varnishd is running , status is tick)

texts:
System info:

Ubuntu / LAMP
Drupal 7.14
Varnish 3.0.2
Varnish module: 7.x-1.0-beta1
http port 80

I have installed Varnish in server.

I started it as:

$ sudo varnishd -f default.vcl -s malloc,1G -T 127.0.0.1:2000

varnishd started and running.

default.vcl details (from this page: https://www.varnish-cache.org/trac/wiki/VarnishAndDrupal)

backend default {
    .host = "127.0.0.1";
    .port = "80";
}

sub vcl_recv {
  // Remove has_js and Google Analytics __* cookies.
  set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+$
  // Remove a ";" prefix, if present.
  set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
  // Remove empty cookies.
  if (req.http.Cookie ~ "^\s*$") {
    unset req.http.Cookie;
  }

  // Cache all requests by default, overriding the
  // standard Varnish behavior.
  // if (req.request == "GET" || req.request == "HEAD") {
  //   return (lookup);
  // }
}

sub vcl_hash {
  if (req.http.Cookie) {
    hash_data(req.http.Cookie);
    return (hash);
  }
}

Vanish module enabled.

Following conf added to settings.php

$conf['cache_backends'][] = 'sites/all/modules/varnish/varnish.cache.inc';
$conf['cache_class_cache_page'] = 'VarnishCache';
$conf['page_cache_invoke_hooks'] = FALSE;

Varnish module configuration page screenshot:

Performance page screenshot:

Then I browse my site. (as anonymous), repeatedly refresh various pages. Checked stats of varnish

$ varnishtop

apparently it is not receiving any request, not caching anything.

Also check the site on http://www.isvarnishworking.com/  , shows Vanish is not working on the site.

What is wrong?

Thanks for any help.


texts: Customise Recent Content block to show only 1 content type

texts:
I need to customise the 'Recent Content' block to show only 1 content type (i.e pages or articles).

This doesn't seem to be possible with the block settings so I presume that I need to clone and/or edit this block to restrict the content it shows?


texts: How to access rules condition values in the rule event?

texts:
I have created a rule (using Rules) in which I added 3 conditons. Now I want to access the conditions values in the action that on which condition the action is performed.

I am attaching the screenshot :

As shown in the screenshot, I want to access

[commerce-license:type], Data value: Diamond Subscription

How can I achieve this ?


texts:
I'm using Drupal 7. Is there a hook for generating image from image style?
For example. I upload an image. When image is displayed for the first time, drupal generates image style. Can I hook to that event somehow?


texts:
The Drupal 7 documentation introduces the Batch API as:

  Functions allowing forms processing to be spread out over several page
  requests, thus ensuring that the processing does not get interrupted
  because of a PHP timeout...

I took this to mean that Batch handles the timeout-related issues for the developer.

However, other posts (ie. How does the batch API work internally?)
imply that it is the developer's responsibility to tell Batch how much work to do before waiting for another user to arrive and Batch to be invoked again --- thereby avoiding the timeout.

If the latter is true then I assume Batch does not guarantee that jobs won't be timed out. Does Batch provide any guarantees? Is it up to the developer to guess how much Batch can process before timing out?

Thank you!


texts: Drupal Commerce: How to handle billions of product combinations?

texts: I was just reading the last chapter of Using Drupal which treats Drupal Commerce and there it says that every product has to have a unique ID but these products can be grouped by product displays. Like when you have a T-Shirt in 10 colors and 4 sizes that's 40 products that can be organized by a single product display. But I have a physical product which has several regions and every region can have one of several thousand designs (different colors, patterns,...). This means billions or even trillions of combinations and I can hardly create a product for every one of those. How do I solve this problem?


texts:
May you give me few hints on how to enable adding 1 optional image to each blog entry?

I've enabled Blog and Image modules and registered users can create and comment on them.

What is the next step?


texts:
I want to disable the form redirect.

$form['#redirect'] = FALSE;
$form_state['#redirect'] = FALSE;

Neither of those works.

How can I turn off form redirect? I want to see the output of $form_values.


texts: Views entity reference depending on other field in contact form

texts:
I have almost the same problem than Peter, here: Entity reference view depending on other field
I have a contact form with two fields: brand and model. Brand is a taxonomy field and Model en entity reference view field. Model field (autocomplete) should be dependent on brand value: nothing if brand is not selected or only products with the brand field chosen.
I think @Francis Yaconiello gave the right answer but I don't understand the relations and contextual filter in his view. If you see this, Francis, can you help me?
Anyone?
Thank you


texts: Snippet to hide the editing of one vocab

texts: I need a snippet that hides/omits the editing of a certain vocab on the node/edit form of a certain content type if they are not in a certain role.  All the access modules are too heavy for just this small requirement.


texts: Hide taxonomy terms when using Taxonomy Access Control Lite

texts:
I'm using the Taxonomy Access Control Lite module to make certain pages/nodes visible only to people with certain roles.  That's working fine.

However, a side effect seems to be that now at the bottom of each node, the tagging I'm using for marking nodes as Private/Public is shown to the user.  My taxonomy is called "Access Level", so the bottom of each page now says either "Access Level: Private" or "Access Level: Public".

What's a good way to hide those?  I feel like it probably has something to do with the "Visibility" checkbox, but I don't really understand what that box is saying.


texts: Combining contextual filters for direct and indirect relationships

texts:
We are trying to create a single view with multiple contextual filters.
The goal is to display the content of type Alice related to content of type Bob.

The reference is set on type Alice using a direct entity reference to type Bob or via a shared taxonomy Charlie.

Hence, the setup is as follows:

(1) Alice (Node) -enity reference-> Bob (Node)

(2) Alice (Node) -enity reference-> Charlie (Term) <-enity reference- Bob (Node)

What we would like to achieve is to combine the direct relationsship (1) using the reference field as well as the indirect relationship (2) using the common taxonomy within one view and display all results matching any relationship.

So far we've tried making it work with Content: ID + Content: Has taxonomy term ID combined with the Content: Bob contextual filter.

We also added Views Contextual Filters OR to implemented this behavior, but this breaks the Content: ID + Content: Has taxonomy term ID combination.

Is there a way to set this up using contextual filters or is it easier to use hook_views_* and filters for this?


texts: After adding data to nodes using hook_node_load(), will this data be saved in the cache?

texts:
When using hook_load() or hook_node_load() to add information to the node object, is it possible to have this data stored in the cache? I'd like to add several different pieces of data and it would be difficult / impossible to get this data in one database query, however, if it's caching the data with the rest of the node object, it should be fine. How do I do this if it doesn't already?

thanks!


texts:
I want to force admin pages open only and only in overlay. As you know if a link with an admin path is clicked it opens in overlay (if enabled). But if you write the URL to the browser, or use some deep link, or you are already in administration theme, the links expectedly wouldn't open in overlay.

How could I force the pages, even if the URL is entered to the browser's path, to open in overlay.

For example, if I type in the browser:

  www.example.com/admin/people

It should always open as:

  www.example.com/#overlay=admin/people


texts: Alter Commerce Line Item Order Edit Form

texts:
I would like to add a column on the line item table on the orders edit page. I've tried to use theme_registry_alter($theme_registry) to override the commerce line item theme_commerce_line_item_manager, but it seems like it's not working. Below is my code:-

function MODULE_theme_registry_alter($theme_registry) {
  if (isset($theme_registry['commerce_line_item_manager'])) {
    $theme_registry['commerce_line_item_manager']['theme path'] = drupal_get_path('module', 'MODULE');
    $theme_registry['commerce_line_item_manager']['function'] = 'MODULE_commerce_line_item_manager';
  }
}

function MODULE_commerce_line_item_manager(&$variables) {
  return 'Print something';
}

Am I missing something? Or is there any other way to alter the display or add a new column on the table?

I've also created a patch, but I don't feel it's the solution to alter the display. Please help. Thank you in advance.


texts:
I've created a facet block according to this example Programatically render a block in a twig template

I've created the facet block as follows:

$variables['block_output'] = Drupal::service('plugin.manager.block')->createInstance("facet_block:topic")->build();

That works great, but I'm missing the block template itself on my page (the block around the facet links output). I need a custom suggestion for this block to format it. Unfortunately, the hook_theme_suggestions_alter() doesn't detect this block. How can I add a file name suggestion?

Thank you!


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

texts:
I used CDN option while creating my sub-theme. I find less and sass things pretty confusing since I am someone who haven't mastered the css yet. What I have found out so far is:

I can edit some styling copying some css lines from "/libraries/bootstrap/css/bootstrap-theme.css" to "subtheme/css/style.css" file.

What I want to do is to remove / disable / hide the file size information which shows up next to the file link which is the product of 'file-field' of Drupal. This is viewed using bootstrap's table styling / template or whatsoever you call it.
Is this something that should be accomplished using css or it is a template file or maybe it can only be modified in module?


texts: Programatically save comma-separated string as value of taxonomy field

texts:
I have a comma-separated string $string of the form "term1,term2,term3" and I would like to save it as the value of a taxonomy term field that is attached to my node. I have tried
$node->field_taxonomy[LANGUAGE_NONE][0]['value'] = $string;
node_save($node); but this throws me an error "Warning: Illegal string offset 'tid' in taxonomy_field_presave()" coming from Taxonomy module.

What is the correct way to set the value of $node->field_taxonomy?

I also need that when node_save($node); is executed, taxonomy terms that had not been taxonomy terms before are created, just like it would happen when I set the value of $node->field_taxonomy via the user interface. I was expecting this to happen automatically when I set and save the taxonomy field value.

Edit: Actually, I am trying to attach taxonomy terms to files, but I thought that the analogous setup of nodes would be more familiar to most people.

I have attached a description field (field_description) and a taxonomy field (field_hashtags) to files via the user interface, using File Entity Module. I now want to upload files and fill in their attached fields using a custom file upload form, but on the custom file upload form there is only

a field for the file itself ($form['file'] of type managed_file) and
a field for the description that the file should be given ($form['description'] of type textarea).

My CUSTOMMODDULE_form_submit() function now defines $submitted_file = file_load($form_state['values']['file']);, i.e. as the submitted file, and $submitted_description = $form_state['values']['description'];, i.e. as the submitted description.

It then sets $submitted_file->field_description[LANGUAGE_NONE][0]['value'] = $submitted_description; and, as expected, when saving the file via file_save($submitted_file); the description field of the file is saved being populated with the submitted values.

However, before saving the file I run a custom function that returns a comma-separated string of hashtags (all words from the submitted description that start with '#') that were used in the description. I now want to set $submitted_file->field_hashtags as exactly those terms from the string that my custom function returns, just like I would enter a comma-separated string into a taxonomy field by hand from the user interface.

Edit 2: I further tried the following code from taxonomy.module

$terms = explode(',', $string);
$voc = taxonomy_vocabulary_machine_name_load('vocabulary_name');
$vid = $voc->vid;

foreach ($terms as $key => $term) {
  if ($possibilities = taxonomy_term_load_multiple(array(), array('name' => trim($term), 'vid' => $vid))) {
            $term = array_pop($possibilities);
        }
        else {
        $term = array(
          'tid' => 'autocreate',
          'vid' => $vid,
          'name' => $term,
          'vocabulary_machine_name' => 'vocabulary_name',
        );
        }

        $term_array = (array) $term;
        $node->field_taxonomy[LANGUAGE_NONE]['$key'] = $term_array;
    }

but this gives me "Error
Error message
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '$key' for column 'delta' at row 1:"


texts: User Locked out after 5 failed login attempts - how to help him?

texts:
I have a user with 5 failed login attempts...and now he's locked out. We reset his password...but is there something else we need to do to unlock his account on a basic Drupal 8 setup?

I'd rather not have to get into using drush on this remote server and messing around with db tables...especially since this is just one user out of thousands. I just want a simple UI solution.

Or does he have to wait 6 hours or something crazy?


texts: How to check if this page is user Profile Page

texts:
I made a custom User Panel which is similar to Wordpress Top Panel in page.tpl.php so this panel will be shown for every logged-in users on the top of their page. But I want to hide that panel in user-profile.tpl.php but, not sure is there any function like is_profile() or something like that so I can check for a profile page and when the statement is true then hide the custom User Panel on user-profile.tpl.php.

Note that my d7 site has its custom user profile page.

Any idea? Thanks


texts: HTML5 Video showing both Source and Flash fallback

texts:
I'm experiencing a sudden problem with an embedded HTML5 video on my Drupal site. At first I thought it was a problem with my HTML5 code, but I believe the problem is with the WYSIWYG editor within Drupal.

I have a video in several formats, and want have a Flash fallback for those less fortunate.

Here is my code:

 <video width="480" height="320" controls="controls" poster="poster.png">
    <source src="video.webm" type="video/webm" />
    <source src="video.mp4" type="video/mp4" />
    <source src="video.ogv" type="video/ogg" />

    <object width="480" height="320"
            data="moxieplayer.swf" type="application/x-shockwave-flash">
       <param name="src" value="moxieplayer.swf" />
       <param name="flashvars" value="url=video.mp4&amp;poster=poster.png" />
       <param name="allowfullscreen" value="true" />
       <param name="allowscriptaccess" value="true" />
    </object>
 </video>

Everything was working as expected. Then I opened the WYSIWYG editor, Disabled rich-text to get to the HTML, and added the "poster" attribute. I clicked save and, ever since, it has been showing TWO videos: the main source and the Flash fallback.

I found that odd so I removed the poster attribute (going back to what I had before), but the problem remained.

I know what the problem is... It became apparent when I viewed the source in the browser. The source is being rendered like this:

<video width="480" height="320" controls="controls" poster="poster.png">

      <source src="video.webm" type="video/webm"></source>

      <source src="video.mp4" type="video/mp4"></source>

      <source src="video.ogv" type="video/ogg"></source>
    </video>

  <object width="480" height="320" data="moxieplayer.swf" type="application/x-shockwave-flash">
     <param name="src" value="moxieplayer.swf" />
     <param name="flashvars" value="url=video.mp4&amp;poster=/" />
    <param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="true" />
 </object>

Notice that in the rendered code, "object" is now outside the video tag. I'm guessing that's the problem. For whatever reason it was fine, then I edited the code to add the poster, and rocking the boat has resulted in this issue. I am in "Full HTML" mode when making my edits.

Unfortunately, disabling WYSISWG isn't an option as my customer needs to use it. This is a bit frustrating as I suspect that may be the issue. I'm using TinyMCE 3.5.10.

Does anyone have any suggestions on how to deal with this problem?

Thank you very much!


texts: Redirect to profile2 page after adding user based on roles?

texts:
I'm using rules and trying to get this workflow.

Site administrator adds new user -> redirected to the user's profile page to fill out information about the user.

I'm using the page redirect action to redirect to the profile2 edit page for the newly created user which works great. But I can't get this rule to trigger only for site administrators.

I've tried using data comparison [ roles= site administrator ] and user roles equals site administrator but neither work.

The idea is that the site administrators can add new users and fill out their profiles immediately.


texts: D7: Change Drupal "Link" field to store node url instead of alias for internal links

texts:
I am using the "Link" field in Drupal 7 to store links. Sometimes these links are internal and sometimes they are external. In the case of internal links, I would like to be able to store the system URL ("node/371") instead of an alias ("about/mission-statement") so that the link field will auto-correct itself when someone changes the URL alias.

Entity Reference is great for keeping track of internal nodes, but I would like the same field instance to handle both internal and external links.

Advanced Link doesn't seem to do this processing either.

Is there another module I should use, or a hook I can use to intercept the link field processing pre-storage?

EDIT

I was able to hack the module to get the behavior I wanted by adding two lines of code to _link_process :

$systemPath = drupal_lookup_path('source',$item['url']);
$item['url'] = ($systemPath) ? $systemPath : $item['url'];

… although it would be nice to be able to do this in a way that preserves an upgrade path.


texts: Problem in admin login, showing blank page in drupal 7?

texts:
Problem in login admin part.

Whenever I try to click on login link or try to login directly from homepage. It shows white screen. Which type of problem is this. I can't see the error logs due to problem in admin login.

Is this issue due to low server space ?


texts: Show specific fields in a list to everybody, but only registered user can see that node

texts:
My Drupal version is 7.50.

I want to show to anonymous user a list with a specific fields (title, image, body abstract), but when you click in title, the content of that node would only be available to registred users.

I tried combining Views to make that list with "Node Access" to limit access to node... but I'm lost. Surely, I'm doing something wrong.

Any suggestion about it? Thanx!


texts:
I would like to build a render array, where the children html is wrapped in a link element.

I am looking for something similar to '#type' => 'container' to achieve this. So it would translate to e.g. '#theme_wrappers' => ['link_wrapper'].

E.g. like this:

$link_element = [
  '#type' => 'link_wrapper',
  '#url' => $url
  'content' => $inner_element,
];

The resulting html would be something like this:

Inner content

The important thing here is that the contents should be a render array, and not merely a '#title' property. This also means I don't want any filtering and escaping. The content, once rendered, should be treated as html.

In Drupal 7, I wrote my own element type and theme wrapper for this, themekit_link_wrapper.

For Drupal 8, I am wondering if something like this already exists.

Or if not, how I would port my D7 'themekit_link_wrapper' to Drupal 8.
(In the end I might answer this myself)


texts: View that shows all children content of parent

texts:
Been searching and cannot find this anywhere for Drupal 8. Very basic view request, can't figure out why it's not straightforward.

I want a View that shows Parent content and under it all Children content. Nothing to do with taxonomy, just want this to display in a view:

Parent Content 1
 - Child content 1
 - Child content 2
 - Child content 3

When trying a contextual filter, I get "This display does not have a source for contextual filters, so no contextual filter value will be available unless you select 'Provide default'."


texts: Rules scheduled email empty when using php variable, but not when hardcoded

texts:
I'm using rules scheduler (on D7) to set up a reminder email based on a time specified within a commerce order (more specifically a line item in the order). I was able to get everything set up correctly using these instructions, so that the email is scheduled and send out. However, I am having a problem with the actual content of the email appearing correctly.

Just to clarify the rule setup, the flow is

Line item is updated
Rules scheduler schedules a component to run based on line item's date field
When the scheduled time is hit, the component is triggered

A view that serves the list of users is loaded
Component loops through list of users in the view

Email is sent to each user

The content of the email is defined by another view, which I am embedding using:

<?php
$id = $line_item->line_item_id;
print views_embed_view('commerce_checkout_page_for_email_embed', 'block_4', $id);
?>

The $id above is used to pass the line item's ID into the view to filter results by the current line item.

In my testing, when triggering the component directly on Line Item Update instead of at a scheduled time, everything works perfectly. The email is sent, and the body of the email contains the proper view filtered by the current line item.

However, when the email is sent by rules scheduler, the body of the email is empty. When I hard code $id ($id=1776 instead of $id = $line_item->line_item_id) the body of the email is exactly as it is supposed to be. I can only assume that this means that for some reason, the scheduled rule is not able to access the variable I'm passing to it. I also tried passing the token for the line item id, but you cannot pass token in PHP, so that was a bust.

Does anybody know why this might be, or have any suggestions?


texts: Creating folders for images using Tokens module

texts:
I have a node for a photo. I want to know what is the best why to define the file path for the images. The images will be user submitted.

Ideally, I would have liked the path be sites/default/files/photo/[node-reference:NID] so that each node would have all the image nodes associated with it in their own folder. This would make it easier to migrate the images since not only in the database but also in the file system would describe which images belong to which. Because the referenced node isn't available for the Tokens module I need to come up with a different strategy.

I have considered things like user sites/default/files/photo to dump all the images into one folder which might become a mess over time or sites/default/files/photo/[user id] so that each user's images are in separate containers. I don't know what the benefit of that would be.

I'm also thinking about creating a name convention for each image to that it has the node reference NID and user name in code. Is it worth the effort?

I'm looking at the image scr attributes on websites like grammy.com and examiner.com to see how they set it up. It looks like the examiner.com uses a hash to name the image.

Does anybody have any ideas on how to do this?


texts: Does the Drupal FAPI support more than one AJAX callback?

texts:
I am using FAPI's AJAX property to save nodes asynchronously. When the associated AJAX callback gets called, it gets passed the $form and $form_state parameters respectively. I then simply call drupal_render($form) from the AJAX callback and voilá, the node edit page is refreshed asynchronously. This works well.

The problem that I am having is that I am only replacing the form, but I also want to replace the page title. The page title is not part of the node edit form; so I could change the node title on the edit form, but the page title would remain stale when saving and refreshing the form (note: the edited title does get saved into the db). I cannot target an element sitting higher in the DOM hierarchy because (ie, by changing pointing the wrapper to the body) because the AJAX callback is only aware of the form's contents.

drupal_render($form) works great, but I have the fear that if I where to point the wrapper to the body (or somewhere near it) and render the whole page, that this would have unintended consequences (such as skipping certain rendering steps, resulting in incomplete DOM data). That's why I thought of maybe adding a second AJAX callback to the form submit action: one for handling the form itself, another AJAX callback for handling the page title. Do you know if having more than one callback is possible? Can you think of a way of targeting two separate wrappers using FAPI's AJAX? Do you know if the path (instead of callback) property provides a solution for my problem? If path does work feel free to augment your answer with a short example.

Please limit answers to functionality supported by Drupal core. I am not interested in third-party modules that use their own javascript logic (ie, ctools, etc).

Sample code:

// Add ajaxified save button in hook_form_FORM_ID_alter (foo_form_node_form_alter).
$form['actions']['ajax_save']['#type'] = 'submit';
$form['actions']['ajax_save']['#access'] = TRUE;
$form['actions']['ajax_save']['#value'] = 'Save';
$form['actions']['ajax_save']['#submit'] = array(0 => 'foo_node_form_submit');
$form['actions']['ajax_save']['#weight'] = 9;

$form['actions']['ajax_save']['#ajax'] = array(
  'wrapper' => $form['#node']->type. '-node-form',
  'callback' => 'foo_ajax_callback',
  'method' => 'replace',
    'effect' => 'fade',
);

...

function foo_ajax_callback(&$form, &$form_state = null) {

  $commands = array('#type' => 'ajax', '#error' => FALSE, '#commands' => array());
  $output = drupal_render($form);
  $commands['#commands'][] = ajax_command_insert(NULL, $output);
  // Prepend status messages to the node form.
  $commands['#commands'][] = ajax_command_prepend(NULL, theme('status_messages'));
  // Update the title on the page.
  $commands['#commands'][] = ajax_command_insert(NULL, $output);

return $commands;
}


texts: Item pagination - fatal error: allowed memory exhausted

texts:
I have an $items array that I was displaying with my template file. Now I want to add a pagination, therefore the code looks like this:

    $current_page = pager_default_initialize(count($items), 4);
    $chunks = array_chunk($items, 4, TRUE);

    return theme('activit_item_list_block', array('title' => $title, 'subtitle' => $subtitle, 'items' => $chunks[$current_page])).
           theme('pager', array('quantity', count($items)));

but now im getting error:

  Fatal error: Allowed memory size of 1342177280 bytes exhausted (tried to allocate 40961 bytes) in C:\xampp\htdocs\grantexpert\includes\theme.inc on line 1514

Can't find out what I'm doing wrong, the code is identical with few examples that i found on internet. There is only 5 items in $items array.

activit_item_list_block:

    <?php $countinrow = 0; $itemcount = count($items); $counter = 0; ?>

<?php echo rip_tags($subtitle); ?>

                <?php foreach($items as $item) { ?><?php $countinrow++; $counter++; if ($countinrow==1) { ?>
<?php } ?>

<?php echo $item['title']; ?>

                                    <?php echo $item['text']; ?>

                            <a class="button btn-small" href="/<?php echo $item['link']; ?>">Viac informácií

<?php if ($countinrow==4 || $counter==$itemcount) { $countinrow = 0; ?>
<?php } ?>


texts: Paragraph items are only available to their parent entities. But is there any known way to make it possible to re-use existing Paragraph items?


texts: Get single field valure from node object

texts:
I have loaded a node object in my module, I want to get the single value entered for a specific field (a text field).

I can access it directly with $node->field_position['und'][0]['safe_value'].

Is there a better way to do this? I have looked at field_get_items and field_view_value but I dont want a renderable array or an array at all. Isn't there a way to just return the string value? Having

$items = field_get_items('node', $node, 'field_position');
$position = $items[0][safe_value];

just seems like additional code that doesnt make it any simpler


texts:
I created a module containing the following files:

menu_imoveis.info
menu_imoveis.module

The content of menu_imoveis.info is the following.

    name = Menu Imoveis
    description = Adiciona imoveis ao menu.
    package = Imoveis
    core = 7.x
    version = 7.x-dev

    files[] = menu_imoveis.module

**The content of menu_imoveis.module is the following.

function menu_imoveis_menu() {
  $items['node/27'] = array(
    'title' => 'Example Page',
    'menu_name' => 'main-menu',
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

The code I wrote doesn't work.


texts: Image gallery as a field, not a content type?

texts:
Tutorials I've found seem to only cover creating Image Gallery content types. Any suggestions on how to make an image gallery as a field, rather than as a content type?

Ideally, I'd like to have something similar to the Photoswipe responsive galleries, but with captions, and appearing inside another content type, be it an article, basic page or in this case a new content type.

Perhaps there's simply something I'm missing about embedding one content type within another?


texts: Is there a module for "mail routing" in Drupal 6?

texts:
Is there a module, with D6 support, that allows one to "route" e-mails.

For example, by default, e-mails would be sent out by the regular mechanism, but for some e-mails, say based on their ID or destination domain, where tracking is interesting, they could instead be passed of to a third party service (such as MailChimp, ExactTarget, MailGun etc).


texts:
I am trying to hide node "edit" tab for certain content types and roles without removing or disabling access to the edit pages. An edit button is going to be created manually and displayed on node pages.

Used below snippet but it disables access to the edit pages too.

/**
* Set up a new permission for tabs.
* Grant access under admin -> user management -> permissions
*/
function mymodule_permission() {
  return array(
    'view hidden tabs' => array(
      'title' => t('Node tabs visibility'),
      'description' => t('Grant access to node tabs.'),
    ),
  );
}

/**
* Implementation of hook_menu_alter().
* Show/hide tabs according to permission settings.
*/
function mymodule_menu_alter(&$items) {
$items['node/%node/edit']['access callback'] = 'user_access';
$items['node/%node/edit']['access arguments'] = array('view hidden tabs');
}

Also tried using this code, which kinda works but disables edit tab on all content types and for all roles.

function mymodule_menu_alter(&$items) {
$items['node/%node/edit']['type'] = MENU_CALLBACK;
}

Obejective: Hide node "edit" tab for certain content types and roles in D7.


texts: Why do modules run multiple times on a single page load?

texts:
In Drupal 7 created a module which implemented hook_init().

I put an error log message as the first line of the function.

function my_module_init() {
  error_log('running init');
}

On each page load of the site I see the error message multiple times. I was expecting hook_init() to be ran exactly once per page load. Why is it running multiple times?


texts: Display file description in view using Download Count

texts:
I have created a view to display my most download files on the site and allow users to download them, to do this I am using the download_file and download_count modules.

The view should display a list of the most download attachment files on the site, I need to display the file name, a download link and then the file description.

When I try to insert the file description into the view I start running into problems, I am doing this by adding the field_attachments field (which is the field inside of my content type that the files are entered into).

When I add field_attachments all of the files associated with a files related node are displayed in the result, instead of what I expect which is just the single description for that file per row. This is probably an issue with relationships, does anyone know of a way to solve this?


texts: Add checkbox setting to a multiple value field

texts:
I have an image field with unlimited values. I want to add a checkbox to each image to use this image on the homepage. I would then check for that value in tpl file. How do I add a checkbox setting to this field?

Looks like a user did it in this post but didn't state how: Add a configuration checkbox in field setting


texts: Node form elements don't work when inserted with Panels. Am I missing something?

texts:
What I have done:

Created a Panels variant for viewing a node.
Added a Context relationship to the node edit form.
Added a form element with the relationship.
Added the node save button with the relationship.
Verified that I can see and interact with the widget and buttons.

What I expected:
 - Updating the field widget and then pressing "save" would save the node with the new value set by the widget

What I experienced:
 - Pressing "save" after entering a value in the widget didn't seem to do anything but reload the page on one of my content types.
 - On another content type it works as expected.

I suspect that some of the vast amount of custom code on my site is breaking it somewhere, but I'm not experienced enough with Panels/Ctools to know where to start looking. The node save button still works fine for all content types from the node/nid/edit page.


texts:
I've got a form that submits via AJAX and in the callback I need to rebuild certain parts of the page to reflect the newly submitted data. One of these parts is the form, which I need to clear all user input values from so it's ready to use again.

$response = new AjaxResponse();

// Remove all user submitted values
$form_state->setValues( array() );
$form_state->setRebuild( TRUE );

// Build a new instance of the form
$form_object = \Drupal::service('class_resolver')->getInstanceFromDefinition('Drupal\tpl_project\Form\MultiContactForm');
$form_object->setCompany( $company );
$replacement_form = \Drupal::formBuilder()->buildForm( $form_object, $form_state );

// Replace the old form with the new one
$response->addCommand(new HTMLCommand('.form-container', $replacement_form));

return $response;

When the form is submitted it runs the validation callback, the submit handler, then calls the above ajax handler. When it rebuilds the form in the above process, it fires the validation and submit handles again, thus storing two records.

How can I prevent this from happening and still rebuild the form to display no user input all within the same request?

Any help greatly appreciated.


texts: What WYSIWYG editor allows me to select styles from a dropdown 'out the box'?

texts:
I have installed the WYSIWYG module in Drupal 7 and have tried it with CKEditor and TinyMCE. I want users to pick styles from the template css when editing, but here appears to be a bug with the WYSIWYG module (drupal.org/node/1069356) that prevents the style dropdown from working. CKeditor seems to have a similar issue (drupal.org/node/746524), although there does seem to be a patch for this. I am not confident enough to deply the patch though.

Is there a WYSIWYG editor that is able to do this successfully out the box?


texts: Ahah helper alwas getting error, but on other page no error

texts:
I have forms with Ahah helper. When I tried to fill the form, it always getting this error:

warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'A' not found or invalid function name in xxx\includes\form.inc on line 378.

A = name of function, but that function is exist
xxx = location of drupal

Line 378 is:

$form = call_user_func_array(isset($callback) ? $callback : $form_id, $args);

At page_new_init, there is no error at all. But, at page_initedit there's always error. This is the .module code:

$items['new/init/1'] = array(
    'title' => 'Add new',
    'type' => MENU_LOCAL_TASK, //MENU_NORMAL_ITEM,
    'page callback' =>'page_new_init',
'access arguments' => array('new'),
);

$items['new/editinit'] = array(
    'title' => 'Edit',
    'type' => MENU_CALLBACK, //MENU_NORMAL_ITEM,
    'page callback' =>'page_initedit',
'access arguments' => array('new'),
'file' => 'act.edit.inc',
);

And this is the form on function "page_new_init":

function page_new_init(){
  global $user;

 $output .= drupal_get_form('form_new_add2',$id,$codeact);

  return $output;
}

function form_new_add2(){
  global $user;

    $form = array();
    ahah_helper_register($form, $form_state);
    drupal_add_js("sites/all/modules/act/javascript/jss.js");

    $form['input']['account'] = array(
    '#type' => 'textfield',
    '#title' => t('Account Code'),
    '#size' => 60,
    '#default_value' => $account,
    '#required' => TRUE,
    '#autocomplete_path' =>'compose/code',
    '#ahah' => array(
        'event'   => 'change',
        'path'    => ahah_helper_path(array('input')),
        'wrapper' => 'input-wrapper',
        'method' => 'replace',
        'progress' => 'throbber',
    ),

    $form['input']['access_code'] = array(
    '#type' => 'select',
    '#title' => t('Access Code'),
    //'#required' => TRUE,
    '#default_value' => $access_code,
    '#options' => opt_accesscode(),
    );

  return $output;
}

And this is the other function "page_initedit":

function page_initedit(){
  global $user;

 $output .= drupal_get_form('form_initedit',$id,$codeact);

  return $output;
}

function form_initedit(){
  global $user;

    $form = array();
    ahah_helper_register($form, $form_state);
    drupal_add_js("sites/all/modules/act/javascript/jss.js");

    $form['input']['account'] = array(
    '#type' => 'textfield',
    '#title' => t('Account Code'),
    '#size' => 60,
    '#default_value' => $account,
    '#required' => TRUE,
    '#autocomplete_path' =>'compose/code',
    '#ahah' => array(
        'event'   => 'change',
        'path'    => ahah_helper_path(array('input')),
        'wrapper' => 'input-wrapper',
        'method' => 'replace',
        'progress' => 'throbber',
    ),

    $form['input']['access_code'] = array(
    '#type' => 'select',
    '#title' => t('Access Code'),
    //'#required' => TRUE,
    '#default_value' => $access_code,
    '#options' => opt_accesscode(),
    );

  return $output;
}

On "page_new_init", there is no error at all, Ahah helper works fine. But on "page_initedit" the error comes up:

warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'form_initedit' not found or invalid function name in drupal\includes\form.inc on line 378.

What should I do?


texts: How to override paragraph remove button template? or Is there any way to alter the functionality of remove button provided by paragraph module?


texts: How to force D8 "Configuration synchronization" to send HTTPS download URL

texts:
I have a Drupal 8 site hosted on an Apache Server.
There are 2 virtuals hosts :

one listening on port 80, which redirects everything to HTTPS
one listening on port 443 which serves the htdocs directory where the Drupal site is located

Everything works well, except for the "Configuration synchronization" full export. When I click the "Export" button, I'm redirected to the home page, without any message or log.

Enabling the console on my web browser, I saw these calls :

POST https://my.domain.fr/admin/config/development/configuration/full/export
[HTTP/1.1 303 See Other 86 ms]
GET http://my.domain.fr/admin/config/development/configuration/full/export-download
[HTTP/1.1 301 Moved Permanently 101 ms]
GET https://my.domain.fr/
[HTTP/1.1 200 OK 183 ms]

The download process of the config file seems to be killed by the redirection.

The second URL (GET http) is sent by Drupal in the response to the first call, in the "Location" header.

How can I force Drupal to send only HTTPS url, even in the Location header in this precise case ?

Edit: Potentially linked post

Edit2: I'm having the same trouble with the RSS link on the site : on the page returned by https://my.domain.fr, the RSS link is http://my.domain.fr/rss.xml

Edit3: Found the solution for the export problem (see answer below). Still not a solution for the RSS link, but it's not the main subject of this post.


texts:
I am using views arguments for filtering jobs list.

I am taking state as argument.

Previously, state argument was accepting single value and it was filtering jobs correctly.

Now I made state field multivalued it means it accepts multiple states as input separated by comma.

here is my code for assigning arguments

$arg[0]=$filters['title_nodes'];
$arg[1]=$filters['company'];
$arg[2]=$filters['city'];
$arg[3]=$filters['state'];
$arg[4]=$filters['zip'];
$arg[5]=$filters['types'];
$arg[6]=$filters['categories'];
$arg[7]=$filters['industries'];
$arg[8]=$filters['beverages'];
$arg[9]=$filters['user'];

previously, $arg[3]=$filters['state']; this $arg[3] is filled with single state as New York etc. and for single value filter was working fine.

now, $arg[3]=$filters['state']; this argument is containing multiple states.

because of multiple states jobs are not getting filtered.

now suppose we entered 3 states, then in $arg[3]  3 states get stored and for each job,

argument checks whether there is any job who is having all 3 states in single job which is not possible.

Now how can I make this filter works for multiple states??

Thanks in advance.

any help will be appreciated.


texts: How do I hide the AJAX Cart block when cart is empty?

texts:
How can I hide Ubercart AJAX Cart block when the user's shopping cart is empty?

I know I could hide it with some jQuery tricks (for example, looking for the "cart-empty" class under my AJAX cart block (which has the class "block-uc_ajax_cart"), and hide the whole block if I found it), but this way I also would have to solve if cart is updated... Too messy.

I haven't found any opportunities to hide the block in this case under block settings, nor under the AJAX Cart Settings (http://<mysite>/admin/store/settings/uc_ajax_cart).

Thanks for your help in advance!


texts: Filtering referenced nodes where logged in user is a member

texts:
I am trying to set up a view of referenced nodes (entity reference field) of the current viewed (group)node.
So when a node is viewed i like to filter all the nodes that point to the current node.

Using the node id from url in contextual filter gives no problems.
So far so good.

However i like to only display those referenced nodes where the current logged in user is a member of.

Is this possible using views?


texts: How do you get the options from a select form?

texts:
As a follow-up to my last question regarding creating a dynamic select using JavaScript and the Forms API, I'm now wondering how do you actually get the options from that select list in a submit function. I've read "How to get All options of a 'select' field?" but I have yet to get it working with my code. Maybe because this person is using a CCK field and I'm using the Forms API which as far as I've read works differently. I've also tried pulling the data from the $form_state as well as the $form with no luck. Below is my code for a more complete picture of what I'm trying to do:

function _jstest_form($form, &$form_state) {
  $form['list'] = array(
    '#type' => 'select',
    '#options' => array('1', '2', '3'),
    '#size' => 4,
  );

  $form['text'] = array(
    '#type' => 'textfield',
  );

  $form['add_button'] = array (
    '#type' => 'button',
    '#value' => t("Add"),
    '#after_build' => array('_jstest_after_build'),
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
    '#submit' => array('_jstest_submit'),
    '#after_build' => array('_jstest_after_build'),
  );
  return $form;
}

function _jstest_submit($form, &$form_state) {
  //  Do stuff with options from select
}


texts: get user profile picture at registration

texts:
I am using Drupal 7.

I follow this link to enable profile picture of user.

Now i want to get profile picture from user at the time of registration.

How can i get this?

Any help will be appreciated.


texts: Custom validation for views exposed form using form alter

texts:
I want to add my custom validation to the views exposed filter form for that I have added below code in hook_form_alter

$form['#validate'][] = 'xxxx_custom_form_validate';

But its being called for form load also, is there any specific way to add custom validation function for views exposed filters form.


texts: Getting the value of a checkbox in form api

texts:
I'm creating a form using Drupal's form API.  This form includes about 50 or so checkboxes that I'm creating using the type 'checkbox'.  The checkboxes are grouped using several fieldset elements.  The checkbox is created from a look using an XML file that decides what checkboxes will appear.

$ageKey = '08';
$course = 'y';

$form['events'][$ageKey][$course] = array(
  '#type' => 'fieldset',
  '#title' => 'Set of checkboxes'
}

foreach($xCourse->event as $event) {
  $eventKey = (int)$event['distance'] .'-' . (int)$event['event'];
  $form['events'][$ageKey][$course][$ageKey . ' ' . $course . ' ' . $eventKey] = array(
    '#type' => 'checkbox',
    '#title' => (int)$event['distance'] . ' ' . $top5->dispStroke((int)$event['stroke']),
    '#default_value' => 1,
  );
}

I'm using hook_submit to process the form

function import_form_submit($form, &$form_state) {
  $checkboxes = $form_state['values'];

  //do stuff here
}

However, I find that the value for all my checkboxes is 0, regardless if the checkbox was unchecked by me or not.  If I remove '#default_value' => 1 from the checkbox definition, none of the checkboxes are checked by default.  The values array also appears to ignore the hierarchy I set up.

How do I get the checked state of the checkbox in my submission code? What am I missing here?


texts: Redirect after login from custom login block

texts:
I have added the login form to a page using drupal_get_form.
Now, I would like to redirect the users back to that page after login.
Note: I don't want to redirect users that logged in somewhere else (e.g. user/login), and I also don't want to use a contib module for that.

B.T.W
Maybe if I'll Ajaxify the login form it will have the same effect?

I'll appericiate any help and/or examples.

Thanks!


texts: Why do the facets display the wrong amount of results ?

texts:
I have two facets that are bound to the Content Type and the Publish Status of my content.

When I do simple keywords search, it works properly, the amount of result corresponds to the real results displayed.

However, when I use double quotes to narrow down the search, the search works as expected, but the amount of result is completely messed up.

The search yielded only one result, but the amount of result is not correct.

All the indexes were rebuilt, the caches were cleared, but the issue remains.
Where could this issue come from ?

I'm using Solr Version: 8.x-2.2 and Facets Version: 8.x-1.1


texts: Different menu links depending on user account

texts:
I need to create menu that has to be diffrent for each user.

/user/%username%
/user/%username%/purchases
etc.

Is there way to do something like that? Thanks


texts: How to build an Isolated Drupal instance for testing

texts:
In order to run DrupalWebTests on travis-ci, I need to build a new Drupal instance where these tests are ran.

Typically, one runs these tests with drush -l http://localhost.example test-run SomeTest

This, however, assumes Drupal installed, being served on http://localhost.example (a webserver) and it being connected to a database as set in settings.php, having simpletest enabled.

Typically, this means installing MySQL, Apache and installing and configuring Drupal. Those are heavy depedencies and doing so for each test-case or even just every build, will require a lot of overhead; a build server like Travis will need to install these servers for each test-run.

Drush has drush run-server to run a lightweight server. Drupal can run off a sqlite database, which would be extremely usefull for these tests.

Moreover: as far as I can make out, the actual web-tests are not ran from that Drupal-instance at http://localhost.example, but get a clean build and isolated database (as should be, when testing). It appears that the Fully-functional Drupal at http://localhost.example is merely used as bootstrap for the web-tests.

Can I circumvent that bootstrap in some way?

And if not, what is a quick and easy way to get a Drupal installed and serving with as little dependencies (like Apache/Nginx, MySQL etc) as possible?

Also note that I am running Travis already for tagadelic, but so far, only for the phpunit tests. I want to extend this to run the DrupalWebTests there as well.


texts:
I was wondering if there is any other way apart from coding (and, possibly, using the rules module) to make the showing of a field dependent on the existance of another field.
Say you have in a node, a video and a photo. You want to show only the video in teaser but if you have not provided a value for the video, then the video field should not be showing, and instead the photo field should be showing.
If you have provided a video, then the photo field should not be showing.
Any ideas?


texts: Anonymous user edited data as draft/revision in drupal 6

texts:
I have a problem(may be only for me).  My requirement is anonymous user or registered user if they like to make a modification in a node they should be permitted but the modifications made by them should be saved as draft until the admin approves them.

Please let me know how this can be achieved.


texts:
I am using the drupal_http_request method and It seems to work well. When I use it, I send by POST from site A, a return URL (which would be site C) to site B that I am directing drupal to go to. So site A goes to B, but returns to A at this point.

I noticed that if I give the die command (on site A) right after I use drupal_http_request my browser opens to site C instead of going right back to A. Would this happen even if site C was on the same domain as site A? Obviously this would not be the same exact location of A.

e.g. A = www.example.com/test and C = www.example.com/test2


texts: How can I export only one paragraph type, the fields, the form settings and the display settings?

texts:
Some days ago I've exported and imported a full configuration with drush cex and drush cim.
What are the steps to export 1 paragraph type including the fields, form settings, display settings etc ...
I'm using a multisite, so it would be great to copy them from one site to the other sites within the multisite.
Can I:

drush cex site 1
copy exported .yml files to other site in folder (sites/site1.multisite.com/files/config_HASH/sync)
Delete all .yml files except those needed for the import of my paragraph type?

I guess there are better methods to establish this?


texts: Using Memcache Effectively with Drupal 7 Multisite

texts:
I am setting a hit ratio of 55% on our memcache instance (v1.4.4) and am wondering what can be done to improve the hit ratio. We're in a multisite setup (30+ sites), with two load balanced web servers; there is an instance of memcached on each web server.

In the settings.php, I have:

$conf['memcache_servers'] = array(
         '11.22.33.44:11211' => 'default',
         '11.22.33.45:11211' => 'default',
      );
$conf['memcache_bins'] = array('cache' => 'default');
$conf['memcache_key_prefix'] = $_SERVER['SERVER_NAME'];

I am looking at using bins to improve hit ratio, but have come across some suggestions that the latest memcache module does this already, but I am unsure as the instructions with the module contain directions on setting up bins.

If bins are they way to go, how do you determine what (table?) needs to have its own bin? These are the cache tables that I have in my sites:

cache
cache_admin_menu (empty)
cache_block (empty)
cache_bootstrap
cache_field
cache_filter (empty)
cache_form (empty)
cache_image (empty)
cache_media_xml (empty)
cache_menu
cache_page (empty)
cache_path (empty)
cache_token (empty)
cache_update (empty)
cache_views
cache_views_data (empty)
ctools_css_cache (empty)
ctools_object_cache (empty)

In addition to bins, what else can I be doing to improve memcached usage?

Many thanks!


texts:
How do you group a list of nodes by the taxonomy term?

e.g.

Term 1
--- Node 1
--- Node 3
--- Node 7

Term 2
--- Node 6
--- Node 9
--- Node 12

I have tried creating a view with "Node" and "Taxonomy Term" as fields. I then enabled grouping, and grouped by the taxonomy term. Doing this outputs the following:

Term 1
--- Node 1
Term 1
--- Node 3
Term 1
--- Node 7
Term 2
--- Node 6
Term 2
--- Node 9
Term 2
--- Node 12

There is a Drupal 6 tutorial here that explains how to fix it, but it doesn't work under Drupal 7.

It seems like such a simple task, yet after many days of trying, I can't get it to work! I've found many threads of people asking the question, but no solutions (at lease a solution which doesn't involve installing taxonews).


texts: Auto populate a node add with values of another node

texts:
Is there any module that auto-populates the fields of a node/add form with the values of an already existing node? I would like to pass the node ID in the URL and get the form prepopulated with the values taken from that node.

I know it is possible to do; I am just wondering if someone has already done it in a module I could use.


texts: Content type with multiple users - create a view of all users that relate to content of that type

texts:
Suppose you have a content type called political party. Political parties can have members that are users. A user can be a member of multiple political parties.

I am trying to create a view where I list every user that is a member of a political party, and list them each only once. I don't need to see what party they are in, and this should just be a newest user sorted list of users that are listed in at least one political party's member field.

So these are the content types that need to be related:

party
   |-members (user reference list)
user

How would you construct a view for this using the views module? I am a little lost on how to tackle this.

(note: I am using political parties, but actual content type name is different. It just is easier to explain this way)


texts: How create a new variable according field value

texts:
Please I need a hand, I would like to create a new variable like the native "frontpage" variable. I have a content type called "Config", in this CT I have some boolean fields and I need check for this field values to print a view in my page.tpl

Something like this, my example field "display reviews block?", its may be set "yes" or "no". So, I need create a new variable "$display_reviews" according this value and print this in page.tpl:

<?php if (isset($display_reviews)): ?>
 <?php print views_embed_view('reviews', 'block'); ?>
<?php endif; ?>

Sincerly, I dont know how to do this, but i tried something like this:

function mytemplate_preprocess_page(&$variables) {
  if (isset($variables['node'])) {
    $n = $variables['node'];

    if ($variables['node']->type == 'config') {

        if (isset($n->field_display_reviews == 'yes') {
          $variables['display_reviews'] = 'this variable need be created';

        }
    }

 }
}

UPDATE

Considering I want to print this variable in my node.tpl not in my page.tpl, I have decided to try with directly query, I dont know if is the better and fast way, but this is my code. Its not working yet, this is broking my site, but now I can display the FIELD ID. Im trying to use the field_attach_load to get the field value but no luck:

/**
* Implementation of preprocess_().
*/
function mytemplate_preprocess_node(&$variables, $hook) {

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'config')
  ->propertyCondition('status', 1)
  // value 1 from boolean field
  ->fieldCondition('field_display_reviews','value', '1', '=');
$result = $query->execute();

if (isset($result['node'])) {
  $stories = $result['node'];

  $fields = field_info_instances('node', 'config');

  // Get id of field
  $reviews = $fields['field_display_reviews']['field_id'];
  field_attach_load('node', $stories, FIELD_LOAD_CURRENT, array('field_id' => $reviews));
  $output = field_get_items('node', $stories, 'field_display_reviews');

  $variables['display_reviews'] = $output;

}

}


texts: Theme Image Style for image located in module directory

texts:
Probably coming at this from too much of a Drupal 6 view point but...

How do I theme an image in a given image style when that image lives in a module folder?  This is driving me batty and I know I'm just missing something simple.

Here is some example code showing what I'm trying to do:

$file_uri = 'public://sites/all/modules/my_module/logo.jpg';
$data['logo'] = theme('image_style', array('style_name' => 'medium', 'path' => $file_uri));

Even if I use file_build_uri(), I end up with a path to a file that doesn't exist. If I move the image to the files directory and change the $file_uri to 'public://logo.jpg', it works just fine.

Do I need to copy the image to the files directory as part of the module code?  If so, isn't this ridiculous?

What am I missing?  Is there documentation on how to do something like this?  I've spent over an hour mining the Drupal documentation and came up completely dry.


texts: How to disable copy and paste in webform textarea?

texts:
Is there a way to disable pasting into a webform textarea field?

I've created a textarea field called: my_words and I want to forbid anyone from copying and pasting text into this field.


texts:
I want use drupal commerce's line items in the following case.

I have 3 Products. (Product A, Product B, Product C).
I want to add line items to these 3 different products. So Product A will have the following structure.
Product A -> Line Item A-1, Line Item A-2
Product B will have the structure as              ,
Product B -> Line Item B-1, Line Item B-2

Now, This is okay with me. But if I want to add line items to the first level of line items. How can it be possible ?

The case is,
If I want to add 2 Line items to Line Item A-1. So the Product A will have a final structure as,

                              Product A
                      ___________|____________
                     |                       |
                Line Item A-1           Line Item A-2
          ___________|____________
         |                       |
     Child Line Item A-1(i)   Child Line Item A-1(ii)

I hope I am able to tell you my problem. Please help me on this.


texts: How to pull active user name from drupal 6

texts: Is it possible to pull the active user name or active ldap user from my drupal site, and store this in a separate DB, as i would like to use it because the login limits who can access the site, but I want to know who is submitting x,y,z data into my forms? so at the top of the form maybe a field that pulls their username?


texts: How to fix broken file.module function 'file_ajax_progress' without hacking the core and patching after every update?

texts:
When site has enabled page cache and anonymous user tries to upload a file, he cannot see upload status progress. He see only message "Starting upload...". Bug was reported in June 2012, has a working patch and I have a question:

How to fix broken file.module function file_ajax_progress without hacking the core and patching after every update? Should I do some function override by custom module?

This is all working code together:

/**
 * Menu callback for upload progress.
 *
 * @param $key
 *   The unique key for this upload process.
 */
function file_ajax_progress($key) {
  $progress = array(
    'message' => t('Starting upload...'),
    'percentage' => -1,
  );

  $implementation = file_progress_implementation();
  if ($implementation == 'uploadprogress') {
    $status = uploadprogress_get_info($key);
    if (isset($status['bytes_uploaded']) && !empty($status['bytes_total'])) {
      $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($status['bytes_uploaded']), '@total' => format_size($status['bytes_total'])));
      $progress['percentage'] = round(100 * $status['bytes_uploaded'] / $status['bytes_total']);
    }
  }
  elseif ($implementation == 'apc') {
    $status = apc_fetch('upload_' . $key);
    if (isset($status['current']) && !empty($status['total'])) {
      $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($status['current']), '@total' => format_size($status['total'])));
      $progress['percentage'] = round(100 * $status['current'] / $status['total']);
    }
  }
  // Mark this page as being uncacheable.
  drupal_page_is_cacheable(FALSE);
  drupal_json_output($progress);
}