texts: Grant/restrict access according to node's author & moderation state

texts:
I'm trying to bypass some of the permissions set by Workbench Moderation, only under specific circumstances. For a specific content type, I need the users of a specific Role to be able to:
- View all Published nodes of that content type (this works fine as it is quite general)
- View Unpublished nodes only if the nodes 1. are related to them (through Entity Reference field) or 2. they have created themselves.
- Edit nodes only if they are related to them (through Entity Reference field) or nodes they have created themselves. This should be allowed only in a specific State.

I've tried implementing hook_node_access_records() & hook_node_grants() hooks in my module but this doesn't seem to work. In the following example, the conditionals are different than what's mentioned above but the logic is the same:

function mymodule_node_access_records($node){
    $grants = array();
    if ($node->nid == 1234 && $node->uid == 99) { //(example conditions)
        $grants[] = array(
            'realm' => 'mymodule',
            'gid' => 123,
            'grant_view' => 1,
            'grant_update' => 0,
            'grant_delete' => 0,
            'priority' => 0,
        );
    }
    return $grants;
}

function mymodule_node_grants($account, $op){
    $grants = array();
    if (($op == 'view' || $op == 'update') && $account->uid == 99) { //(example conditions)
        $grants['mymodule'] = array(
            123,
        );
    }
    return $grants;
}

This does add a line in node_access table where only grant_view has a value of 1. It should just allow related users to view the specific (unpublished) node but not edit it.

UPDATE: I installed Devel node access and here are my findings for the test case above (node 1234 is Unpublished, user 99 is author):

Test User can View the node - OK
Test User can Edit the unpublished node (non-Published draft) - NOT OK
Test User cannot Delete the node - OK
Test User can Moderate the Unpublished node (allowed transitions set by WM config.) - OK

Here is what Devel actually displays on that node's view page:

Create: YES: by node (permissions) - OK
View: YES: view own unpublished content - OK
Update: YES: by node (permissions) - This should be overridden by my access module
Delete: NO: no reason - OK

How can I override this edit permission with my module? I'd eventually like to expand the functionality of this module to cover other cases as well.


texts: How can I access the CiviCRM contact record 'group' value(s) of the current user?

texts:
The unique key is email address. Perhaps there is a CiviCRM API?

EDIT

There is a CiviCRM API. My code so far:

civicrm_initialize();
$content = civicrm_api('contact', 'getvalue', array(
  'email' => $GLOBALS['user']->mail,
  'version' => 3,
  'return' => 'first_name')
);

I need the user's group, not first name.


texts: How to create relationships between Taxonomy vocabularies?

texts:
I'm trying to build a site with similar content conventions to Craigslist. The problem is, I don't really know a good way to create multiple vocabulary relationships in drupal. Here's the end result I need:

Vocabs:
Locations
Categories (contains 'Goods' and 'Services')
Status

Content Type:
Item

  Relationships:

  User has many Items
  User has one Location
  Location has many Users
  Location has all Categories
  Item has many Categories
  Item has one Location

The end result is having all Locations be easy to navigate, with Items being appropriately displayed, in multiple Categories, but restricted to Locations. Users should also be redirected to their respective locations based on their assigned Location and should be able to create Items without having to manually stipulate the Location they are already in.

Does that make sense? Can this be done easily in Drupal?


texts: Should I source control contribed modules in my project?

texts:
I've been told that while developing I should source control everything under sites/ into my code repository (e.g SVN).

Assuming I'll never touch any of the contrib modules I use (ctools, views etc) but will only create my own theme, should I still do that?

Or should I just source control everything under sites/all/themes/?

thanks


texts: How can I achieve a mutli-level sort of a field that is being pulled in via a relationship from multiple content types in Views?

texts:
I have a content type called Session which uses the Inline Entity Form module to create/entity-reference three other content types: Material, Audio Archive, and Adobe Connect (AC) Archive.

In the view, I only want to show nodes from the Material, Audio Archive, and AC Archive content types. But I want to also show the Session node titles each of these nodes are related to.

There are four columns in this table view:

Date
Title (this is the title of the Material, Audio Archive, and AC Archive nodes)
Item Type (for Audio Archive and AC Archive, it shows the name of the content type; for Material, since that content type has several subtypes, it shows the name of the subtype -- if no content type is selected, it shows the name of the content type)
Title of Related Session (this is the title field of the Session content type that the other nodes are related to)

The title of the Session is showing up in the last column for each node, which is good (although I'm not sure how that was achieved as I inherited this project from a much more experienced developer).

I'm trying to resolve two related issues:

1) How do I do a multi-level sort in views?

I want to first sort by Date (descending), then by Title of Related Session (ascending), then by Title (ascending).

I want to achieve this regardless of content type/subtype.

2) Right now, if I want to sort by Date or by Title (as just a single-level sort), the sort is working properly. If I try to sort by Title of Related Session though, it's not working properly.

So if I try to sort by the Title of Related Session column, here's what happens:

Materials with a subtype selected gets sorted (I think this has to do with the fact that in the Fields section of views, Materials is listed last as there's some rewriting going on), and then after that, Audio Archive, AC Archive, and Materials with no subtype aren't getting sorted at all. I think figuring out how to even sort this at a single-level sort will make the multi-level sort work properly when I get to that (which is my true issue/solution I'm trying to achieve).

Also, I tried to re-create the relationship between, say, Session and Materials and Session and Audio Archive myself but when I try to add the relationship, I'm unable to see the Session content type at all so I'm very puzzled by that. Any help with that would be greatly appreciated too, thank you.

Please note that I'm not a developer so I'm unable to write any code and I unfortunately don't have access to one so any solution (if any) would need to configuration-based only.


texts: How to install required packages for feeds spreadsheet module as shown required by Composer Manager?

texts:
Modules being used
Composer Manager
Feeds Spreadsheet
Requirement

I need to install the package as mentioned in the configuration page of module composer manager.
The error shown is as given below.

Composer's install command must be run to generate the autoloader and install the required packages.
Refer to the instructions on the Composer Manager project page for installing packages.

I have access to Cpanel but don't have command line access right now, how can I install the required packages?


texts: How to add a page redirect in Drupal htaccess file or otherwise?

texts:
I've built a Drupal website to a replace an old website (not in Drupal) and some of the pages changed urls. I need to create redirects for those pages.

I've thought of using Drupal's .htaccess file and have the following:

RewriteCond %{HTTP_HOST} ^www.example.com/old-page-name$
RewriteRule ^$ http://www.example.com/new-page-name [L,R=301]

But that didn't work.

I've added those lines inside the redirect block in Drupal's htaccess:

<IfModule mod_rewrite.c>
</IfModule>

Just under these rules:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

This will be a temporary solution until I install the redirect or some other module.


texts: CKeditor doesn't work in controller response within a default theme

texts:
In a Drupal 8 project I've a controller which returns a form that contains a text_format field.

CKeditor is working perfectly in my administration theme (Stable), but it does not on the default theme.

I've tried to attach ckeditor core module libraries to the controller returned response with no results.

The role which I test with has permissions "Use simple HTML text format", "Use full HTML text format", also the role is checked on /admin/config/content/formats/manage/basic_html also on /admin/config/content/formats/manage/full_html.

my_module/src/Controller/MyController.php :

<?php

namespace Drupal\my_module\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\user\Entity\User;

/**
 * Provide user form.
 */
class MyController extends ControllerBase {

  /**
   * Return page content.
   */
  public function content() {
    // Load user edit form.
    $entity = User::load(\Drupal::currentUser()->id());
    $formObject = \Drupal::entityTypeManager()
      ->getFormObject('user', 'default')
      ->setEntity($entity);
    $form = \Drupal::formBuilder()->getForm($formObject);
    $render = \Drupal::service('renderer');
    $render_form = $render->renderPlain($form);
    return [
      '#theme' => 'customize_user_form',
      '#form' => $render_form,
      '#attached' => [
        // Attach ckeditor core module libraries.
        'library' => [
          'ckeditor/drupal.ckeditor',
          'ckeditor/drupal.ckeditor.stylescombo.admin',
          'ckeditor/drupal.ckeditor.admin',
          'ckeditor/drupal.ckeditor.plugins.drupalimagecaption',
        ],
      ],
    ];
  }

}

Results:

Any suggestions?

Many thanks.


texts: How to set up a contextual filter or child relationship?

texts:
Every now and then I'm re-attempting to set up a decent taxonomy explorer/browser. I have already managed to customize a tpl file for that (oh, I know, tpl should not contain advanced logic, some day I'll learn how to do that properly). Now I decided to give it a shot using Views. While I managed to set up a view for the top-level listing, now I'm trying to set up a decent lower-level browser.
I don't think it's possible, but maybe you will prove to me that it is.
My taxonomy has a very simple structure in that at a given level it has only branches or leaves, never are they mixed. Now, at some level (the depth is variable at different branches), the branches end and the leaves are to be listed. Therefore I'd thought this logic would be appropriate:

on page taxonomy/term/%
list items which
(a) belong to vocab X
and ((b1) are either children of parent with tid=%1
(b2) or are published nodes of content type Y with term tid=%1 assigned.)

For (b1) I have defined a parent term relationship and used it as a contextual filter. This alone works, but I don't know how to set up the b2 part. Can I re-use the same part of URL for another or'ed contextual filter. The '%1' string does not seem to work when entered in the filter section. What am I doing wrong?

Thanks.


texts:
Ajax facets work but I get an error "An error occured while attempting to process /ajax/ajax_facets/refresh:$.blockUI is not a function" when I click on ajax links with checkboxes for the facets for the first time.

I am using search api views as per mentioned in the project description
You can check the error in the screenshot attached


texts: Tabs not visible after creating view tabs

texts:
I am trying to create view tabs and follow below video

https://www.youtube.com/watch?v=hpuRdzyK3jI

but couldn't get any tabs displayed, only the results are displayed.

I am using Bootstrap Barrio sub theme.

I created a view with two pages

fun (Menu named as "Hot")
fun/fresh (Menu named as "Fresh")

When I access the url

http://localhost:8888/funnyplaceorg/web/fun

http://localhost:8888/funnyplaceorg/web/fun/fresh

I see the posts, but couldnt see the tabs.

Admin console for View pages

Edit

Added more images.


texts:
So I followed the instructions from this thread; Need a simple Google Maps solution; lost in the labyrinth of modules. I've gotten everything to work how I need it on my test server a few months ago. The SS below shows how it looks with the distance/proximity working.

Just before I got it working. I had a problem that the distance would not show based off the address or zip searched for. After some tinkering with views (atleast I think it was views), I finally got the distance working.

Now, my boss wants me to push it live and I can't remember how I got the distance to calculate based off an address or zipcode when I expose the proximity in views. It looks like the following;

I've opened both my test server and live side by side and checked over tons of the settings MANY MANY times over and still haven't been able to figure out what I missed. I've tried the following;

Refreshing the Proximity calculations via the openlayers/proximity tab
Tinkering with many different views settings.
Creating new test nodes
Rebuilding the process from the beginning

If you guys can maybe point me in the right direction or just mention SOMETHING that maybe I haven't thought about it would be great help. Thanks in advanced.


texts: Multistep information collection with reference to price addition or substraction

texts:
As I have posted previously, I was trying to built product kit with customization option. But there is no easy solution for that and diving into the coding using drupal commerce or ubercart need understanding of those module first.

So I reviewed the requirement again and saw, checkout is not required. I just have to declare the product kit & gather the information...

Have a look here on this link - Customize Your Laptop

I have to declare package like this. Where there would be default price for kit which will be sum of all default product. Every kind of product, there would some other option either in radio or checkbox and at time of going through step by step user can give their input and total price would change accordingly.

I will tell you the options which I have till now -

Webform (But the reference price change would be an issue)
Quiz (Same problem)
Form API (Client can't create package from them-self that is the main criteria behind this application)

Can I have some suggestion from someone, like what can be my roadmap or which module can help me with it by some tweaking or their API?


texts: Count of the number of nodes tagged with a particular status

texts:
I have a content type called promise whose node can be tagged with a status: not started, in progress, achieved, broken.

I wish to show a count for each of the above statuses in a view block. So say there are 100 promises, I want it to show the following.

90 of 100 promises are not started
2 of 100 promises are in progress
3 of 100 promises are achieved
5 of 100 promises are broken

How can I go about this? I know how to count a taxonomy term and show it has 2, 3 or 18 nodes tagged against it, but how to show out of 100?


texts: How to create a views tree and place at home page in drupal 7?

texts:
I want to create a forum using the Views Tree module, which I've installed/enabled. But I don't know how to create it as shown in image below and then place at home page. Here is a screenprint like I want to create:

Any suggestion on this?


texts: why does trying to add a line item on order presave redirect to the user page?

texts:
I have a lot more code than this in the hook_commerce_order_presave() however this

if ($show_charge_in_cart == True) {
  $product = commerce_product_load_by_sku("0909990000005");
  $line_item = commerce_product_line_item_new($product, $setup_fee_count, $order->order_id);
  commerce_line_item_save($line_item);
  //$order->commerce_line_items['und'][] = array('line_item_id' => $line_item->line_item_id);
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $order_wrapper->commerce_line_items[] = $line_item;
}

bit is failing and redirecting me to my user page specifically any combination of the last four lines whether I use the last 2 or the third from the end doesn't seem to matter and if I comment out the line_item_save it doesn't do it either.

To get back to the cart view I have to clear the caches (however checking the admin view I can see the setup fee was added to the order), then it will let me load the page once (and it shows the setup fee) continuing or updating the cart causes it to go back to the user page and will not let me back to the cart until I clear the caches again.

(edit)Added Full Code:

function edit_commerce_functionality_commerce_order_presave($order) {
  //dsm($order);
  $mouldings_in_order = False;
  if ($order->status == "cart" || $order->status == "checkout_checkout" || $order->status == "checkout_review") {
    foreach ($order->commerce_line_items['und'] as $unloaded_line_item) {
      $line_item = commerce_line_item_load($unloaded_line_item['line_item_id']);
      $product = commerce_product_load($line_item->commerce_product['und'][0]['product_id']);
      if ($product->type == "moulding") {
        $mouldings_in_order = True;
      }
    unset($product);
    unset($line_item);
    }
  }
  if ($mouldings_in_order == True) {
    foreach ($order->commerce_line_items['und'] as $unloaded_line_item) {
      $line_item = commerce_line_item_load($unloaded_line_item['line_item_id']);
      if ($line_item->line_item_label == "0909990000005") {
        commerce_cart_order_product_line_item_delete($order->order_id, $line_item->line_item_id, True);
      }
    }
    unset($line_item);

    $data = Array();
    $setup_fee_count = 0;
    $show_charge_in_cart = False;

    foreach ($order->commerce_line_items['und'] as $unloaded_line_item) {
      $line_item = commerce_line_item_load($unloaded_line_item['line_item_id']);
      $product = commerce_product_load($line_item->commerce_product['und'][0]['product_id']);
      $knumber = $product->field_knife_number['und'][0]['safe_value'];
      $line_item_price = $line_item->commerce_total['und'][0]['amount'] / 100;
      $made_to_order = $product->field_made_to_order['und'][0]['safe_value'];
      if ($made_to_order == "Made To Order usually ships in 2-3 Weeks") {
        $data[] = Array("knumber" => $knumber, "price" => $line_item_price);
      }
    }
    unset($product);
    unset($line_item);

    $master_data = array();

    foreach($data as $value) {
      if(array_key_exists($value['knumber'], $master_data)) {
          $master_data[$value['knumber']] += $value['price'];
      } else {
          $master_data[$value['knumber']] = $value['price'];
      }
    }
    unset($data);

    foreach($master_data as $value) {
      if ($value < 250.00) {
        $setup_fee_count += 1;
        $show_charge_in_cart = True;
      }
    }

    if ($show_charge_in_cart == True) {
      $product = commerce_product_load_by_sku("0909990000005");
      $line_item = commerce_product_line_item_new($product, $setup_fee_count, $order->order_id);
      commerce_line_item_save($line_item);
      //$order->commerce_line_items['und'][] = array('line_item_id' => $line_item->line_item_id);
      $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
      $order_wrapper->commerce_line_items[] = $line_item;
    }
  }
}

any ideas?  Thanks in advance.


texts: how to stream video on-site generated from link preview in a text area?

texts: I am using opengraph filter module to generate preview from url. It is working perfectly. Now if a user has shared a video or image through url on the site and the preview is generated, when someone clicks on that preview, it takes the user to the link page (external website). What I want is, it should open on my site i.e embed on my site so that user can see the picture or video, generated from link preview, on my website. Currently, there is a video filter module which converts links to embeded videos, but it requires users to use this format [video:url] when sharing videos, but this format [video:url] for sharing a video link is not desirable, so leave it. I just mentioned it for reference/information.


texts:
Im running onto some issues with Drush. I worked with php 5.3 and after upgrading to 5.5, i ran into some issues and decided to downgrade my PHP version back to 5.3. Now im running into the issue that Drush isnt working anymore.

Command cache-clear needs a higher bootstrap level to run - you will need invoke drush from a more functional Drupal environment [error]
to run this command.
The drush command 'cc all' could not be executed.                                                                                [error]
Drush was not able to start (bootstrap) the Drupal database.                                                                     [error]
Hint: This error often occurs when Drush is trying to bootstrap a site that has not been installed or does not have a configured
database.

Drush was attempting to connect to :
  Drupal version    : 7.28
  Site URI          : http://default
  Database driver   : mysql
  Database hostname : 127.0.0.1
  Database username : root
  Database name     : drupal_practice2
  Default theme     : garland
  Administration theme: garland
  PHP configuration :
  Drush version     : 4.5
  Drush configuration:
  Drush alias files :
  Drupal root       : /var/www/drupal
  Site path         : sites/default
  Modules path      : sites/all/modules
  Themes path       : sites/all/themes
  File directory path: sites/default/files
  %paths            : Array

You can select another site with a working database setup by specifying the URI to use with the --uri parameter on the command
line or $options['uri'] in your drushrc.php file.

Ive been searching on google for almost 3 days now and re-installing my computer would be a lot faster. I have lots of data so i dont want to re-install.

Someone that can help me with the solution?


texts: How can I sort a view based on a date value in a multi-value paragraph reference field?

texts:
I have a custom entity type that uses an entity reference revisions field that accepts multiple values. The referenced paragraphs contain a date field. I would like to sort the entities (descending) by the most recent date in a paragraph referenced from their fields. E.g.:

Entity 1

Paragraph 0

Date: 1/1/2016

Paragraph 1

Date: 1/1/2017

Paragraph 2

Date: 1/1/2018

Entity 2

Paragraph 0

Date: 2/1/2017

Paragraph 1

Date: 2/1/2018

Entity 3

Paragraph 0

Date: 3/1/2016

Paragraph 1

Date: 3/1/2017

...should sort to: Node 2, Node 1, Node 3.

Thanks!


texts: 4095 Selectors Limit on IE. How to split the Drupal 7 CSS compressed files?

texts:
Here is my problem. Using Sass (from Zen theme) and on top of that Brunch, our compressed css file has over 4095 Selectors and is then compressed by Drupal (and still has over 4095 selectors in one files).

Do you know if there is a way to tell Drupal to compress files in smaller files in order to avoid the 4095 selector limit per files ?


texts:
Aside from searching the Drupal api, is there a module or an easy way that will allow you to find out which hook or function you need to use to interact with pages in your site?

For example, I am looking to force certain values in a webform setup, to which I was able to use mymodule_form_webform_configure_form_alter to change the submission limit, status etc. But I was able to do this because I found the starting point for the script, now I am looking to force a default 'email to' value in the setup, but I don't know what function I need to use

What's the best way of finding out the best hook (etc..) for the job

Kind regards


texts: What happens if you leave out an `access callback` specification?

texts: In a custom module, if you have a menu hook item that has a custom access argument, but don't specify an access callback, what is drupal's default behavior? Does it use user_access? In other words, is an access callback necessary to specify?


texts: How do I invalidate cache for a block for anonymous users on a schedule?

texts:
At the top of every page of page of my organization's site resides the current hours of operation and current "now open"/"now closed" status, using Views block and Office Hours module).
At this time of night on a Wednesday when logged in, I correctly see that the hours are reflecting tomorrow's hours and that the organization is now closed:

However when logged out, I see that the current day's hours (now over) and "NOW OPEN". It's six hours after closing time and the 5 minute page cache time in performance settings does not seem to be respected for anonymous page views:

What can I do to force an anonymous cache clear (overkill?) or invalidation of a block for anonymous users, perhaps on a schedule? I'm aware that the built-in Page Cache module may be caching full rendered pages for anonymous users while Dynamic Page Cache module makes it usable for logged in users. Shouldn't Page Cache respect the page cache maximum age set in the Performance settings page? Most people viewing the current hours at the top of every page are anonymous users.
For now I'll manually clear the cache, making the status update properly (not ideal).


texts: Custom views filter + Add a groupBy in the query() function

texts:
On a domain site (domain access module), I want to filter medias/nodes by the related domains to the current user. For this I have created a custom views filter : I analyse the user domains and modify the query to display only the needed nodes/medias. Here is the code of my custom views filter:

  /**
 * {@inheritdoc}
 */
public function query() {
  $this->ensureMyTable();
  // Load the current user.
  $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
  $domains = array();
  // Retrieve the domains of the current user.
  $user_domains = $user->get('field_domain_access')->getValue();
  foreach ($user_domains as $domain) {
    $domains[] = $domain['target_id'];
  }
  if (!empty($this->value) and $user->get('field_domain_all_affiliates')->value == 0) {
    // Add an additional condition to filter contents/medias by the user domains.
    $this->query->addWhere($this->options['group'], 'node__field_domain_access.field_domain_access_target_id', $domains, 'IN');
  }
}

But, I get duplicates results in my views.
If I use this filter, I need to desactivate the SQL rewriting option, so I can't use the distinct option to remove duplicates.

Is there a solution to add a groupBy to remove duplicates? I tried to use this code without sucess:

$this->query->groupBy('nid');
$this->query->distinct(); // don't work

Do I add a new field in my query (node field) ?

Thanks for your help.


texts: Show Webform confirm message in my custom panel page

texts:
I'm new to Drupal. I have created a web form in my page using Webform module. I added my contact web form in a custom panel page. I use the Clientside Validation module to validate the web forms.

If the form validation is okay, I want to show the confirmation message at the top of the web form in my panel page instead of the default message location used in the page.tpl.php. I use the single page web site.

Can anyone help me to solve my problem?


texts:
At present, my Drupal 7 website’s "Page not found" is 301 redirected to a custom 404 page.

However, I just checked the HTTP response code for a random URL and I noticed it 301 redirects to a custom "Page not found" page, but that page returns a 200 HTTP response code.

Shouldn't the page response header be 404?

If that's the case how do I fix the response code to 404 in Drupal 7?


texts: Show page content on another page using views

texts:
I have a 'presentation' page where I would like an image gallery where all the uploaded images that users upload to the site are displayed.

So far these images are being displayed only on the 'upload' page as default.
(users are effectively modifying the same page when adding content)

I want to keep the 'upload' only as means to upload the images but I want all the images to be displayed ONLY on the 'presentation' page!

How do I do it with views?


texts: What is the equivalent of a call to drupal_http_request()?

texts:
In Drupal 7 I am using the following code.

$url = 'testdomain/url';
$response = drupal_http_request($url, array('method' => 'POST', 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8')));
if ($response->code == "200") {
  $result = $response->data;
}

What is the equivalent code I should use on Drupal 8?


texts: Is it possible to bypass one specific view for authentic users?

texts:
I have a specific view. This is running well under admin rights but not with specific other roles which do not have the permission “Bypass content access control”

Debugging with devel tools and related blocks as well as change permissions setttings in the role is not solving the problem :-(

Is there a easy way to create the possibility to give this specific view a "Bypass this view only for authentic users" ?


texts: How can I send Newsletter in HTML format?

texts: I have  installed the following modules simplenews, mailsystem, html mail to send HTML news letter from a Drupal 7 site. Right now, I am just able to send plain text email from send test option. How can I send an HTML email from my site? How can I send a newsletter to registered emails of my site?


texts: Function preprocess_views_view if not logged in

texts:
I have added two javascripts for one page only using preprosess in template.php. The two scripts seem to work well.

The jquery version I include on this page/view is interfering with admin overlay and other stuff for the editor. I'd like to apply this preprosess only if the user is not logged in.

/**
 * Equal height row javascript + jquery 1.10.2 - in page-view (my-view-page)
 */
function mytheme_preprocess_views_view(&$vars) {
   $view = $vars['view'];
   // Make sure it's the correct view
  if($view->name == 'myview') {
     // add needed javascript
     drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/jquery-v1-10-2.js');
     drupal_add_js(drupal_get_path('theme', 'mytheme') .'/js/equal-height-row.js');
  }
}

Is it possible to correct this function to make sure the scripts are not served to logged in users? Or does it require a different approach like preprocess_html?

(For now there is not going to be registered users other than editors)

(Using Drupal 7.25 and custom subtheme of Responsive Bartik)


texts: Facets removed when using contextual filter (category page)

texts:
I have taxonomy terms, which are also enabled in the menu (besides the all). The all points to the default product search page (/products) for which i have configured the search API to show two facets (category and location).
I am now trying to setup the /product-category/% page to also show a facet (for location). This view is also in the context of search (its type is "Product Display"). All seems to work as long as the contextual filter does not match

So when i type /product-category/BOGUS i get the facets, but when i do /product-category/realthing it does not show the facets (the whole sidebar first is not used)

I am finding it awkward that this proves to be so difficult. What i want is people to drill further down after having selected the category from the menu.


texts: cache table should be truncated if doing it in database?

texts:
Given this information from Clearing cache

  In the database
  Use phpMyAdmin or another tool to access the database tables and TRUNCATE (empty, not remove) all tables that start with cache_.

Should I also truncate the table called cache as is?


texts: How to add custom settings / attributes to a field

texts:
I want to be able to add custom settings / attirbutes to field instances.

I can create a custom field with custom settings no probs, but is it possible to get rid of the custom field and just add the settings so that the settings are stored per instance?

For example:

I create a content type, let's call it vehicle. I add a field called wheels which is a basic textfield where you can specify the number of wheels. Now I would like to add a few settings to the wheels field such as brand, model, etc. These settings would be specific to the content type but if you re-used the field wheels on another content type the settings could have different values... now this is a bit contrived but you get the idea!

Any ideas on how this could be achieved? My current solution is to create a separate field called something like Wheels meta information with the settings but I would rather a cleaner solution.


texts: How to correctly access entity elements in a twig template

texts:
I have an array of entities that i would like to render in a list.

$ids = \Drupal::entityQuery('chemical')
  ->condition('tid', $tid)
  ->execute();
$controller = \Drupal::entityManager()->getStorage('chemical');
$entities = $controller->loadMultiple($ids);

$chemicals = [];
foreach ($entities as $entity){
  $chemicals[] = ['id' => $entity->id(), 'label' => $entity->label()];
}

$output[] = [
  '#theme' => 'chemical_taxonomy',
  '#chemicals' => $chemicals,
];
return $output;

The twig template then creates the unordered list of URLs using the array of {{ chemicals.label }} and {{ chemicals.id }}. However, I should be able to just pass $entities to the template instead of extracting the id and label and building a new array, shouldn't I?

If I replace '#chemicals' => $chemicals with '#chemicals' => $entities I receive an error:

Uncaught PHP Exception Exception: "Object of type Drupal\\Core\\Field\\FieldItemList cannot be printed." at /var/www/Drupal_Sites/console/core/lib/Drupal/Core/Template/TwigExtension.php line 443,


texts: I am using calendar module and using calendar widget to show in front-end. Views has option to link title with colorbox popup. Here comes my obstacle I have multiple events in a day. When user clicks on the date at calendar widget it should popup to provide the day event listings in popup. How can I achieve this?


texts: How to properly filter a form's data against XSS?

texts:
Drupal 7.

I've got an (ECK module) entity form. The form's only field is a multi-value field of the field_collection (Field Collection module) type. The field collection contains two fields: a textarea, and a set of radio buttons. The user submits the form (AHAH), the entity is saved and the form is presented back to the user with the submitted values. For this project that is the intended (and necessary) behavior.

My (stripped down) validation handler is as follows:

/**
 * My custom validation handler.
 */
function my_module_eck_entity_form_validate($form, &$form_state) {
  $values = &$form_state['values'];
  $lang = $values['entity']->language;

  $fields = array('field_my_text', 'field_my_radios');
  foreach ($fields as $field_name) {
    // the values which get saved to the entity object
    foreach ($values['field_my_field_collection'][$lang] as &$item) {
      foreach ($item['entity']->{$field_name}[$lang] as &$child) {
        $child['value'] = filter_xss($child['value']);
      }
    }

    // the values which get output as part of the form on page-reload
    foreach ($form_state['complete form']['field_my_field_collection'][$lang] as &$item) {
      if (is_array($item) && isset($item[$field_name][$lang])) {
        foreach ($item[$field_name][$lang] as &$child) {
          if (is_array($child)) {
            $child['value']['#value'] = filter_xss($child['value']['#value']);
          }
        }
      }
    }
  }
}

It works and does what I want, but it is an ugly monstrosity that'll keep me up at night. There has got to be a nicer, cleaner way of doing this.

For the intents and purposes of this question, let's not discuss the pros & cons of Drupal's filter_xss() vs other tools - plenty of existing questions about that.


texts:
i have a menu with this structure:

Item name: Sport
Item link: taxonomy/term/35

And taxonomy terms with this structure:

Football tid 35
- Smallfotball tid 38 parentid 35
- Bigfootball tid 55 parent id 35

When i access to menu link my view displays all content that has taxonomy term id 35 and his childs. ( i use this contextual filters Content: Has taxonomy term ID (with depth) and Content: Has taxonomy term ID depth modifier)

I need only displays Childs and exclude contents with taxonomy term 35 (taxonomy parent, id menu link), i resolve this with filter criteria where (term) Taxonomy term: Parent term (!= 0) but in other cases does not works, for example in this (when parent is a children of other term):

Football tid 35
- Smallfotball tid 38 parentid 35
- Bigfootball tid 55 parent id 35
  - Big2football tid 56 parent id 55
  - Big343football tid 66 parent id 55

if menu link is

Item name: Bigfootball
Item link: taxonomy/term/55

display:

Bigfootball tid 55 parent id 35

Big2football tid 56 parent id 55
Big343football tid 66 parent id 55

and i need displays only

Big2football tid 56 parent id 55
Big343football tid 66 parent id 55


texts: How to define and use an external database connection in a custom module

texts:
I'm developing a module that will rely heavily on external database queries. Is there a best practice for defining and using an external database connection throughout a module?

This page tells me how to make the connection, but not where to put it in a module (specific hook?) so I only have to define it once. Also, is it always necessary to do "db_set_active('YourDatabaseKey');" or can I pass an argument that will set the db to use? I'm using Drupal 7.


texts: problem in admin_path module with my custom content type paths

texts:
I have created a content type "Test".

The content which I created of type "Test" have the paths like this "test/content1, test/content2 etc. means test/*".

So I entered the path "test/*" in the administrative pages.

But when I try to open any content of type "Test", First the url becomes like this "#overlay=test/content1" and then it redirects to "test/content1" and does not appear in overlay.

I tried some other paths of the contents of some other types and they are working fine in overlay.

So what is the problem with my custom content type? Any one who have some idea about t his?


texts:
Im using Panopoly, and have created a new Fieldable Panels Pane (FPP) bundle for a specific content type.

I notice that all preset Panopoly FPP's have a check box labelled 'Make title a link' inside a fieldset called 'General Options', which is also automatically added to my new bundle, and I can't for the life of me work out how to disable it!

For reference, this field is visible through the Panels IPE as well as the traditional /admin/structure/fieldable-panels-panes/manage/BUNDLE-NAME/add.

Does anyone know how I can isolate and disable this option on a per-bundle level?

Thanks!


texts: How to allow uploaded image brightness and contrast to be edited with a UI like a slider?

texts:
Many sites, like eBay to give a well-known example, allow users to edit images they upload with a slider or buttons to increase or decrease brightness and contrast. When the UI is used, a new image is (generally) generated server-side and AJAX-loaded in place, until the user is happy and saves a particular version.

In theory, Drupal is capable of all this. GD and ImageMagick support brightness and contrast adjustments and there are plenty of modules built on Image Styles that allow image editting (Imagecache Actions, Manual Crop).

Some even imply they support something like this, for example imagick:

  Modulate

  Brightness
  Saturation
  Hue

...and Imagecache Actions:

  Brighten/Darken
  ...
  Custom Actions - Execute your own PHP/GD code in the middle of an imagecache generation process. Requires some familiarity with imageAPI internals.

Image Effect Kit also has brightness and contrast under its "filter" options.

However, I can't find any combination of settings, modules and configuration that gives any control over anything like this to the user, or that could be attached to a UI control.

It's also possible to edit an image purely in the client side, using a JS/Canvas editor like CanmanJS then sending the Base64 data to the server, but I'm not aware of any existing Drupal integration for this or way to pipe this image data into Drupal's filefield/image style system. I've found a couple of modules for exporting images as Base64 (Image Base64 Formatter, Data URI creator) but not for importing them as such.

I've seen Image Editor module which pipes in 3rd party image editors like Avery, but they're excessive for my needs and I'd prefer not to rely on a 3rd party service. The only one I can see that uses a local library not a hosted 3rd party service is PaintWeb which seems to be only basic drawing tools, not brightness or contrast, and an SVG editor.

Can this be done in Drupal?


texts: Easiest way to add x-webkit-speech to the search block's input element

texts:
I am creating a zen sub theme and I was wondering what't the quickest way to add the x-webkit-speech attribute to the search box so user's can search with their voice? I know there is a Drupal project that can modify the search for me but I would prefer to do it in my templates somewhere so the rendered output is something like...

<input title="Enter the terms you wish to search for." type="text" x-webkit-speech id="edit-search-block-form--2" name="search_block_form" value="" size="15" maxlength="128" class="form-text">


texts: override date module function for label strings changes

texts:
I configured a exposed filter for a shipping date field on myview with operator "Is between".
I saw two labels,"Start date" and "End date" in myview form.
I wanna change these strings to "From Date: " and "To Date: ".

I have checked the file sites/all/modules/date/date_views/includes/date_views_filter_handler_simple.inc
This file includes the

function date_parts_form()

that includes the codes:

$label = t('Start date');

and

$label = t('End date');

But I don't want to modify this file directly for further maintenance.
I am not certain how to override this function with keeping an original module file.
Please show me the way with circumstantial directory path and file name.


texts:
I have been requested, against my better advice, to try to ensure that a Drupal site for an associated part of our organisation is up to date, although the site developers left no admin maintenance documentation nor information about any custom setup that they may have done, and now seem to be uncontactable (poor project management on the part of the site owners).
The standard Drupal update did not work, and I now have to try to revert the site back from the drush archive that was taken just beforehand.
However, drush arr (drush archive-restore) says:

Missing required argument: file.

I'm not sure what file I need to specify (our own installation of Drupal is somewhat customised and clear upgrade instructions, working in a different way, are supplied by the maintainers).
Looking in the drush-backups folder, I seem to have two choices:
/root/drush-backups/archive-dump/20200831154526/sitename.20200831_154526.tar.gz
/root/drush-backups/sitename/20200831154744/drupal/

(the latter of which seems to contain the Drupal files as-is (not as a .tar.gz file))
Is the .tar.gz file from the archive-dump folder the file that drush arr is wanting, and then drush will know how to find the rest automagically?


texts:
Before I knew Drupal, I made a CMS that was working like Wikipedia, where each page and link could have parent and children. Now I want to create that website with Drupal.

Is there any module for this?

This is what I need: Each page may have children, and each children may have children too and so on.


texts: Calculate Star rating based on webform submissions

texts:
Is there a module to calculate Average Vote based on webform submissions?

Explanations:

I have a Webform which looks like this. So when a user submits the form i need a average value to be calculated which i can show as star rating some where on another page.

Does it need a custom module ?

Any clues ?
thanks


texts:
I have a weird issue. I created a custom profile using the Profile module. This profile has some classic fields and some paragraph type fields. I assigned permissions to a role to create profiles and the user is able to do that. The problem is that this user (the owner/author of the profile) cannot view the paragraph fields when displaying the profile entity. He can edit fields but cannot view them. Other classic fields can be seen, but not paragraphs.

Anyone else had this problem?

I looked into the paragraph module and the message "You are not allowed to view this ..." is displayed when the user does not have "view" access to the paragraph entity. Which is weird because it does have access to view the parent entity (it is the author) and to edit all fields in it.


texts: How do I add a variable for a Twig template in my preprocess function?

texts:
I'm using the following code to preprocess the variables for my template:

function template_preprocess_imagegallery_format(&$vars) {
  template_preprocess_image_formatter($vars);
  $vars['image']['#theme'] = 'igimage';
  $vars['image']['#thumbnail'] = ImageStyle::load('thumbnail')->buildUrl($vars ['image']['#uri']);
  $vars['image']['#fullimage'] = file_create_url($vars ['image']['#uri']);
}

The #uri variable is already present, and if I just modify it everything works fine. But I need to add additional variables here as I need two different styles of the same image. But simply adding those variables to the array doesn't work.

If I dump the available variables in my Twig template with {{ dump(_context|keys) }}, I don't see the variables I added there. If I try to use them in my template, nothing gets inserted.

I can see that the values are added to the array, when I dump the image variable in the theme that renders the entire field, I see my variables in the array. But they're still not available in the template that renders the image variable itself.

What else do I need to do to add a variable in my preprocess function that I can use in my Twig template?


texts: How can I sort options in an exposed views filter alphabetically?

texts:
I am using an exposed Views Selective Filter which limits the options available quite nicely. However the display order of the Options is what is causing me the trouble. Here is an example of my Select list:

Accomodation
 - Camp Sites
 - Hotels
 - Rural Hotels

Beauty
 - Hair and Nails
 - Makeup
 - Spa

In the results these display exactly as I want them which is grouped by the Parent term (Accomodation, Beauty etc...). The trouble is that when I use the Views Selective Filter to only show options with results the list of options shows like this:

Camp Sites
Hotels
Rural Hotel
Hair and Nails
Makeup
Spa

What I really want to do is to resort that list alphabetically before it is displayed to the User. I guess Hook Form Alter is the way to go but I can find anything anywhere on how to create the alpha sort option. I hope that all makes sense.
Thanks


texts: 'The alias is already in use' when editing a node that had an alias generated programmatically

texts:
I'm currently using an event subscriber to latch onto an event from a module that creates and/or updates nodes. I'm programmatically setting the url alias based on a user inputted field by doing the following

$path = \Drupal::service('path.alias_storage')->save("/node/" . $node->id(), $url_alias, "en");

It works but when I open the node and attempt to edit it, I get the message

  The alias is already in use

When I try to save it. Is there something I'm missing? Does a field on the actual node have to be edited as well?

I'm also using pathauto if that has any effect.

UPDATE: I just noticed that whenever that aliased is saved it generates 4 entries in the URL alias list.


texts:
How to create a view of hierarchical taxonomies and each taxonomy lists all its nodes?

Item1
--node1
--node2
Item1.1
--node3
Item1.2
--node4
Item2
Item2.1
--node5


texts: How to set available options for Comment Per Page select?

texts: In Drupal 7, In comment setting a option Comments per page show 10, 30, 50, 70, 90, ... 300. I want to option "Comment per page" show like 1, 2, 3, 4, .... .


texts: I want to use dd/mm/yy as date format in a custom form instead of default mm/dd/yy

texts:
I am using the following date form element.
$form['dobnew'] = [
  '#type' => 'date',
  '#title' => t('Birth Date new'),
  '#date_date_format' => 'd/m/Y',
  '#default_value' => date('d/m/Y'),
  '#required' => TRUE,
];

The date widget I get is the following one.


texts:
I have a block like this:

Languages

Nederlands

English

Français

But what I want is this:

  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
    Action
  </button>

Action

Another action

Something else here

Separated link

I've overwritten the locale block like this: (block--locale.tpl.php)

    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
        LANGUAGE
    </button>
    <?php print $content; ?>

But I need to change the structure in the $content variable, how can I do this?

UPDATE:

In my locale module (in /modules) I've found this:

function locale_block_view($type) {
  if (drupal_multilingual()) {
    $path = drupal_is_front_page() ? '<front>' : $_GET['q'];
    $links = language_negotiation_get_switch_links($type, $path);

    if (isset($links->links)) {
      drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css');
      $class = "language-switcher-{$links->provider}";
      $variables = array('links' => $links->links, 'attributes' => array('class' => array($class)));
      $block['content'] = theme('links__locale_block', $variables);
      $block['subject'] = t('Languages');
      return $block;
    }
  }
}

As you can see they add a class language-switcher-{$links->provider}. Now I would like to add some more classes to that.

How can I do this now in my subtheme template.php? It's like my function locale_block_view_alter isn't called for some reason. I already tried with a var_dump but no result in my browser ...


texts:
I'm installed drupal 8 in local and created a content type named as  Project with minimal fields. And implemented form API to collect data in custom module.

Here how can I save the data as node content?
or How can I use entity save in drupal 8


texts:
When I include the snippet found in answer to this question How to simply make the whole site HTTPS?  to redirect to https in my htaccess.php file, all urls resove to /index instead of going to the page originally requested (Ex: user tries to access example.com/about, and is redirected to https://example.com).

Here is the snippet I used:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I have also tried the slight variation found at https://www.drupal.org/https-information, which has the same unsatisfactory result:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www.domainname\.com*
RewriteRule ^(.*)$ https://domainname.com/$1 [L,R=301]

How can I make the site all https without breaking the ability to navigate to a specific page?

Edited to add: I've got the Secure Pages module, but haven't managed to get it to work. If you have advice on that point instead I'd happily take it.


texts: Adding a drop down field to user registration

texts:
We are using Drupal 8 for one of our new project and we need to add a country dropdown to the user registration form. I see that we can add a select box through Manage fields section, but how do I make it configurable?

I mean I want to show the values in the select box from a configurable list.


texts: I want to use an argument from the path in a twig template (as a html class)

texts:
Having read about how D8's path system is different from D7, and having seen some 'simple' examples, I have tried

setting a path variable in a preprocess functions and outputting that as a {{ my_path_variable }} in a twig template
outputting {{ kint(my_path_variable) }} in the twig template
outputting kint(my_path_variable) in the preprocess function

None of the above works, I only get NULL in my kint output.

I've read this page: Get the current path alias or path?, and I really don't know where I'm supposed to place the $current_path definition in order to get the path into a twig template, so I can output it as variable.


texts: How do I detect spam from among published comments?

texts:
My spam prevention modules had to be disabled while I was fixing a problem. Meanwhile, I was attacked by numerous spam bots and now have thousands of published spam comments on my site.

Is there a way to detect these comments and unpublish and/or delete them?

I am using drupal 7.


texts: Set the value of a hidden field in form block

texts:
Using the code below in a block, I am displaying a form in a block on all pages for a content type called Goals. I want to use this block / form to update progress on the goal to a content type called Goal Progress, and connect the two through a key called goal_id - the nid of the Goal.

The challenge that I am having is setting the value for the goal_id field (Goal Progress content type). I suspect I need to use $form_state['values']['field_goal_id']['und']['0']['value'] = 'value'; to declare the value, but I can't figure out where that should be placed.

Been looking for a solution for a couple of hours now, so any suggestions are greatly appreciated.

<?php
  $node = menu_get_object();

  if (isset($node->nid)) {
    $nid = $node->nid;
  }

  module_load_include('inc', 'node', 'node.pages');
  $node_form = node_add('goal_progress');
  print drupal_render($node_form);
?>


texts: How to make user.html.twig template for two different pages (users)?

texts:
I want to make user.html.twig template for user ID1 is not such as to all other users. How to?

I tried this code in MYTHEME.theme file:

function MYTHEME_theme_suggestions_page_alter(array &$suggestions, array $variables) {
  if ($user = \Drupal::routeMatch()->getParameter('users')) {
    // For make files, like:
    // page--user--[id].html.twig
    $suggestions[] = 'page__user__' . $user->uid();
  }
}

But template page--user--1.html.twig or page--user--%.html.twig don't work. Cache is clear.


texts: How to change placeholder title of search box?

texts:
I have placed 2 search box in 'node/92' page at two different region one is at header region and another is at content region ,I have to change the placeholder text of both search box as abc and xyz respectively
my code is:

function bartik_form_search_block_form_alter(&$form, &$form_state, $form_id) {      //print arg(1);
      if (arg(1) == 92)
    {

    $form['search_block_form']['#attributes']['placeholder'] = t('abc ');
}

}

but this code not working well after using it both the search box placeholder text having the same title  "abc"


texts:
I have a need to automatically create an Article node type each time a Basic-Page node type is created - I am using Rules successfully to achieve that effect.

My problem is a Menu link also needs to be created for each Article node created. This means the Provide a menu link checkbox needs to be automatically enabled in the process of creating each Article node - but it isn't.

The image above shows the checkbox I'm trying to automatically enable.

When creating an Article node directly, i:e not using Rules to create the new Article node, the box is checked and things work as normal.

I really need to find a solution which will enable the checkbox as I auto create my node types.


texts:
I had used files of a website to create new website. I had changed the database and user details in settings.php. Now everything is working fine except email settings in webform. It is showing old informations as default.

I need the default email to be "noreply@pharmahelpdesk.net".
In Configuration > System > Site Information , I had used the same email id. But it is not getting updated. Due to this I am not receiving emails. Please see the images and suggest.

.


texts: Search page shows empty fields of unpublished content

texts:
How can I make a filter to my search page that hides unpublished content?

In filter criteria I only have global, indexed and search.


texts: How to retrieve files from url when they have whitespace into filename?

texts:
I need to import a lot of images/pdf from urls, and then save them to a file/image field into nodes.

To achieve that, I am using this script (example with images):

if($image!='\N'){

    $image_url = 'http://www.example.com/images/news/'.$image;
    $managed = TRUE; // Whether or not to create a Drupal file record
    $path = system_retrieve_file($image_url, 'public://news/', $managed, $replace = FILE_EXISTS_REPLACE);
    $fid = $path->fid;
    $node->field_image['und'][0]['fid'] =$fid;

}

This is working so well in almost every case. Only files containing whitespaces in filename are not retrived as expected. Example:

2009 juin texte TVA vote final.pdf
Geoffrey Schinder Award.jpg

/**** EDIT ****/

Regarding Molot comment I changed my code including urlencode(), this way:

if($image!='\N'){
    $image_url = urlencode('www.example.com/images/news/'.$image);
    $managed = TRUE; // Whether or not to create a Drupal file record
    $path = system_retrieve_file($image_url, 'public://news/', $managed, $replace = FILE_EXISTS_REPLACE);
    $fid = $path->fid;
    $node->field_image['und'][0]['fid'] =$fid;
}

But it's even worse, I can not retrieve any file this way. Here is my filename after urlencode():

http%3A%2F%2Fwww.example.com%2Fimages%2Fnews%2F2009+juin+texte+TVA+vote+final.pdf
http%3A%2F%2Fwww.example.com%2Fimages%2Fnews%2FGeoffrey+Schinder+Award.jpg

And before:

http://www.example.com/images/news/2009 juin texte TVA vote final.pdf
http://www.example.com/images/news/Geoffrey Schinder Award.jpg

/**** EDIT 2 ****/

Here is the kind of errors I am getting when file has white spaces:

HTTP error 404 occurred when trying to fetch http://www.example.com/images/photos/Geoffrey Schinder Award.jpg

This is so strange because I can reach all these images from browser, for example typing http://www.example.com/images/photos/Geoffrey Schinder Award.jpg in url bar will display the image correctly. But system_retrieve_file() isnt' able to reach it.

$path = system_retrieve_file($image_url, 'public://news/', $managed, $replace = FILE_EXISTS_REPLACE);


texts: Duplicate field values in views for a custom entity

texts:
I have a custom entity. I'm using hook_entity_property_info() to tell views what fields are in my custom entity.

However for some reason I am getting duplicate fields when it comes to views. As in, I go to add a field in a view, and it is listed twice. It's not a problem, but cosmetically it is ugly.

Why would this be?

I am using this as my views controller class:

'views controller class' => 'EntityDefaultViewsController',

Could that be the problem?

This is the link that is most relevant to what I am doing:

https://www.drupal.org/node/1208874

My hook_entity_property_info():

/**
 * Implements hook_entity_property_info().
 */
function stockinfo_historical_entity_property_info() {
  $info = array();

  $info['stockinfo_historical']['properties']['sid'] = array(
    'label' => t('SID'),
    'description' => t('The ID of the stockinfo historical row.'),
    'type' => 'stockinfo_historical',
    'schema field' => 'sid',
    'entity views field' => TRUE,
  );
  $info['stockinfo_historical']['properties']['symbol'] = array(
    'label' => t('Symbol'),
    'description' => t('Symbol of the stock.'),
    'type' => 'text',
    'schema field' => 'symbol',
    'entity views field' => TRUE,
  );
  $info['stockinfo_historical']['properties']['name'] = array(
    'label' => t('Company Name'),
    'description' => t('Name of the company.'),
    'type' => 'text',
    'schema field' => 'name',
    'entity views field' => TRUE,
  );
  $info['stockinfo_historical']['properties']['date'] = array(
    'label' => t('Date'),
    'description' => t('The day this happened on.'),
    'type' => 'date',
    'schema field' => 'date',
    'entity views field' => TRUE,
  );
  $info['stockinfo_historical']['properties']['stockinfo_historical_high'] = array(
    'label' => t('High'),
    'description' => t('The high on this day.'),
    'type' => 'decimal',
    'schema field' => 'stockinfo_historical_high',
    'entity views field' => TRUE,
  );
  $info['stockinfo_historical']['properties']['stockinfo_historical_low'] = array(
    'label' => t('Low'),
    'description' => t('The low on this day.'),
    'type' => 'decimal',
    'schema field' => 'stockinfo_historical_low',
    'entity views field' => TRUE,
  );
  $info['stockinfo_historical']['properties']['stockinfo_historical_close'] = array(
    'label' => t('Close'),
    'description' => t('The close on this day.'),
    'type' => 'decimal',
    'schema field' => 'stockinfo_historical_close',
    'entity views field' => TRUE,
  );
  $info['stockinfo_historical']['properties']['stockinfo_historical_volume'] = array(
    'label' => t('Volume'),
    'description' => t('The volume on this day.'),
    'type' => 'decimal',
    'schema field' => 'stockinfo_historical_volume',
    'entity views field' => TRUE,
  );
  $info['stockinfo_historical']['properties']['stockinfo_historical_adj_close'] = array(
    'label' => t('Adjusted Close'),
    'description' => t('The adjusted close on this day.'),
    'type' => 'decimal',
    'schema field' => 'stockinfo_historical_adj_close',
    'entity views field' => TRUE,
  );
  return $info;
}


texts: How to upload media to S3 using entity browser and Flysystem S3 module

texts:
My site is configured to upload media images to S3 using the flysystem module.

However when I want to use the entity browser it's default configuration is to upload images to the filesystem.

Is there a way to change the upload location to use the same S3 location?

What syntax should be used in the "Upload location" field below?


texts: Editing Image of Media Type Image in Drupal

texts:
I'm having an issue with an Image field that I've set up under a Media Type. I'm able to create nodes, upload images or select images from the media browser just fine, but if I need to edit the node and change the photo, when I save it I get the following warning and my image disappears:

User warning: Missing file with ID image/jpeg. in Drupal\image\Plugin\Field\FieldType\ImageItem->preSave() (line 327 of core/modules/image/src/Plugin/Field/FieldType/ImageItem.php).

The only way I seem to get it working again is to completely delete the node and recreate a new one.

I have other fields set up the same way with normal content types and it works fine. Is there something I'm missing?

I'm using Drupal 8.5.3


texts: Taxonomy views listing url to follow site url structure

texts:
This is part of my site structure

A node gets part fo url alias from term and parent terms
mysite.com/term:name/term-child:name/node:title (Those are replaced with actual tokens)

Lenght of the alias may chanche depending on how many child terms there are
it may be food/banana/chiquita or cars/race/ferrari/red/enzo

What I would like to do, is to have pages like listing views that show nodes under that term (not parent term or child term).

so food will show nodes tagged with food (not nodes tagged with banana) and cars/race will show nodes tagged with race (not nodes tagged with cars or Ferrari).

I've tried taxonomy display but does not seems to work as expected.

I've set up term alias to follow same site structure so Ferrari term has got the alias cars/race/ferrari.

I'm using taxonomy menu and it works reeally well and it does the job but I cannot change view mode. I would like to change it to teaser or a custom view mode.

My questions are:
1) using taxonomy menu, how can i change taxonomy view mode?
2) is it possible to get same result with views?

Thanks in advance.


texts: Webform default validation message altering

texts: I am working with drupal8 site.Here i want to override the default "The email address %mail is not valid" email format validation message.I have checked with hook_form_alter to implement this.But no result.Is it possible to alter this message?


texts: How do I sync taxonomy terms with the second level of a menu?

texts:
This question pops every time I create a new e-commerce site.

I have a horizontal main menu with Home, Products, Blog, etc... in it. I need to get the terms from my Product catalogue as the drop down menu underneath Products.

I use Taxonomy Menu to good effect elsewhere in the site, but I can't see any way of moving an entire Taxonomy Menu (or even a sub-set) to underneath a menu link in another menu.

My usual method is to hard-code a function into my theme (with appropriate caching of course), which builds up the sub-menu of terms. I then have to create another function to mimic the menu rendering functions, and inject the 'taxonomy menu' when my loop hits a certain menu link ID. Finally I use that function in place of the standard method of outputting menu links in my page template file.

Needless to say that's not a good method and it leaves me feeling dirty every time. I'd really prefer a more opaque method that keeps the menu in sync when terms in the vocabulary are changed.

It seems like this problem would have been solved over and over again, but my Google-fu is failing me.

Anyone got any good suggestions (that don't involve creating a View, which would be way too much overhead)?

I should also mention the lazy man in me is looking for a pre-built module to do this. It would be fairly trivial(ish) to implement the code on a case-by-case basis (see hampusn's comment below) but I'm hoping there's a generic module based solution available.


texts: Register an object with the Service Container and give it a setRequest() (get base url)

texts:
I'm looking for a way to get the hostname of a multisite, and I've found several answers about it.

One of the solutions was to use:
Answer link

$host= \Drupal::request()->getHost();

  or

\Drupal::request()->getSchemeAndHttpHost();

Per also a user comments that the use of the Request object can be dangerous, as mentioned in the following link.

The comment warning say: Url to documentation

  Note: The use of this wrapper in particular is especially discouraged.
  Most code should not need to access the request directly. Doing so
  means it will only function when handling an HTTP request, and will
  require special modification or wrapping when run from a command line
  tool, from certain queue processors, or from automated tests.

  If code must access the request, it is considerably better to register
  an object with the Service Container and give it a setRequest() method
  that is configured to run when the service is created. That way, the
  correct request object can always be provided by the container and the
  service can still be unit tested.

  If this method must be used, never save the request object that is
  returned. Doing so may lead to inconsistencies as the request object
  is volatile and may change at various times, such as during a
  subrequest.

I have a custom module and I have a service, is it possible to implement it in a service?

My question is according to the comment and recommendation of the API, how is it that it should be implemented?

Thanks.


texts: Why field is double when I print it in node.tpl.php

texts:
I have a issue. I created a field in "content types > article". Then I went to node.tpl.php and added next code:

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

after that, I cleared cache and saw double field in my article.
I tried to hide this field in "manage display" but it didn't successful, my field disappeared at all.

I just want to render my field in a certain place in the node.tpl.php


texts: A user-friendly, fast way to delete the same field from several content types at once?

texts:
I have a Drupal 7.39 site with about 10 content types. All of these content types contains 2 fields which I want to delete (It's a long story why).

Is there a way to delete both of these fields from all content types at once, instead of manually deleting each one of them from each content-type? Thanks,


texts:
In my web application (Drupal 7) I'm using a date field with year-month-day granularity, but I would like, for a specific content type, to add also hours and minutes.

Is this possible to achieve? How?
Is this safe or it'll mess with the other content types, existing views etc.?

I've thought of adding an extra time only field, so I've checked some modules like CCK Time or Timefield, but they don't seem maintained anymore (last release is about two years old).

Use case:
I have an "Absence" content type. When a student is absent, the teacher selects the day when the student is absent, hours and minutes aren't needed. I'm now creating an "Early exit" content type: if a students has to go out from school before the regular school day end, in that case the teacher need also the time when the student left the school. As an alternative I was thinking on two integer fields (hours and minuter), but it doesn't sound as an optimal solution to me.


texts: How to theme single node differently to nodes in taxonomy list?

texts:
I'm editing node.tpl.php, to apply custom theming when the site displays single nodes.

However, if I browse for a certain taxonomy term, the list of nodes presented is also affected by my changes.

Is there a way to theme just the single node pages?


texts: Custom template file for custom view mode on site front page

texts:
I'm trying to style a view a certain way on the front page (using a custom front page, page--front.tpl.php) of my site, and here are the steps I've taken using Entity View Types and Views modules:

1.) Created content type called 'Recipe'
2.) Created View Mode called 'Front Small'
3.) Created a view and called it 'Front Feature One'
4.) In the view settings, I've set the format to 'Content', and selected 'Front Small' view mode for display
5.) In my template.tpl.php file I've put in the following:

if ($variables['view_mode'] == 'front_small') {
    $variables['theme_hook_suggestions'] = 'node__' . $variables['type'] . $variables['view_mode'];
}

6.) I tried creating a file called node--recipe--front-small.tpl.php to style the node in a custom way but it never gets used. The standard node.tpl.php file is being used instead.

Can anyone tell me if I'm naming the file incorrectly or if something else might be wrong? When I spit out the $view_mode variable in my node file it shows "front_small" only. I've also tried removing 'recipe' from that file name to see if it would make a difference, but to no avail.

Note: I am using a custom front page styled in the page--front.tpl.php file. The view mode above that I'm trying to style should be appearing on this front page, so I'm not sure if there are other things I am missing.

Any help is greatly appreciated. Thanks in advance!


texts:
I plan to develop a module (say M2) that uses a pre-existing module(M1) as a soft dependency.  In short there are a number of functions that I can reuse from M1 in my module M2...

other than specifying M1 as a dependency in M2's .info file what other steps do I need to take to re-use M1's functions.. also since these aren't classes but functions so how can I inherit them ?

using module_load_include() function only includes the .inc file... but then what about the .module file of M1 ?


texts:
I've installed drupal several times and I'm still having the same problem. Some modules aren't working.

E.g:

Admin menu - They don't always appear. It only shows in random moments.

Wysiwyg and CKeditor - is not visible when I'm creating the content.

These are the modules I have installed and I'm using Marinelli theme:

admin menu
Wysiwyg
IMCE Wysiwyg bridge
IMCE - this is for images
IMCE Mkdir
Pathauto
Chaos tools
insert
Mega menu


texts: How to format database fields in a report created with Forena?

texts:
How can I choose how to display the fields from the database returned by the data block (using the Forena module)? Such as a field just returns a number, but each number of that field represents something else that I'd like to display. For example:

 if (id=5) { $text = "see website"; } else { $text = "free"; }

If this is not possible, how in general can I change how the fields are displayed?


texts: Why doesn't my code to save an order work when invoked by AJAX?

texts:
I am programmatically creating an order in Drupal Commerce. It works perfectly with a user who is logged in, but for anonymous users it redirect to a checkout page and shows a "page not found" message.

$product_id = 1;
$order = commerce_order_new($user->uid, 'checkout_checkout');
commerce_order_save($order);
$product = commerce_product_load($product_id);
$line_item = commerce_product_line_item_new($product, 1, $order->order_id);
commerce_line_item_save($line_item);
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper->commerce_line_items[] = $line_item;
commerce_order_save($order);
drupal_goto('checkout/' . $order->order_id);


texts: How to customize survey builder form by programatically in drupal

texts:
I have installed survey builder module. Using this we created survey pages, but form elements are not aligned properly. I want to give some style to survey form elements.

How can i make it is possible? can any one suggest any idea for this ?


texts: Add multiple products with diferent quantities to cart at once

texts:
I would like to show a list of products along with a quantity field for each product and a single add to cart button at the bottom.

I found a module that would achieve exactly what I want in Drupal 7 https://www.drupal.org/project/commerce_add_to_cart_extras and the image included represents what I would like to achieve.

Any direction / help in how you would achieve this in Drupal 8?


texts: How do I get the fivestar module's vote on a review node to count towards a product node?

texts:
Should be simple.
I have a content type called Product.
I have another content type called Review.

I want people to vote when they create the Review content type and have the vote count towards the Product.
When I display the Product, I want the average of the votes to appear with the product.
Problem: When I add the fivestar field to the Review content type I DO NOT see an option to set a target node.

Note: I am not using comments as reviews, I am using another content type.

I have tried to find a solution in other postings and I have no problem with a programmatic solution but I have not found anything clear.


texts: Multiple Values in Custom Template Field

texts:
I have a custom template for a node, and a field which has the possibility of having multiple pieces of data. In this case:

There is an Author node
There are Publication nodes
Publications are being Entity Referenced on the Author node

The custom template then prints the publications to the node

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

I know that adding ['1'] displays the first publication if multiple publications are attached to the same author, however, how would I display the top 5 publications, if say, there was 10 publications by the same author?


texts: Apply hook_menu to all nodes except node593

texts:
I have 2 separate hook_menu callbacks going on in my code.

I want to apply a function to all nodes and then for node593, I want to apply it's own function but I can't seem to do this.

The function for the % wildcard seems to work for all nodes, including 593.

Anyone know how I can get past this ?


texts: Overriding a specific view mode html.tpl.php template

texts:
How can I override the html.tpl.php template for only the "teaser" view mode of the "Article" content type?

I found this on the Drupal 7 Template (Theme Hook) Suggestions page on drupal.org page, but cannot see how to drill down to a specific view mode for a single content type.

  html.tpl.php base template: html.tpl.php The following are some examples of how you may override the base template:

  html--internalviewpath.tpl.php
  List item

  html--node--id.tpl.php

  See html.tpl.php in the Drupal API documentation for more
  information.

Will I need to implement a page preprocess hook to accomplish this?


texts:
For a customer we should do a bunch of sites build with Drupal. Multisite is not possible because of different hosting solutions.

Would creating a custom distribution work out for that case? Is it possible to make a "private" distribution not listed on Drupal.org?


texts: hook_default_rules_configuration can't debug it or force it to load

texts:
I am trying to debug a hook from title, here it says
http://api.drupalhelp.net/api/rules/rules.api.php/function/hook_default_rules_configuration/7.2

"This hook is invoked when rules configurations are loaded. " but not sure when this is happening? I am clearing cache, clearing Rules cache from UI, but seems like xdebug breakpoint never stops inside. Maybe I need somehow to trigger it, but not sure how?


texts: db_update after a submit button is clicked

texts:
I want to update  a "picture" field with a type of character varying, after a button is click. My customize module is already connected to it's database.

This is my form:

function myid_user_page_form(){

    $enrollment = array(
        'database' => 'enrollment',
        'username' => 'postgres',
        'password' => '',
        'host' => 'localhost',
        'driver' => 'pgsql',
    );

    Database::addConnectionInfo('myid', 'default', $enrollment);

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Save',
        '#attributes' => array(
            'id' => 'myid_save',
        ),
        '#submit' => array('formsave_action'),
   );
   return $form;
}

function formsave_action($form,&$form_state) {
    db_set_active('enrollment');

    $num_updated = db_update('student')
        ->fields(array(
          'picture' => 'Yucks',
        ))
        ->condition('studid', '101-03043', '=')
        ->execute();

    if($num_updated) {
        drupal_set_message('Successfully Saved');
    }else{
        drupal_set_message('Save Failed');
    }
    db_set_active();
}

Unfortunately, nothing works. Nothing gets updated and displayed and an error saying:

My external database is SQL_ASCII compared to drupal's default database which is UTF8 encoded. Does it do something with my problem? Can someone point me to where I've been wrong? Thanks.


texts: How to model players and rosters in a team sport site

texts:
I'm very new to Drupal and I would like to know, from a general design standpoint, how you would enter players of a team into drupal. I don't want to add them as users because they should not be able to log in etc.

Each player could have fields like Name, Picture, etc.

Is this really a content type? Because the players are not published alone. Or is it necessary to create a custom module for this?

These players are then used to show the current roster. This could be done with a View and custom template I guess, but I'm not sure. They are also used in game reports (who played in that particular game and maybe the stats)

If I have a database of players somewhere, I would like to have a field that allows me to select a particular player. So basicly I must reference a content type inside another content type. I have not seen that option though.

No technical details are required, just general hints to modules or advice how to accomplish this task.


texts: Need to give a user "superadmin" status through database

texts:
There doesn't appear to be a superuser on the users table.
Whenever I try to access permissions directly I get "Access denied", even though my user is listed as and Admin.

How can I promote another user to superuser status through the database?


texts: Forums 'Add Container' function not doing anything

texts:
I have enabled the Forum module and ran into some rather annoying errors:

No 'Forum' link comes up in admin, I have to go directly to admin/content/forum
I click on 'Add Container' or 'Add Forum' and nothing happens
When I click on 'Create Content' I cannot see type forum (only when I view content types)
When I direct to node/add/forum I cannot create as the Forum dropdown box is empty (as I can't create Containers

I have run cron and update to no prevail. I read something somewhere it helps to manually update the database by incrementing the container row count or something?


texts: How can i remove required field validation on click submit button?

texts:
I have some radio buttons such as draft, need review, etc. I want to remove (omit) the required fields when draft is selected, and click on the submission button.
I tried with below code but it is not working.

function mymodule_form_alter(&$form, &$form_state, $form_id)
{
 if($form_id =='catalog_node_form')
 {
  $form['#validate'][] ='remove_required_field';
 }
}

function remove_required_field($element)
{
 foreach (element_children($element) as $name)
 {
  $element[$name]['#required'] = FALSE;
 }
 return $element;
}


texts: How do I access Session variables in Drupal that were set on non-drupal pages?

texts:
If I go print_r($_SESSION) on a drupal page (say mysite.com/ )I only get Session variables set from drupal pages (which are none atm). I can set new ones and they'll show up.

Array
(

)

However If I print_r($_SESSION) on a non-drupal page (say mysite.com/somefolder/index.php) on the same domain I get a different (and desired) array:

Array
(
    [last_url] => /downloads/full.php
    [ip] => ::1
    [address1] =>
    [address2] => Australia
    [zip] =>
    [phone] =>
    [fax] =>
    [dealer] =>
    [referral] =>
    [software] =>
    [searchTerms] =>
    [user_type] => user
)

I have session_start(); at the beginning of all files.

How does my site seemingly have two $_SESSION arrays? How can I access my $_SESSION vars set on non-drupal scripts within drupal pages?

Thanks


texts:
I'm hoping someone can take pity on me because I just can't seem to figure out how to make a simple module to remove, or hide some tabs in my user pages.
I read the docs on making custom modules, questions about removing tabs, and thought I figured it out. I made a custom module called 'TabEdit' with this structure, just to test it out:
/tabedit
    tabedit.info.yml
    tabedit.module

tabedit.info.yml
name: TabEdit
description: Edit tabs shown in user pages.
type: module
package: custom
core: 8.x
core_version_requirement: ^8 || ^9

tabedit.module
<?php
/**
 * Implements hook_menu_local_tasks_alter()
 */
function tabedit_menu_local_tasks_alter(&$data, $route_name) {
  unset($data['tabs'][0]['simplenews.newsletter_subscriptions_user']);
}

It didn't work, so I obviously still don't get the fundamentals on how to make a module. What I want to do is remove the Shortcuts, Simplenews Subscriptions, Activity, and Submissions from the user menu tabs.


texts: From here, it is clear that regions contain blocks, but when working with Panels, are regions still relevant? If yes how? What is the relationship between regions and panels? Thanks.


texts: Adding Boolean or Tag to Image File Field

texts:
I am using File Entity and have added a boolean to the image file field. This checkbox is to check when I want to make a favourite photo.

My problem is, I'm not seeing this on the node creation page, I upload the image(s) and I just still have alt and title fields available and no boolean.

I have gone through manage form display, manage display and I can see it there for Default and Thumbnail view modes.

What step am I missing?

Drupal 8


texts: How do I inject services in class that implements an interface?

texts:
How do I inject services in a class that implements an interface.

class RoleNegotiator implements ThemeNegotiatorInterface {

  public static function create(ContainerInterface $interface) {
    return new static(
      $interface->get('router.admin_context')
    );
  }
  public function __construct(RouteMatchInterface $route) {
    $this->route = $route;
  }
}

The above code throws an error.


texts: How can I edit metadata and custom fields for an embedded image using Media Module in a WYSIWYG in D7

texts:
I need the ability to edit custom fields (Caption, Credit) on an image that has been placed in a WYSIWYG. I'm using the latest dev version of the media module and WYSIWYG + CKeditor. I see the fields fine when I add the image, but when I click the media button to edit the image, the custom fields are not accessible.

Adding an image works, but only if you upload a new image.

Editing does not show the fields though.

This seemingly was solved a long time ago... but doesn't seem to be part of the latest dev branch.
https://www.drupal.org/node/835516#comment-7537339

Any direction on how to get the custom file fields to display and be editable with D7?


texts: mark single form field as cause of error on form validation

texts:
I've a custom field, and I'm trying to write the validation for the field values. however when a particular field causes the failure, the whole fielset is marked in red. I only want the specific field element to be highlighted, and in the case of Unlimited I only want the specific entry highlighted.

here is the code I have so far. but the whole fieldset is marked in red when ever a validation fails.

   function prodlist_field_widget_form(&$form, &$form_state, $field, $instance, $langtype, $items, $delta, $element) {
      $base = $element;

      if ($instance['widget']['type'] == 'prodlist_text') {
        $element['#element_validate'] = array('_prodlist_text_validate');

        $element['prod_type'] = array(
          '#type' => 'select',
          '#title' => t('Product Type'),
          '#default_value' => isset($items[$delta]['prod_type']) ? $items[$delta]['prod_type'] : NULL,
          '#options' => type_options(),
          ) + $base;

        $element['prod_description'] = array(
          '#type' => 'select',
          '#title' => t('Description'),
          '#default_value' => isset($items[$delta]['prod_description']) ? $items[$delta]['prod_description'] : NULL,
          '#options' => description_options(),
          ) + $base;

        $element['order_amount'] = array(
          '#type' => 'textfield',
          '#title' => t('Amount'),
          '#default_value' => isset($items[$delta]['order_amount']) ? $items[$delta]['order_amount'] : NULL) + $base;
      }
      return $element;

    }

function _prodlist_text_validate($element, &$form_state) {

  if ($form_state['complete form']['#form_id'] == 'field_ui_field_edit_form') {
    return ;
  }

  $values = $form_state['values'];
  $language = $values['language'];
  $field_name = $element['#field_name'];
  $field_name_error_box = $field_name;

  foreach ($values[$field_name][$language] as $delta => $item) {

    if (isset($item['order_amount'])) {

      if (is_numeric($item['order_amount'])) {
        if($item['prod_description'] != 'no order' && $item['order_amount'] <= 0 ){
          form_set_error($field_name_error_box, t('Order amount has to be more then 0'));
        } else if ($item['prod_description'] == 'no order' && $item['order_amount'] > 0) {
          form_set_error($field_name_error_box, t('You have created an order amount without selecting a product.'));
        }

      } else {
        form_set_error($field_name_error_box, t('Order amount has to be numeric'));
      }
   }

  }

}

I'm trying to set the variable $field_name_error_box = $field_name; to the correct value but it either lights up the whole form section or nothing at all.

I've tried the following, and lots of other variants without luck.

$field_name_error_box = $field_name . 'order_amount';


texts:
I have a few pieces to my existing puzzle:

Node Type  Snippet
View with Block Display called Snippets Block
A context rule to put the Snippets Block inside a container page

How to I tell a Views Block to only pull Snippets belonging to the same OG as the container page?

To start:

I've created the following relationship and contextual filter, but the containing page doesn't show the expected node teasers.

Node Type's Fields:

(view larger)

Current View set up:

(view larger)


texts:
I have created content type with multiple entries some of them have term reference / autocomplete.

Why cant i do that to the title for the content type?
Is there a way I can make that happen?

Also why can't I use the title in other content types?

Attached image with title .


texts: Show all users except profile being viewed (views, panel node)

texts:
I've got a view of type "users".  I have it filtered to a certain "role".  There are only 12 ppl in this role (it is for a calendar, and someone is sponsored each month).  When viewing a users profile I want to show a list of the other 11 below that user.  I currently have it listing all 12, I cant figure out a filter to exclude the current profile being viewed.

I have to be missing something easy


texts:
I created a marketplace there are two fields pue the product reference.

a "Store Reference" field that the store owner fills.
a "SKU" field I want it to be unique and generated automatically.

On Drupal Commerce I want the sku of my products to be generated automatically and that this code is unique.

I want a sequence of numbers and random letters, for example a single sku of 12 characters (number and letter).

There is a hash token in "Explore Available Tokens." and "Random". What is it used for ?

Can he meet my needs? Can it generate a unique code that will never be reused?

There are several store owners who can create products at the same time, the same sku must not be generated.


texts: Filter Search Result by current site language

texts:
I am using the core search module provided by drupal 8.2. I have the 'English' & 'French' language enable on the site. I want the search result to be filtered by the site language.How can i do it?

FYI: i am using the core search module.


texts: Should #process callback use #default_value or #value when expanding an element?

texts:
Background

The '#process' callback on a form element is called within form_builder(). It can be used to expand an element into sub-elements.

This is how e.g. the 'radios' or 'checkboxes' elements work: They behave to the outside as a single form element where the value is an array. But internally they are expanded to separate 'radio' or 'checkbox' sub-elements.

Optionally, there can be a '#value_callback' that acts as the counterpart of '#process'. This way, values are "translated" between the per-sub-element level and the super-element level.

My observation from form_process_radios() is that #process callbacks should use the #default_value from the parent element to populate the #default_value of the newly created sub-elements.

Question

I am writing ajax-powered elements that should expand into a different tree of sub-elements depending on the current form value. So not the $element['#default_value'] but the $element['#value'] or $form_state['input'] or $form_state['values'].

So in this case should I write a '#process' callback that looks into $element['#value'] instead of $element['#default_value']?

Note: I might figure this out for myself and just use "whatever works". On this platform I would love to see an answer that actually makes it all sound logical. Which is more than just "whatever works".

Another nice thing would be examples in existing code in core or contrib.


texts: Drupal 7 hook_theme() not loading template file

texts:
I'm trying to get a very simple module to load a template file using drupal's hook_theme(). It's pretty much as simple as you can possibly imagine.

function sectionheader_theme ( $existing, $type, $theme, $path ) {
  return array(
    'sectionheader' => array(
      'variables' => array( 'foo' => NULL ),
      'template' => 'sectionheader',
    ),
  );
}

The template is named sectionheader.tpl.php. The rest of the module is working as expected. I've cleared the Drupal cache. I've inserted a die("Debug") statement in this function, and it is being executed, but my template is simply not being called, ever. The template merely has some debug text in it so I can see that it's working, but is not visible in any view of the module.

I've done everything in every example I can find, I've even copied and pasted code directly from other modules, and this template will still not load.

I've tried renaming the template and the 'template' array value. No luck.


texts: How can I include a list of what a user ordered (the line items) in an e-mail sent by Drupal Commerce?

texts:
I want to send an e-mail that contains the content of a user's Drupal Commerce order (the line items) with Rules.

I tried modifying the default Send an order notification e-mail (in Rules) provided by Commerce.  I noticed that there was a [commerce-order:commerce_line_items] token, but when I insert this into an e-mail, I get a message of No line items found when the e-mail is sent, even though the order has line items.  What am I doing wrong?


texts: drush appears to not be respecting --no-backup

texts:
My server has a great backup system in place.  I do not need additional backups dropped into my home directory.

Reading the drush docs gave me the impression that the --no-backup option, would instruct drush to not make a backup.

$ drush --version
drush version 4.5

When I update a module with the --no-backup option it seems to be ignored.

$ ls ~/
creds
$ drush dl drush --no-backup --yes
Would you like to back up your current drush version 4.5 to /home/username/drush-backups/unknown/20110823223228 and replace it with drush 4.5? (y/n): y
drush backed up to /home/username/drush-backups/unknown/20110823223228/drush  [ok]
Project drush (7.x-4.5) downloaded to                                [success]
/srv/www/_drupal_.example.org/drush.
Drush successfully updated to version 7.x-4.5.                       [success]
$ ls ~/
creds  drush-backups

Am I missing something obvious here?  I have tried changing the order of the parameters, but that doesn't seem to make any difference.


texts: How to create programmatically menu links with just created nodes during installation profile in aegir ?can't get nid!

texts:
I am creating a set of nodes in an installation profile.  When I try to create menu links for them in the same PROFILE_NAME.install, the links don't get created.

I have also tried creating the menus links in a separate module, and using hook_update_N() to enable them, but that also does not work.

When I uninstall the module and reactivate it, it creates correctly my menu's links correctly.

I tried to use hook_install_tasks() and put it in MYPROFILE_NAME.profile or MYPROFILE_NAME.install, but this also doesn't work.

How can I create menu links for nodes created as part of an installation profile?

My code for creating the nodes in MY_PROFILE_NAME.install is:

// creation of my nodes (same content for all)
   $nodi = array(
       // i have other 14 nodes
      'title' => array('Home'),
       // i have other 14 paths for the nodes
      'path' => array('home'),
   );
$titoli = array();
$titoli = $nodi['title'];
$percorsi = array();
$percorsi = $nodi['path'];
//CREAZIONI DEL CONTENUTO PROGRAMMATICAMENTE
  for($i = 0; $i< count($titoli); $i++){
$testo_body = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat velit eget metus placerat,varius eros facilisis. Aenean aliquam imperdiet nisl ut dapibus...';
           $node = new stdClass(); // nuovo oggetto nodo
           $lingua = 'it';
           $node->type = "page"; //
           $node->title = $titoli[$i];
           $node->language = $lingua;
           $node->path = array('alias' => $percorsi[$i]); // i think here is the problem !!!
           $node->uid = 1; // admin
           $node->status = 1;
           // Body field
           $body_field_info = field_info_field('body');
           if (field_is_translatable('node', $body_field_info)) {
              $body_lingua = field_valid_language($lingua);
           }else{
              $body_lingua = LANGUAGE_NONE;
           }
           $node->body[$body_lingua][0]['value'] = $testo_body;
           $node->body[$body_lingua][0]['summary'] = 'text...';
           $node->body[$body_lingua][0]['format'] = 'full_html';
           $node = node_submit($node); // Prepare node for a submit
           node_save($node); // After this call we'll get a nid

And my code for creating the menu links is:

    // Create a Home link in the main menu.
  $path = drupal_lookup_path('source', 'home');
  $item = array(
    'link_path' => $path,
    'router_path' => $path,
    'link_title' => st('Home'),
    'menu_name' => 'main-menu',
    'weight' => -50,
    'customized' => 1,
    'plid' => 0, // Parent menu item, 0 if menu item is on top level
  );
  menu_link_save($item);
  menu_rebuild();

Update 2

The menus are created in the menu_links table but with empty link_path so i can't get the nid created nodes.
I treid also to override the install_finished() and put my function for creating menus in .install or in .profile files, but it's the same.
Any ideas?


texts:
I have two blocks in a custom module.

function THEME_block_info(){
    $blocks = array();

    $blocks['contact_info'] = array(
        'info' => t('Contact Info Block'),//admin ui block name
    );
    $blocks['contact_form'] = array(
        'info' => t('Contact Form Block'),//admin ui block name
    return $blocks;
}

function THEME_block_view($delta = ''){
    $block = array();

    switch($delta){
        case 'contact_form':{
            $block['subject'] = t('');
            $block['content'] = build_contact($delta);
            break;
        }
        case 'contact_info':{
            $block['subject'] = t('');
            $block['content'] = build_contact($delta);
            break;
        }

}

These blocks show up in the admin UI where we are able to order them. However, the order set in the admin UI doesn't work.

How should I set the order of these custom blocks to make it match the one sets in through the UI?