texts: How do I render a Twig template and load a CSS file from a controller?

texts:
Is this considered a good practice for rendering a Twig template and loading a CSS file from a controller?

DefaultController.php

namespace Drupal\acme\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Template\TwigEnvironment;

class DefaultController extends ControllerBase implements ContainerInjectionInterface
{
  /**
  * @var Drupal\Core\Template\TwigEnvironment
  */
  protected $twig;

  public function __construct(TwigEnvironment $twig)
  {
    $this->twig = $twig;
  }

  public static function create(ContainerInterface $container)
  {
    return new static(
      $container->get('twig')
    );
  }

  /**
   * hello
   * @param  string $name
   * @return string
   */
  public function hello($name)
  {

    $template = $this->twig->loadTemplate(
      drupal_get_path('module', 'acme') . '/templates/hello.html.twig'
    );

    $markup = [
      '#markup' => $template->render([ 'name' => $name ]),
      '#attached' => [ 'css' => [
          drupal_get_path('module', 'acme') . '/assets/css/acme.css'
        ]
      ]
    ];

    return drupal_render($markup);
  }
}

acme.routing.yml

acme_hello:
  path: '/acme/hello/{name}'
  defaults:
    _content: '\Drupal\acme\Controller\DefaultController::hello'
    _title: 'acme Title'
  requirements:
    _permission: 'access content'

hello.html.twig

Hello {{ name }}!


texts: Twig find if a css class exists in a tag

texts:
Is there a way to find out if a css class exists in a specific tag through twig?
For example:
<body class="new-class">

Then I'm able to do a conditional statement in twig based if new-class exists.
Is this possible?


texts: Create dynamic text fields on form based on other entities

texts:
I've created an entity which has fields that users need to fill out. As part of that entity there is a reference field back to a content type 'food'.
The 'food' content type has it's own entity reference called 'sections'.
When a user selects a 'food', i want to dynamically add each 'section' as a title with a textarea box underneath which gets stored against the original entity.
Considered using paragraphs as the 'sections' but they need to be reusable on different 'food' nodes. Also checked the dynamic fields module but this doesn't look like it's well supported.
Fallback approach is going to be to programmatically create a field for each 'section' item as they are added, but with this we could end up with hundreds of fields.
Any ideas on how else this can be done programmatically?


texts: How to display date in Calendar's week view?

texts:
I'm using the Calendar module. In the week display (not minicalendar), I would like to display the date ("January 21, 2015") in the heading in addition to the weekday ("Wednesday"), with the current date highlighted.

I've worked with calendar-week-overlap.tpl.php, I can see that the weekdays are written in a loop:

<?php foreach ($day_names as $cell): ?>
    <th class="<?php print $cell['class']; ?>" id="<?php print $cell['header_id']; ?>">
      <?php print $cell['data']; ?>
    </th>
  <?php endforeach; ?>

The documentation at the top of this file refers to several promising looking variables: $rows['date'], $rows['datebox',  $min_date_formatted, but if I try to use them inside this loop I get a PHP error stating that each of these variables does not exist!

$cell['data'] contains the weekday only.

The documentation also refers to implementing my own theme_preprocess_calendar_week_overlap function, but I don't see where I can safely get and store the date for each day in this function.


texts:
i've developed a project using Nice Menus module, but on mobile can't use well with submenus. So i thought to use JS injector to listen swipe on screen and make menu visible.
i wrote this code

$(document).ready(function(){$("#second-column").on("swipe",function(){
      if($(window).width()<=900)
        $("#nice-menu-1>li>ul").css("display: block; visibility: visible;");
  });
});

but chrome console said $ is not a function so i search and replace $ with jQuery, now i've no moar message but it doesn't work.

Thanks in advance for help


texts:
I was told I should use GUID and tick Unique setting for best method of filtering out duplicate content each time cron runs. But what do I set GUID to? My XML sources has like only ,  etc.

Now I am using Title as unique for duplicates. But I get lots of random issues, Feeds Import doesn't import all feeds after each cron, or even better, it gets stuck e.g. 'Importing 48%' and etc.

I got 4 feed imports that parse XML from external site, all from same site (also Drupal). Also I use custom module to trigger them when running cron, because by default Feed Import doesn't even react to hourly cron.

So trying various solutions, maybe this GUID thing will solve this.

I also use XPath XML parser.


texts: Filter taxonomy terms in autocomplete list by boolean field on vocabulary's terms?

texts:
I need to implement a boolean field for a vocabulary that determines whether terms within a vocabulary appear in autocomplete results for a taxonomy term reference field's autocomplete widget. The function taxonomy_autocomplete(...) has the query that I want to modify. But how can I modify the query or override the results of the autocomplete json callback?

I know how to add the boolean field to the vocabulary but not how to filter autocomplete results. The idea is to let users enter new terms but not have their new terms appear in autocomplete results unless approved by an admin.


texts: How to password protect terms in Taxonomy

texts:
I have a taxonomy vocab "region"
in the region, I have a bunch of provinces as the terms, and subpages for each province.

I would like to add a password protect or only allow authorized users to access the provinces.

etc, only username "ontario" "password" can access the term "ontario" in the taxonomy. Is this possible?


texts: Webform theming field labels through webform-form.tpl.php

texts:
I'm theming a Webform I created by using a custom webform-form-[nid].tpl.php template. I've been able to render individual fields fine, but I'm having a problem with the date field which is split into 3 fields (month, day, year).

To wrap each item in custom HTML, I render each of those fields like this:

 <?php print drupal_render($form['submitted']['birthdate']['day']); ?>
 <?php print drupal_render($form['submitted']['birthdate']['month']); ?>
 <?php print drupal_render($form['submitted']['birthdate']['year']); ?>

But the label is automatically being rendered separately, so how can I render it manually?

This is the output that I'm getting: (simplified for ease of understanding)

    Month
    <select name="submitted[birthdate][month]">
      <option selected="selected" value="">Month</option>
      <option value="1">Jan</option>
      ...more options...
    </select>

    Day
    <select name="submitted[birthdate][day]">
      <option selected="selected" value="">Day</option>
      <option value="1">1</option>
      ...more options...
    </select>

    Year
    <select name="submitted[birthdate][year]">
      <option selected="selected" value="">Year</option>
      <option value="2014">2014</option>
      ...more options...
    </select>

  Birthdate

So I need to somehow print that "Birthdate" label manually so I can place it wherever I need, like so:

row
  column label
  column month
  column day
  column year
/row

I need to do this so I can wrap each element with CSS classes for a responsive grid.


texts: Is there an option in the Views 3 UI to reset one section of a non-master display to the default state?

texts:
I've got a view that contains several different displays.  When I override an option for a single display, the header for that section is displayed in italics.  For example, if I override the Filter Criteria for a single display, Filter Criteria is shown as Filter Criteria on that display.

Is there a way to revert overridden sections (Filter Criteria, Fields) from within the UI if I change my mind about overriding?  Of course I can manually re-create the settings to match those of the master, but this is a pain...


texts: How to prevent Drupal from scrolling to the bottom of ajax-appended content in a form

texts:
I have a custom form in Drupal.

When a user first sees this form, the only thing on the page is a select box, along with a few other elements they have to fill out.

When they make a selection from the select box, the #ajax callback regenerates the form, and adds about 50 results to the page.

By default, Drupal is scrolling down to the last result.  This is a problem, because the users have to scroll back up to the elements near the top of the page to finish their work.

Is there a way to prevent Drupal from scrolling to the bottom of the newly-added form content?

Here is a snippet that shows how I'm setting up the form:

$form = array(
'#tree' => TRUE,
'#prefix' => '
',
'#suffix' => '
',
);

Here is a snippet from the select box that triggers returning the results.

$form['selectbox'] = array(
  '#type' => 'select',
  '#title' => t('Select box'),
  '#options' => $predefined_select_options,
  '#empty_option' => t('Select something!'),
  '#ajax' => array(
    'callback' => 'mymodule_form_ajax',
    'wrapper' => 'myform',
    'effect' => 'fade',
  ),
);

$form['other_stuff'] = array(
  '#type' => 'textfield',
  '#title' => t('Other stuff they need to fill out here'),
);

if (isset($form_state['values']['select box'])) {
  foreach ($lots_of_results as $result) {
    $form[$result] = array(
      '#type' = 'fieldset',
      '#title' = 'Lots of results in their own field sets',
    );
  }
  // It scrolls to the bottom of this huge list after it's rendered.
}

Here is the ajax handler for the select box.

function mymodule_form_ajax($form, $form_state) {
  return $form;
}


texts:
I managed to create a gallery and show it under a page (creating a view of type page).

What I really need is having one different gallery associated for each article, so I created a view of type "block", but the showed gallery is always the same, while it should related to the current article.


texts: Set Parent Item when using Migrate module

texts:
I'm migrating content from an old site using a CSV file. I have my own module setup that is importing all the other data using this documentation.

Because this site is very large and has a very complex hierarchy, I'm hoping to set the Parent Item when migrating the content over. I don't see a destination for this type of data in the Migrate UI. Is there a way to do this?

I did see this class but it doesn't seem to be documented.

Any help would be appreciated. Thanks!


texts: Imagemagick error convert delegate failed `'cwebp'

texts:
i'm following this guide
I've installed Imagemagick, run
composer require drupal/imagemagick
drush en -y imagemagick

and all next steps.
After add convert to WEBP to specific image style, receive this error:
ImageMagick error 1: convert: delegate failed `'cwebp' -quiet -q %Q '%i' -o '%o'' @ error/delegate.c/InvokeDelegate/1919. [command: /Applications/MAMP/bin/apache2/bin/convert '/Applications/MAMP/htdocs/mysite/sites/default/files/2020-10/image.png' -resize 406x376! -crop 336x376+35+0! -quality 70 WEBP:'/Applications/MAMP/htdocs/mysite/sites/default/files/styles/image_336x376/public/2020-10/image.png.webp']

But if run this command in my Terminal:
/Applications/MAMP/bin/apache2/bin/convert '/Applications/MAMP/htdocs/mysite/sites/default/files/2020-10/image.png' -resize 406x376! -crop 336x376+35+0! -quality 70 WEBP:'/Applications/MAMP/htdocs/mysite/sites/default/files/styles/image_336x376/public/2020-10/image.png.webp'

convert correctly
My OS is Macos Catalina 10.15.7, i've installed yet webp with homebrew


texts: When to use BaseFieldDefinition instead of hook_schema

texts:
While creating a new information for Drupal 8, I came across 2 approaches to create a new column on the entity table on database:
* use hook_schema() (as I was used on Drupal 7) (https://gist.github.com/pedrorocha-net/3ed63f33b513d9c9ff86)
* extends ContentEntityBase and use BaseFieldDefinition (https://gist.github.com/pedrorocha-net/70d6a84c3ddba1c5939d)

Both alternatives creates the table for me, with the data, but I think the latter already provides me more integration with other Drupal components e.g. Views module. By the other hand, being an "Entity" I believe brings some "weight" to the data, as it works with some wrappers(on Drupal 7 at least).

What i'm doing is port the Voting API module, so this question about extra weight can really impact on sites with more content.

Any thoughts?


texts: Is there a way to have a single field behave as a text field and a file upload/browser at the same time?

texts: I need an option for users to have a single field behave as both a textfield so they can enter an external url or browse/upload field depending on which one they want to use. Having two fields will be confusing for users. Is this possible?


texts: Cannot uninstall modules due to missing table br_schedule

texts:
When I hit the Uninstall tab in the UI or try to uninstall a module with Drush I get the following errors:

Drush:

SQLSTATE[42S02]: Base table or view not found:
1146 Table 'DATABASENAME.br_schedule' doesn't exist

Drupal Log:

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]:
Base table or view not found:
1146 Table 'DATABASENAME.br_schedule' doesn't exist:
SELECT base_table.vid AS vid,
base_table.id AS id FROM {br_schedule}
base_table LIMIT 1 OFFSET 0; Array ( ) in
Drupal\Core\Entity\EntityStorageBase->hasData()
(line 552 of MYSITEPATH/core/lib/Drupal/Core/Entity/EntityStorageBase.php).

I have no idea what br_schedule is so I don't know how to rebuild that table. I have Businesses Rules installed but I see no br_schedule module.


texts: Multiple currencies in commerce kickstart

texts: How to make different prices for one product.I want to display product price in both currency that is euro/$ without any currency selector.


texts:
We have a Drupal site that exposes a JSON API for users (http://site1/api/users).

We need to create on site2 a view of users based on the data provided by site1. (We cannot store the users on site2).

How can I use a view on site2 that consumes data from site1? Which hook should I use? What approach should I follow?


texts:
I am trying to create multiple bundles for a given entity.

However, when I'm doing this, all of my manage field and manage displays are on the same page, and it doesn't appear like any of the other pages are working.

Here's one of the bundles:

  $info['gov_data'] = array(
    'label' => t('Government Data'),
    'base table' => 'gov_data',
    'entity keys' => array(
      'id' => 'gid',
      'label' => 'type',
    ),
    'module' => 'gov_data_entities',
    'access callback' => 'gov_data_access_callback',
    'fieldable' => TRUE,
    'bundles' => array(
      'bill' => array(
        'label' => t('Bills'),
        'admin' => array(
          'path' => 'admin/structure/gov-data/bill',
          'real path' => 'admin/structure/gov-data/bills',
          'access arguments' => array('administer site configuration'),
        ),
      ),
  'committee' => array(
    'label' => t('Committee'),
    'admin' => array(
      'path' => 'admin/structure/gov-data/committee',
      'real path' => 'admin/structure/gov-data/committee',
      'access arguments' => array('administer site configuration'),
    ),
  ),
),
    'admin ui' => array(
      'path' => 'admin/structure/gov-data',
      'controller class' => 'EntityDefaultUIController',
    )
  );

There are about 6 or 7 more exactly like that.

Why are they all showing up on the main entity page?

How do I organize this so that it looks like content types?

EDIT: Here's my hook_menu() for the person asking:

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

  $items['admin/config/services/gov-data'] = array(
    'title' => 'Government Data settings',
    'description' => 'Configure settings for Government Data',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('gov_data_admin_settings'),
    'access arguments' => array('administer site configuration'),
  );
  return $items;
}


texts: Is this a reasonable use of hook_user_presave?

texts:
The documentation for hook_user_presave says that

  This hook is primarily intended for modules that want to store properties in the serialized {users}.data column [...]

Instead, I'm using it to check that a change of email address does not clash with any email address in a database separate from the database for my drupal site. If it does, I do

$edit['mail'] = $account->mail;

so that the update to mail does not go through, but the rest of the edit is unaffected. (I also put up a warning message, under the assumption that the only time the email changes is when someone changes it manually.)

With anything web-related being outside my usual field, I'm not sure if using this method in a different way than intended is too clumsy or unsafe. Is it ok to use this method in this way?


texts: How to add custom input type button in forms?

texts:
I want to add custom input type button in form.
I tried following code, but it is converting it to submit type button.
How can i add  input type button ?

$form[custom_button] = array('#type' => 'button','#value' => t('Test Button'),);


texts: How do I add CSS body classes for logged-in and logged-out users?

texts:
In Drupal 7 I would add a theme process function to add the body classes needed.

function template_preprocess_html(&$variables) {
  $variables['classes_array'][] = $variables['is_front'] ? 'front' : 'not-front';
  // Add a class that tells us whether the page is viewed by an authenticated user or not.
  $variables['classes_array'][] = $variables['logged_in'] ? 'logged-in' : 'not-logged-in';
}

In D8 this theme function exists but they don't have all the variables need for users.


texts:
Is it possible to use hook_form_alter() on a hook_form_alter() function already defined in another module?

For example, if I want to alter the output of the following hook from the menu module, can I define a function which allows me to alter the renderable array?

function menu_form_node_type_form_alter(&$form, $form_state) { ... }

I have looked at the documentation but can't seem to find anything that suggests this is allowed/possible.


texts: How do I log in as a different user when there isn't a login link on the front page?

texts:
I created a user with limited rights and logged in as that user.

Now I have discovered that I have not placed a login module on the front page.

How do I log back in as administrator?


texts:
Fairly new to Drupal, trying to determine what kind of performance we should expect from a stock Drupal install, with the optional modules (not the barebones option).

We have a fresh dedicated Win 2008 server, 16GB RAM, 8 cores, etc. Hardware shouldn't be an issue.

Latest release of Drupal 7.x. FastCGI. WinCache enabled. MySQL with innoDB.

Load times: 1100-1300ms. Seems crazy high for a FRESH Drupal install (Bartik theme), no custom modules. This is authenticated user, so caching isn't really coming into play.

So, I'm curious, what's the fastest perf we should expect from a fresh Drupal install? Please list your stack (IIS, Apache, etc), your load speeds (code processing time/database query time). We're using the devel module (the only extra module) to collect the speed stats.

I don't see how Drupal can be useful without getting down to ~100ms with stock modules, ideally faster. Maybe we have a configuration problem, but this is exactly the same speed we're seeing in the dev environments.


texts: How to attach a library to a specific block

texts:
I wonder how to attach a library to a specific block. I do this:

in mytheme.libraries.yml

   lib-name-script:
      js:
        header: true
        js/masonry.pkgd.min.js: {}
        js/main.js: {}
      dependencies:
        - core/jquery

in main.js

jQuery(document).ready(function() {

    $('.grid').masonry({
        itemSelector: '.grid-item',
        columnWidth: 220,
        horizontalOrder: true
    });
});

and in views-view--block-some.html.twig

{{ attach_library('theme_name/lib-name-script') }}

<div class="grid">
    {{ rows }}
</div>

But from some reason this dont works. :S

On the and of file I have:

<script src="/themes/theme_name/js/masonry.pkgd.min.js?oxcmsf"></script>
<script src="/themes/theme_name/js/main.js?oxcmsf"></script>

Was I corect load js, or mistake is on some other place?


texts: Why does "my blog" menu link disappear when I use a view with the path blog/%?

texts:
When I create a view with the path blog/%, the menu link "My blog" disappear from the main menu but still exists in the database. The view works exactly as expected when I go to /blogs and click the nav link at the bottom of the article.

Already tried without success (logged in as administrator)

1) Change view access to:

none
permission: view published content
permission: blog entry:
create new content role: authenticated users

2) Add/Remove the view filter: status published

3) Create a new menu link using Menu Token module but this link disappears too (but still exists in the db).

4) Enable/disable Menu Token and Menu item visibility modules, just to check if there is a conflict somewhere but it doesn't change anything.

Versions:

Drupal 7.31
Blog 7.31
Views 7.x-3.8.
Menu Token 7.x-1.0-beta5
Menu item visibility 7.x-1.0-beta1


texts: How to create a checkbox field in a node for Terms and Conditions

texts:
I need a field to ensure the users who create a node accept my Terms and Conditions. I've gone as far as creating a boolean field and making it a required field but I don't know how to:

1) Disallow node creation if the checkbox isn't checked, and modify the node creation rejection message.

2) Only make the field required for non-admin roles.

3) Insert a label for the checkbox with html markup so that I can link part of the text.


texts:
Is there any module to put blocks under menu items? I will use it to create mega menu. I mean something to generate this code:

    Item

...


texts:
I have a block like this:

Languages

Nederlands

English

Français

(From the language switcher module)

But now I would like to have something like this:

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

Action

Another action

Something else here

Separated link

Where do I have to change this?


texts: "Route "ctf.content" does not exist" when installing custom module

texts:
I tried writing my own copy of the skeleton module from https://github.com/sidharrell/D8HWexample.git modules/custom/hello_world, but I thought I'd start by changing the module name and using "ctf" instead of "hello" in the routes. I tried to install the module but I got an exception.

  Route "ctf.content" does not exist

I deleted my module folder from beneath the custom folder and reloaded the page, but I still get this error. The site is now unusable.

Do I need to reinstall or is there an easy way to flush the cache or uninstall the module? I don't have drush installed (yet).


texts: How to apply multiple sort criteria on views?

texts:
I have created a view where I used

  Display a specified number of items | 5 items

And I have 2 sort criterias.

  SORT CRITERIA

  Add sort criteria

  List additional actions Content:

  Authored on (desc)

  Content: Page Views (desc)

What I want is sort criteria 1 should be applicable on first 3 rendered items, and sort criteria 2 should be applied on next 2 items. So here right now, total 5 items are displaying. From them, I want first 3 items to pass from sort criteria 1 and other 2 items from sort criteria 2.

How this can be achieved?


texts: Return URL of ubercart after successful payment

texts:
I created a third party payment gateway integrate with ubercart. I manage to redirect to third party payment gateway once check out. I am able to return url but I cant change statue to complete? I get this info from: http://nmc-codes.blogspot.ca/2012/07/how-to-create-custom-ubercart-payment.html

I set my return url as this: http://www.example.com/cart/mypayment/complete", but page not found.

What should I do?

Here is my code:

 function uc_mypayment_menu() {
    $items['cart/mypayment/complete'] = array(
    'title' => 'Payment Complete',
    'page callback' => 'uc_mypayment_complete',
    'page arguments' => array(1, 2),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

function uc_mypayment_complete() {

  if (empty($_POST)) {
    watchdog('My Payment Gateway',
             'Received an empty or incomplete response.  Response details: @request_details',
             array('@request_details' =>  print_r($_POST,true)), WATCHDOG_ERROR);

    return 'There was a problem with your payment';
  }

  if ($_POST['status'] == 'SUCCESS') {

    uc_payment_enter($order_id, 'my_pay_gateway', $amount, $order->uid, NULL, $orderId);
    uc_cart_complete_sale($order, variable_get('uc_new_customer_login', FALSE));

    return 'Thank you for your purchase';
  }
}


texts: Custom layout for a field in Drupal 7 with using a term id and term name

texts:
I have a content type that has term reference fields. One is a select one and one is a select many. What i'm trying to achieve is to overwrite the output for these fields.

I want the output of these 2 fields to be {artistName} and {locationName}, {locationName}

These links will point to a page with an isotope grid layout on it, and will prepopulate the filters with what is in the querystring.

I have found how to update the output of the field, but I have no idea on how to get the terms ID and terms name.

function TEMPLATENAME_preprocess_field(&$variables) {
  if($variables['element']['#field_name'] == 'field_artist') {
      $variables['items']['0']['#markup'] = 'View Map';
    }
  }
}

Thanks.


texts: How to expose a select field to a Rules Condition?

texts:
In Drupal 7, I have defined a new content type which has a checkbox field . The idea is that when a user chooses option A and submits the content, the system does something after the creation of the node, say, send an email to the webmaster and if the user choose option B or C while creating the content, the system do nothing.

I've had difficulty to expose the select field result to a Rules Condition and I'm even not sure whether it is possible, so appreciate your help.


texts: What happens when you choose a default country during installation?

texts:
In the last step when you install Drupal 8 under "Configure site" you can choose a "default country":

However no clues are provided about the option...

What happens when you choose a default country for the site?
And what happens when you just leaves it as "none"?


texts: How to restrict node access based on viewer use role and node author user role?

texts:
I have two Profile2 profile types, and each one automatically applies a specific user role to the user account:

Man
Woman

All users have the ability to add a specific type of node... let's call it "Event".

Man users should never see other Man-user-created events. They should only see Woman-user-created events

Woman users should never see other Woman-user-created events. They should only see Man-user-created events.

I already have the permissions set up where Man users cannot view other Man user profile pages, and likewise for Woman users. How can I apply that same logic/permission restriction to the content those user types create?


texts: How can I include a third party library in my custom module without using Composer Manager

texts:
I'm trying to create a custom Twitter Pull module in Drupal 8.  I would like to include https://github.com/abraham/twitteroauth.

I can't seem to get it working adding it via composer in the root composer.json file, or by using Composer Manager and creating a composer.json file in my module root, so for the sake of this question, how else can I include and make use of the library?

Can I add a dependency to my custom module .yml file?
How would I handle the namespacing/autoloading for this library in my custom module?


texts: How to get a list of all javascript files in a directory

texts:
Is it possible to get a list of all the javascript files in the libraries directory? So far I have tried using files_scan directory but it's not returning anything:

$dir = base_path() . 'sites/all/libraries/';
$files = file_scan_directory($dir, "/.*\.js$/");
dpm($files);

many thanks.

EDIT

I changed to using DRUPAL_ROOT. This gives the correct path and returns an array of js files but there is a double slash // in the uri just before the file names: /var/www/html/droop/sites/all/libraries//d3/d3.min.js

$dir = DRUPAL_ROOT . '/sites/all/libraries/';
$files = file_scan_directory($dir, "/.*\.js$/");
dpm($files);


texts: Problem visualizing the rating value inside a view

texts:
I'm using the Voting API and Vote Up/Down modules. My problem is that I can't display the vote result in a view.

What I've done is creating a relationship ("Node: Vote results") and used "Vote results: value" as field.

I'm getting a vote counter, but it always shows zero, even if I am voting inside a node. By the way, inside a node the vote counter is displayed correctly.


texts: Drupal 8 add javascript and pass data in a hook with custom module

texts:
I am building a custom module with Drupal 8. One of the requirements of the module is that it sets up a javascript file based on the configuration settings, which the user of the module sets up in module configuration.

The javascript which needs to be added to the page depends on the configuration settings. Hence I can not add it using Libraries as mentioned in this article: Adding assets to Drupal module.

I first implemented it using a block. I use Twig templates to pass the configuration variables in PHP to the twig file, and in the twig file, I have a <script> tag to add the javascript based on the config variables. Refer Using twig templates.

The problem with this approach is that user needs to add the block on the page, and there is no UI facing element on that block. I also find it very messy.

Is there a cleaner way to add my javascript using hook and pass variables to it? I looked around and found hook_install and hook_page_attachments. So I can add Javascript, but don't know how I can pass any php variables to it.

I am new to Drupal development. Any help with this is really appreciated.

TL;DR I need to find a way to add Javascript using Drupal hook and pass some PHP variables to it.


texts: drupal 7 create a user profile view using user relationships fields

texts: I would like to create a view using the user relationships module as well as the profile2 module. I know you can use the concept of view relationships as they act like a join  other tables together. views Relationships and argument? I am wondering the best way to assemble this with the profile fields and the relationships fields in a view. What would some best practice principle be. I also know I will need to use conceptual filters so that each user will have there own profile page. Should i extend the functionality of the user relationships browser view which has a path for each relationship or should i create my own view from scratch


texts: Play Buttons of SoundManager2 are disabled in Ajax o JS

texts:
I have a views that call a content type with soundmanager fields (360 style) with pager.

On the first page show 3 soundmanager fields and play ok, but in the second page by ajax the no longer played in the input play btn.

In the second page the input play not function.

I tested with 3 options:
Infinite scroll module.
Custom js code for the scroll in the same page.
Views Module load more.

In all feel the same, in the second page loaded in ajax or js buttons play of SoundManager are disabled.

appreciate your help


texts: Is there any way to alter the "field type" of a field?

texts:
I need to change the field type "file" to "image" in drupal 7. I just hack the database and found a table named "field_config" and modified the "type" and "module" column, from "file" to "image". I found that it's works correctly.

My question is that, is this the correct way to change the "field type" of the field? Any better answer would be appreciated. Thanks in advance.


texts:
How can I insert a simple google map in a block?

I have a contact page with a contact-form (that one can fill in and send),
and I want to add to this page a google map.

thanks alot in advance!


texts: Drupal 7: can't get ckEditor module configured for inline editing

texts:
Drupal 7: I using ckEditor module for editing within the textarea fields and I noticed on the ckeditor website that you can do inline editing like:
http://ckeditor.com/demo#inline

I can get the ckEditor module to work for regular editing but I can't seem to get it configured for inline editing like the demo listed above.


texts: How to add a CCK field to custom template file?

texts:
I am working on a Drupal 7 site, and I am setting up a template that will be used with the Print module when PDFs are created using that module. The PDFs will draw from pages that list specifications of products, and the PDF itself will act as the printed spec sheet.

I want to completely customize the output of the PDF so that I can choose where each and every field will be placed. Unfortunately, the PDF creation is currently not respecting all of the layout specifics on the website page, so I have decided to customize the print.tpl.php file (part of the Print module) to enact those specific layout elements.

The part I am stuck on is... how do I call in the various individual fields/fieldsets from the content item and have them show up on the template file for printing? For instance, the content type is "Shirts" and one of the fields in question is "Color" ("field_shirtcolor")... how can I access that field/print that field in my custom tpl file?

Thanks!


texts: Cannot change checkboxes options in drupal form using AJAX callback

texts:
I am trying to apply the #options value of a checkboxes in a form inside a Ajax callback.

Even after using $form['tags']['table']['#options'] = $final; the value in the form is not changing.

I have tried printing the #options value in the watchdog and the value seems to have changed.
But it is not getting reflecting on the form page.

The form field which needs to be updated

$form['tags']['ask_button'] = array(
      '#type' => 'button',
      '#value' => t('Next'),
      '#ajax' => array(
        'callback' => 'ajax_tag_callback',
        'wrapper' => 'replace_tagfield_div',
      ),
    );
$form['tags']['question_tags'] = array(
      '#title' => t("Tags"),
      '#type' => 'textfield',
      '#prefix' => '
',
    );
$form['tags']['table'] = array(
      '#type' => 'checkboxes',
      '#options' => drupal_map_assoc(array(t('SAT'), t('ACT'))),
      '#suffix' => '
',
    );

The Ajax callback

function ajax_tag_callback($form, &$form_state) {
\\some code\\
  $final = drupal_map_assoc(array(t('SAT'), t('ACT')));
  $form['tags']['table']['#options'] = $final;
  $form['tags']['question_tags']['#value'] = $tag_names;
\\returned the form here
 return $form['tags'];
}

Even after returning the form field, my form is not getting updated. Please suggest me a solution..


texts: Ajax callback on select box change event not working on second time

texts:
I am building a form with form API in a custom module. Certain fields should be populated based on the selected value of a dropdown.

User will select the pre-entered profiles, based on which other fields should be populated.

I have used ajax callback on select box, it works fine for the first time. But not working on next time.

function multi_step_user_info_form($form, &$form_state) {
$form['user_data_form']['reference_number_ajax'] = array(
'#type' => 'select',
'#title' => 'Select a Patient',
'#ajax' => array(
        'callback' => 'ref_number_dropdown_callback',
        'wrapper' => 'ref_number_list',
        'event' => 'change',
        'method' => 'replace',
        'effect' => 'fade',
        ),
'#attributes' => array('class'=>array('dynamic-select')),
'#default_value' => isset($values['reference_number_ajax']) ? $values['reference_number_ajax'] : NULL,
'#prefix'=>'
',
'#field_suffix'=>'
');

$form['user_data_form']['patient_name'] = array('#type' => 'textfield',
'#title' => 'Patient Name','#value' => $patient_name, '#default_value' => isset($values['patient_name']) ? $values['patient_name'] : NULL,
'#prefix'=>'

',
'#field_suffix'=>''
 ); return $form; }

function ref_number_dropdown_callback($form, $form_state) {
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node')
      ->entityCondition('bundle', 'query')
      ->propertyCondition('status', NODE_PUBLISHED)
      ->fieldCondition('field_reference_number', 'value', $form_state['values']['reference_number_ajax'], '=')
      ->range(0, 1);
    $result = $query->execute();
    $nid ='';
    if (isset($result['node'])) {
       $nid = $nid = current($result['node'])->nid;
       $node = node_load($nid);
    }
  //  $form_state['rebuild'] = TRUE;
  // THESE TWO VALUES SHOULD BE POPULATED ON AJAX CALLBACK //
    $form['user_data_form']['patient_name']['#value'] = $node->field_patientname[$node->language][0]['value'];
    $form['user_data_form']['age']['#value']          = $node->field_age[$node->language][0]['value'];
    $elements = array($form['user_data_form']['patient_name'],$form['user_data_form']['age']);
    return $elements;
  }


texts: Require input for optional field select widget

texts:
(My own use case is about taxonomy term reference fields. But a more generic answer is welcome.)

A taxonomy term reference field, single value, not required, with a select widget that shows all terms of the field.

The user should be allowed to leave the field empty, which would mean e.g. "not known" or "none" etc.

But I want the user to make an active choice, and not just skip the field out of laziness.

There could be the default option "- Please choose -", which would be separate from the "- None -" option. Submitting the form with "- Please choose -" would fail element validation.

This would only apply to the (node) creation form. When editing a node where the term is "none", there would be no "- Please choose -" option.

I know I could do this with a new (custom) widget type or with a form alter hook, by adding a new option that will fail validation.

But I wonder if there is an existing solution out there.


texts:
Is it possible to remove the default value an exposed filter (implemented by the Better exposed filter module) in a view? I would like to have users choose a value.

I tried using this in the template file, but nothing changed.

function custom_theme_form_views_exposed_form_alter(&$form, &$form_state) {
  // dpm($form);
  if ($form['#id'] == 'views-exposed-form-betterexposed-page-1') {
    foreach(element_children($form) as $key => $value) {
      if (isset($form[$key]['#type']) && $form[$key]['#type'] == 'select') {
        array_shift($form[$key]['#options']);
      }
    }
  }
}

The HTML markup is now the following.

<form action="/be1" method="get" id="views-exposed-form-betterexposed-page-1" accept-charset="UTF-8" class="jquery-once-1-processed">

            Published

 <input class="bef-select-as-radios form-radio" type="radio" id="edit-status-1" name="status" value="1" checked="checked">  Yes

 <input class="bef-select-as-radios form-radio" type="radio" id="edit-status-0" name="status" value="0">  No

      <input type="submit" id="edit-submit-betterexposed" name="" value="Apply" class="form-submit">

</form>

I also tried the following code.

function custom_theme_form_views_exposed_form_alter(&$form, &$form_state) {
foreach(element_children($form) as $key => $value) {
    if (isset($form[$value]['#type']) && $form[$value]['#type'] == 'select') {

      $options = $form[$value]['#options'];
      $newOptions = array();

      for ($i = 0, $optionsCount = count($options); $i < $optionsCount; $i++) {
        $optionsKey = array_keys($options[$i]->option);
        $optionsValue = array_values($options[$i]->option);

        $newOptions[$optionsKey[0]] = $optionsValue[0];
      }

      unset($form[$value]['#multiple']);

      $form[$value]['#type'] = 'radios';
      $form[$value]['#options'] = $newOptions;
      $form[$value]['#theme'] = 'select_as_radios';
    }
  }
}

I now get the following notice and warning messages.

  Notice: Trying to get property of non-object in
  custom_theme_form_views_exposed_form_alter()
  Warning: array_keys() expects parameter 1 to be array, null given in
  custom_theme_form_views_exposed_form_alter()


texts: PDF Preview module not working in ubuntu for Drupal 8.5 version

texts:
PDF Preview module not creating the image(first page of PDF) in docker (Ubuntu) for Drupal 8.5 version.

I have installed imagick(configured the exce path in imagetoolkit module) and Ghostscript and also configured the PDF Preview to the file filed of my content type.

But when I upload the Pdf file I get below error,

ImageMagick error 1:
convert: no images defined '/var/www/html/web/sites/default/files/pdfpreview/58-samplepdf_9.jpg' @ error/convert.c/ConvertImageCommand/3210.

Could any one please help me to resolve this issue?
Please find more details below,
PHP version - 7.0;
Imagick version- 7.x;
Ghostscript version - 9.18;
OS -  Ubuntu 16.04

I guess ghostscript is creating the issue here. Is there any post installation configuration required in docker that we need do  for imagic or ghostscript.


texts:
I Copied the file

bootstrap\theme\system\block.tpl.php

to my subtheme

bootstrap_subtheme\templates\block.tpl.php

I made another 2 copies and renamed them to

bootstrap_subtheme\templates\block--sidebar-first.tpl.php
bootstrap_subtheme\templates\block--sidebar_first.tpl.php

In the subtheme.info file it says
regions[sidebar_first]  = 'Primary'

The block.tpl override works but the sidebar-first.tpl.php does not get overridden.

What am I doing wrong?


texts: Drupal 7: hook_menu not working correctly

texts:
I've created a custom module (called page_arg) simply for the purpose of registering a path and having it use a certain template file. I had this working with Drupal 6, but can't get it to work in Drupal 7. Basically, if I leave the page_arg_callback() function in the module, I get a 500 Server Error on every page in the site. If I remove it, I'm able to visit the path I'm trying to register, but it isn't using the template file I want it to use.

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

  $items['flashcards'] = array(
    'title' => 'Flashcards',
    'page callback' => 'page_arg_callback',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
  );
  return $items;
}

function page_arg_preprocess_page(&$vars) {
    $url = urlSplit(); //custom function. trust me, this isn't the problem :)
    if($url[0] == 'flashcards'){
        $vars['template_files'][] = 'flashcards';
    }
}

function page_arg_callback($arg){
  return 'howdy';
}

As a secondary question, is this the best way to go about simply registering a path and pointing it to a template file? Seems a bit elaborate. Could I implement hook_menu() in my theme instead?


texts:
I am trying to add a custom field to the user login block in drupa 7 for the zen theme. That is, in addition to the username and password fields, I need another field called code. Most of the available documentation on the net is targeted at drupal 6. From what I've read, the template.php file and the block--user--login.tpl.php files need to be modified for the particular theme. Is this right? Also, what functions need to be modified/added?

Any help appreciated.


texts: Is it possible to unset private_tempstore values?

texts:
I have a block that creates a private_tempstore value (which I understand works exactly like PHP sessions).

How do I unset that value.

This is the code I am using for the block.

class SsoSessionBlock extends BlockBase {
    /**
     * {@inheritdoc}
     */
    public function build(){
        $value = 'dav';
        $session = \Drupal::service('user.private_tempstore')->get('achva_sso');
        $session->set('name', $value);

        return [
            '#type' => 'markup',
            '#markup' => $this->t('The output of super SsoSessionBlock block.'),
        ];
    }
}

I saw this method, but I am not sure how I am supposed to use it.

I tried the following code, but I get an error.

namespace Drupal\achva_sso\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\user;

class SsoController extends ControllerBase{
    public function ssoLogout(){

        $session = \Drupal::service('user.private_tempstore')->get('achva_sso');
        PrivateTempStore::delete('name');

        if(isset($session)){
            $status = $session .' is logged in';
        }else{
            $status = 'is logged out';
        }
        return[
            '#type' => 'markup',
            '#markup' => '<p>' . $status . '</p>' ,
        ];

    }
}

How do I unset a value I previously set?


texts: Barrio theme not showing user menu drop-down

texts: I tried to show the multilevel dropdown submenu for the user account menu in subtheme using bootstrap_barrio but it is not showing up. however i did the configuration in the block to show multilevel and put the menu links as expanded.


texts:
I really would need some help with contextual filter.

I have a content type I use for products, different kind of security cabinets. In this particulary case it is aboyt burglary safes. They have a classification of 0,1,2,3,4,5, S1 or S2. So all burglary safes has one of these classes. To give them the class I have created a Vocabulary with the name "Burglary Classes" and there I have created the classes 0,1,2,3,4,5, S1 or S2 as terms.

In Views I have made a block with a table presenting all burglary safes, containg fields like dimensons and weight and so on and have brought in this table block to the Content type, as a field, and it works just fine.

Now to my question;
All products in the Content type are not burglary safes so some are not classified according to 0,1,2,3,4,5, S1 or S2 , but I can't firgure out how to configure the Contextual filter.

I want ALL safes classifed to ANY of the terms 0,1,2,3,4,5, S1 or S2 to appear in ALL of the nodes having ANY of the terms 0,1,2,3,4,5, S1 or S2 but NOT to appear in any other node

The best shot I have had is filtering so that in the node only products belonging to the same Burglary Class as the node itself, appears. But as said, I want all products with a burglary class to appear.

Greatful for your help

Hans

(On request I have tagged the question for Drupal 7! Sorry for forgetting)


texts: how to get this functionality? views: Format options in ctool modal modify field data

texts:
In views module, when we edit view page and add fields to it, there is an option Format:unformatted-list and when we click on unformatted-list, a popup appears displaying radio buttons of grid, table,jump-menu, etc. Choosing any of the radio button, the field adjust themselves in either grid, table, whatsoever the option we choose.

I need the exact functionality of choosing radio buttons, modify my fields display output.

Thanks in advance.


texts:
I need to download a zip with all attached files from a webform.

Is it possible?


texts:
I'm trying to add tags to my blog posts on my Drupal 7 site. I've added the Term Reference field to the content type and when I add a blog post it is letting me add tags without a problem, however despite the field being visible in the 'Manage Display' tab I can't get them to show up when viewing the blog entry.

I know that the field is working because I have the Metatag module installed and that's producing metatags from the field token. I've checked the page source though and the field isn't even there but hidden because of CSS.

Anyone any ideas?


texts: How do I override the default page.tpl.php?

texts:
I have one page in my D7 website with significant deviation from the rest of my pages. In this page I will only display a limited number of regions and in a different layout.

What is the best way to override the default page.tpl.php? Can I create something like "mycustom-page.tpl.php" that gets called ONLY on a specific url within my site?


texts:
I have a page with two view blocks in it, each pulling from different content types. Is there a way to allow the user to search both views at the same time? I want to be able to enter a search term and have both views be filtered by this term.

Edit: Going off of johnbburg's answer, I found a solution using Panels, but would really like to avoid adding Panels to the site. Perhaps I could use javascript to insert the search term into the other field?


texts: Do I need to give a complete copy of my site's source code to a themer?

texts:
I want to get my sites themed from expert themers ( for example at Freelancer etc). I need node, views etc be themed along with site look and feel.

I've done little themeing till now and I tested with my site source.

What I want to ask is it necessary to give complete site source code to the themer which i don't want to do? What minimum they'd need?


texts: Print mailing address labels from a view

texts:
We have a site built with Drupal Commerce and are looking for a way to print address labels from a view

So far I have been able to make a grid view of addresses and use the printer friendly version module to create a print view, but i can't seem to get the CSS right to line up the labels correctly.

I have seen this module for Drupal 6 - http://drupal.org/project/mailing_label, but nothing for Drupal 7. I was wondering if someone had any insight.

Thanks.


texts: How can I echo a views object ($data->nid) into javascript?

texts:
I need to echo out a few different variables in an onclick event for Google analytics.

I figured this would work but the specific $data objects aren't echoing out.  The variable_get does, however.

<?php
  echo "<script>jQuery(document).ready(function($) {
 _gaq.push([ '_trackEvent', 'my_category', 'my_action', '". variable_get('4_measly_letters', 'AAAA') ."|".$data->nid ."|".$data->node_data_field_i."']);
  });
 </script>";
?>


texts: Image Responsive Carousel like image Gallery

texts: I have created a view of images and I want to display those images in a carousel like display but that needs to be responsive. I came across a jquery plugin for this called "elastislide" but cannot properly figure out how to use it with drupal views I have followed the example here, but nothing is working as such.


texts: How to write this SQL code in Drupal 7 standards!

texts:
So basically i am developing a module which is using Another Database,NOT THE DEFAULT DB and it is connecting successfully.
I have this SQL query which runs Smoothly in my custom MVC application.
Now Running the same code in Drupal Gives me error!

Below is the Code

function market_summary(){

$sql = 'select s1.company,(s1.closingprice-s2.closingprice)/100 as diff from stocks as s1
  INNER JOIN stocks as s2 ON s1.company = s2.company
     s1.dpid = (select max(dpid) from stocks) and s2.dpid = (select max(dpid)-1 from stocks)';

$mymodule= Database::getConnection($target='default',$key='$mymodule');
$result = $mymodule->query($sql);
$output='';

foreach($result as $record){

 $output.=$record->company.'<br/>';

 }
      return $output;
}

I want to know how to write the SQL part of this Code in Drupal standards.
I have attached a screenshot, showing the error message.
I will Appriciate for any help.


texts: Calendar view: Making year+month exposed filter go to the right URL

texts:
Using the calendar module, I've created a monthly calendar:

The built-in navigation using << Prev and Next >> links works great, and correctly navigate to the previous and next month, using URLs like:
http://example.com/calendar?field_event_date_value[value][year]=&field_event_date_value[value][month]=&date=2014-07

The 2nd navigation is the year + month select lists. I got a requirement to navigate directly to a specific year and month using a dropdown selection. So I've added an exposed filter on the "Event: start date" field (see screen below), which tries to do it but the URL gets broken on the way. I get: http://example.com/calendar?field_event_date_value%5Bvalue%5D%5Byear%5D=2014&field_event_date_value%5Bvalue%5D%5Bmonth%5D=7. However, even if I manually fix the URLs displays empty data.

I tried to put a custom date selection form using this tip, but the form doesn't print. I also tried to create a custom submit handler like this in order to create a custom redirect but views behavior doesn't change. Also, changing the form action doesn't work since the target of the redirect depends on the user's selection and it still appends the extra query parameters.

Any idea on how to fix it?


texts: How to set proper permissions for drush rsync

texts:
I have a weird problem here. When I use drush sync for my remote server, Drush changes permissions for the uploaded files to the name of the remote user for both the user and the group on the system.

The remote server is an Apache-FPM install where the name & group of webroot files have to be owned by vu2003:vu2003. Is there a way to achieve this with the aliases.drushrc.php?

Here Is my aliases file:

$aliases['live'] = array(
    'uri' => 'pts1.tk',
    'root' => '/var/www/virtual/pts1.tk/htdocs',
    'remote-host' => 'pts1.tk',
    'remote-user' => 'publisher',
    'os' => 'Ubuntu',
    'path-aliases' => array(
    '%drush' => '/usr/share/php/drush',
      '%drush-script' => '/usr/bin/drush',
      '%dump-dir' => '/tmp',
      '%files' => 'sites/default/files',
      '%private' => '/var/www/virtual/pts1.tk/000_private',
     ),
    'databases' =>
      array (
        'default' =>
        array (
          'default' =>
          array (
            'driver' => 'mysql',
            'username' => '[placeholder]',
            'password' => '[placeholder]',
            'port' => '',
            'host' => 'pts1.tk',
            'database' => '[placeholder]',
          ),
       ),
     ),
     'variables' => array(
        'site_name' => 'Drupal',
      ),
     'command-specific' => array (
       'sql-sync' => array (
         'no-cache' => TRUE,
       ),
     ),
  );

 $aliases['default'] = array(
      'root' => '/var/www/d7',
      'uri' => 'drupal.dev',
    'os' => 'Ubuntu',
    'path-aliases' => array(
    '%drush' => '/usr/share/php/drush',
      '%drush-script' => '/usr/bin/drush',
      '%dump-dir' => '/tmp',
      '%files' => 'sites/default/files',
      '%private' => '/var/www/html/private',
     ),
    'databases' =>
      array (
        'default' =>
        array (
          'default' =>
          array (
            'driver' => 'mysql',
            'username' => '[placeholder]',
            'password' => '[placeholder]',
            'port' => '',
            'host' => 'localhost',
            'database' => '[placeholder]',
          ),
       ),
     ),
     'variables' => array(
        'site_name' => 'Drupal',
      ),
     'command-specific' => array (
 'sql-sync' => array (
         'no-cache' => TRUE,
       ),
     ),
  );


texts: How to implement apple-touch-icon to a site

texts:
I'm trying to place an apple-touch-icon on a site.  I have attempted to implement this via the following code block placed in example_preprocess_node()..

function example_preprocess_node(&$variables) {

  ...

  $apple_touch = array(
    'rel' => 'apple-touch-icon',
    'href' => path_to_theme() . '/apple-touch-icon.png',
    'sizes' => '114x114'
  );

  drupal_add_html_head_link($apple_touch);

  ...

}

I cleared the caches and reloaded the page, but I'm not seeing the <link.../> line in my header at all.

Is this this right place to implement the apple-touch-icon?


texts: Access denied PDO Exception - other users are getting it but not me

texts:
I've set up a new Drupal 7 site (which is still in a vanilla post-install state with no custom code, no themes, no content). This particular site runs on a remote DB, with users (my team colleagues) downloading the Drupal code from a VCS to run on their local machines. Everyone is getting the following error while trying to access the site - except me. I can log into the site just fine.

PDOException: SQLSTATE[HY000] [1045] Access denied for user
'root'@'localhost' (using password: YES) in lock_may_be_available()
(line 167 of /private/var/www/drupal_media_7/includes/lock.inc).

What could be different about my local setup, given that we should all be running the same code and accessing the same database with the same credentials? (since the credentials are all in the code).

How might I start debugging this?


texts: How change "user menu" to current username

texts: I'm looking for a way to change the label "user menu" to be the current user's username. I am using the default Drupal 7 theme, Bartik, if that makes any difference.


texts: Auto fill content field with random values

texts:
I have field_x with values "A" or "B".

They must be assigned randomly by the system between A or B at every node added ( must not be changed on "node edit" by the node author).
The total numbers of nodes will be "30" and the assignment must be symmetrical ( after all 30 nodes will be added: 15 nodes must have "A" value and 15 nodes "B" value)

I've tried an solution with RULES but I didn't find an random function to use. Anyone has an better solution ? Thank you!

More rational explanation of the problem:

Insurance company "X" has 5 workers who upload client files (nodes), every worker must upload 30 files per month to the system. Every file has an field named "file_inspector" that has the name of the inspector who will check the insurance problem from that respective file. The field "file_inspector" can have "inspector1" or "inspector2" values that will not be completed by the worker but will be assigned by Drupal randomly based on the fact that at the end of the month total number of nodes will be 30 for every worker and "inspector1" and "inspector2" must be assigned equally 15 / 15.
The assignment must happen in real time (when the node is added) not at the end of the month. (Hope this makes more sense now)


texts:
I have searched and searched and found many possible solutions but none of them work for me.

I have a very odd website setup (the client wants it that way)
Setup (all next to each other):

Main menu (Menu block)           Submenu (regular block)                 Main content (body)

What I need is the following: When a user clicks on a Main menu item the main menu item gets another color (last cliked menu link).
When the user then clicks on a submenu item that submenu item gets another color (last clicked link). The main menu item can still have the color but this doesn't have to be.
I just want a css rule to change the color of the last clicked link. So not just menu link but just the last link. Is it possible with just CSS or do I need something more? :)


texts:
I realize priority headers are something of the past for the most part, but I was wondering if it's possible to add additional headers (eg. Priority Flag) to an email sent from Webform (Drupal 8 version)?

Similar to this question - https://www.drupal.org/forum/support/post-installation/2013-08-29/adding-priority-flag-to-email-sent-by-webform-module

I understand this is possible with a remote post, but this is strictly for sending an email.

Any help is apprciated.

Just for context, here is how it can be set strictly in a PHP email.

$headers = "MIME-Version: 1.0\n" ;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";

$to = 'bob@email.com';
$subject = 'High Importance Email Testing';
$message = 'Testing email importance, please ignore';
$status   = mail($to, $subject, $message,$headers);

I managed to get the module working as I'd like, thanks to @jrockowitz

Here is the final module

<?php
/**
* implements hook_mail_alter()
*/
function priority_headers_mail_alter(&$message)
{
    // only alter webforms
   if (strpos($message['id'], 'webform_email_web_requests') === 0)
   {
       //Get webform submission
       $webform_submission = $message['params']['webform_submission'];

       //Get the value from the priority field
       $priority = $webform_submission->getElementData('priority');

       if($priority == 'Critical')
       {
           /*setting priority headers*/
           $message['headers']['X-Priority'] = '1 (Highest)';
           $message['headers']['X-MSMail-Priority'] = 'High';
           $message['headers']['Importance'] = 'High';
       }
   }
}


texts: How do I prevent this? I'm not sure what is causing this. This site is running over 60 modules now and yesterday I noticed something changed my admin_menu toolbar layout, but don't know if this has to do anything with this.


texts:
I have a page with 8 languages. Most of the content is translated and have a language assigned. But there is one part of the page, where I need language neutral content to show in each language.

If I create a language neutral content, it generates the "Language Neutral" path from the URL-Alias settings. This looks basically like the English path. Thats Ok. But it looks now for every language like the english path. Only the language prefix changes:

/path/to/content
/de/path/to/content
/fr/path/to/content

Is there a way to generate programatically URL-Aliases to this node for each enabled language?

/path/to/content
/de/pfad/zum/inhalt
/fr/chemin/au/contenu

I have found something similar for Taxonomy Terms where it creates a URL-Alias for each term in each language (Pathauto i18n Taxonomy). But I should have this for nodes.

How can I achieve this without creating each alias manually?


texts: how to update the order total in checkout page?

texts:
I'm calculating discount amount base on total order amount. how can I show the discount amount like something what coupon module has done? (see the picture)

what is the correct way to update the total order amount? I mean how should I subtract the discount amount from the order total so if any products has been removed or added it always works correctly??


texts: Puilling Information From Referenced Entities to Display/Use In A Custom Content Type?

texts:
Exposition

I have two Content Types with the following fields:

Scenes

Scene Name
Starring (Actor's names)
Streaming Link

Releases (DVD Releases)

Title
Description
Starring (All actor's names from all Scenes referenced)
Scenes (Entity references to the Scene Content Type)

My question

When displaying a Release node, how can I get Drupal to generate the list of Starring Actors by taking the names from the 'Starring' fields in the Scene nodes that have been referenced?

Thanks


texts: Uninstalling a created custom module in drupal 8

texts:
I've created a custom module in drupal 8 and on this module i've created:

Content types
Fields
Entities
Views ...

all this programmatically.

But the problem when i try to uninstall it the database keep all this forms stored !!!

I'm wondering if there is a solution to automatically delete them from database when uninstalling a module

I appreciate any kind of help :)


texts:
I am getting this error on my website.

  Strict warning: Creating default object from empty value in theme541_preprocess_html()

I found a patch https://www.drupal.org/node/1242362 by Damien McKenna but I don't know how to apply the patch that fixes the error.


texts: How to not index comments in search_index?

texts:
I'm using drupal search, the core module.

I want to not index the comments in the search_index

In the node.module, the "function _node_index_node($node)" loads and renders the node. Comment content is loaded and indexed here. I would like to not load the comments content here in order to not index this content. How can i do this ? Thanks

NB : i'm drupal 6, but tips in 6 or 7 are welcome


texts:
I am using Drupal for running a website. I have integrated the "Share bar" module to share the current page in social networking sites. I know from the plugins code of Facebook that the share count of the website is 200+ But the share bar module shows only 20+ count.

I could find out what the problem is, the code for sharebar is:

   <fb:like href="[url]" send="true" layout="box_count" width="450" show_faces="true"></fb:like>

In the code above, [url] token actually gives out http://www.indiansnakes.org/frontpage instead of http://www.indiansnakes.org. I think the [url] token refers to hyperlink before redirection is completed.

How can I modify the script above so that I get the count for www.indiansnakes.org instead of www.indiansnakes.org/frontpage


texts:
When I edit a view, and click on the "Save" button, I get the following message:

  An AJAX HTTP error occurred.
  HTTP Result Code: 200
  Debugging information follows.
  Path: /admin/structure/views/view/vouchers_list/preview/page/ajax
  StatusText: OK

What does that message mean? How can I fix the error?


texts: Installing Bootstrap theme using Composer

texts:
I am new to using Composer.

How can I install a theme, say https://www.drupal.org/project/bootstrap using composer

I've tried:

composer require drupal/bootstrap

But didn't work.

I also tried:

composer require twbs/bootstrap

Installation was completed successfully but I couldn't see the theme appearing at Drupal admin page.

What is the standard way to extract the name of the theme or module to be used with composer require?


texts: Update the actual file associated with a file entity while keeping the fid?

texts:
Media module provides a generic.png file that it copies into /sites/default/media-icons/generic. That file is used on my site ~300 times, but I'd like to replace it with another PNG. Is it possible to replace the actual file that is associated with that file entity? Ideally I'd keep the generic.png name, but I can use an updated file name if needed.

I've tried simply replacing the file in /sites/default but that had no effect.


texts:
I am working on a custom Drupal 8 module which generates a menu. Refer Create a new Menu in Drupal 8 programmatically for details.

I have the menu now, but when I try to add custom menu links to it, following add a menu link, somehow it's not getting added to that custom menu.

Another weird thing is that the links are getting added to the wrong menu, i.e. they show under User Account Management menu.

The only reason I can think of is, when I install the module, Drupal tries to create the menu link first, before it has created custom menu. As the custom menu is not there yet, it tries to add the menu links to another menu. Is that right?

Here is my code, if that helps:

// system.menu.aeauth.yml // This creates the new menu on module install

langcode: en
status: true
dependencies: {  }
id: aeauth
label: 'AE Authentication Links'
description: 'Links related to AE Authentication'
locked: true

// ae.links.menu.yml // This adds menu links to menus

ae.admin_settings:
  route_name: ae.adminForm
  title: 'AE Configuration'
  description: 'Configure AE for your website'
  parent: system.admin_config_system

ae.register:
  title: 'Register'
  description: 'Register using AE Connect'
  parent: aeauth
  route_name: ae.regroute

ae.login:
  title: 'Login'
  description: 'Login using AE Connect'
  parent: aeauth
  route_name: ae.loginroute


texts: How to attach browser-specific stylesheets in D8?

texts:
In D7 it's possible to attach a css file based on browser sniffing, like this:

drupal_add_css(
  $path_to_css,
  array(
    'browsers' => array(
      'IE' => 'lte IE 9',
      '!IE' => FALSE
    )
  )
);

Drupal 8 does away with drupal_add_css in favour of #attached => array('css' => array( $path_to_css )) but how, in that situation, can you achieve the same thing.

(Nb. I'm not actually using D8 yet, but where things can be done the D8 way in D7, I'm adopting them to ease the learning curve to come!)


texts: How to view nodes that only you have published?

texts: I need to be able to incorporate into my system a method for which users can view nodes that only they have created.  How can this be done?


texts: After module install - mass CSS errors and menu problems

texts:
Whilst I was installing the Form Builder UI module, the website semi-crashed - didn't load the page correctly.

Upon reloading it, the module was installed, however there were a tonne of errors, including:

The PHP Filter Module became disabled
There are huge CSS errors on the front page, particularly around the drop down menus (see www.movingonios.co.uk for details)
The reports section from the Admin options is missing Status Report - no sign or error logs etc.

I have tried reenabling PHP filter module, and disabling form builder, but the problem persists. I have also tried clearing the Drupal cache.


texts:
I have an Image field for a node. I added a default image, but now I want to use a different default image.

When I click the Remove button, I get the following AJAX error:

  An AJAX HTTP request terminated abnormally. Debugging information
  follows. Path:
  /file/ajax/instance/settings/default_image/form-h8XGqyiOrbYg2szWDEf3u-Ch9LDl7xvajwpG-3cLx5g
  StatusText: n/a ResponseText:  Error   Error message Recoverable fatal
  error: Argument 2 passed to drupal_array_set_nested_value() must be an
  array, null given, called in /var/www/includes/form.inc on line 2519
  and defined in drupal_array_set_nested_value() (line 6570 of
  /var/www/includes/common.inc). The website encountered an unexpected
  error. Please try again later.

  ReadyState: undefined


texts: Alter existing form and add element with an ajax "add more" button

texts:
I am altering the field settigns form, in order to add custom settings. I used the example module as a guide and added my code in the following manner:

/**
 * Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.
 */
function fd_image_form_field_config_edit_form_alter(array &$form, FormStateInterface $form_state) {

  // Gather the number of names in the form already.
  $num_names = $form_state->get('num_names');
  // We have to ensure that there is at least one name field.
  if ($num_names === NULL) {
    $name_field = $form_state->set('num_names', 1);
    $num_names = 1;
  }

  $form['#tree'] = TRUE;
  $form['names_fieldset'] = [
    '#type' => 'fieldset',
    '#title' => t('People coming to picnic'),
    '#prefix' => '
',
    '#suffix' => '
',
  ];

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

  $form['names_fieldset']['actions'] = [
    '#type' => 'actions',
  ];
  $form['names_fieldset']['actions']['add_name'] = [
    '#type' => 'submit',
    '#value' => t('Add one more'),
    '#submit' => ['_fd_image_add_one'],
    '#ajax' => [
      'callback' => '_fd_image_add_more_callback',
      'wrapper' => 'names-fieldset-wrapper',
    ],
  ];
  // If there is more than one name, add the remove button.
  if ($num_names >= 1) {
    $form['names_fieldset']['actions']['remove_name'] = [
      '#type' => 'submit',
      '#value' => t('Remove one'),
      '#submit' => ['_fd_image_remove_callback'],
      '#ajax' => [
        'callback' => '_fd_image_add_more_callback',
        'wrapper' => 'names-fieldset-wrapper',
      ],
    ];

    $form_state->setCached(FALSE);
  }
}

I also added my ajax callbacks:

/**
 * Callback for both ajax-enabled buttons.
 *
 * Selects and returns the fieldset with the names in it.
 */
function _fd_image_add_more_callback(array &$form, FormStateInterface $form_state) {
  return $form['names_fieldset'];
}

/**
 * Submit handler for the "add-one-more" button.
 *
 * Increments the max counter and causes a rebuild.
 */
function _fd_image_add_one(array &$form, FormStateInterface $form_state) {
  $name_field = $form_state->get('num_names');
  $add_button = $name_field + 1;
  $form_state->set('num_names', $add_button);
  // Since our buildForm() method relies on the value of 'num_names' to
  // generate 'name' form elements, we have to tell the form to rebuild. If we
  // don't do this, the form builder will not call buildForm().
  $form_state->setRebuild();
}

/**
 * Submit handler for the "remove one" button.
 *
 * Decrements the max counter and causes a form rebuild.
 */
function _fd_image_remove_callback(array &$form, FormStateInterface $form_state) {
  $name_field = $form_state->get('num_names');
  if ($name_field > 1) {
    $remove_button = $name_field - 1;
    $form_state->set('num_names', $remove_button);
  }
  // Since our buildForm() method relies on the value of 'num_names' to
  // generate 'name' form elements, we have to tell the form to rebuild. If we
  // don't do this, the form builder will not call buildForm().
  $form_state->setRebuild();
}

Now when I go to the field settings form, I see my form elements and I do see the add more button. I can click the add more button 1 time and it adds an extra element, but the problem is, I cannot add more than 2. Once the page have 2 elements subsequents clicks on "add more" result in an ajax callback that does nothing.

After debugging it looks like the $num_names is not being correctly stored and increased. I am assuming that is because the Examples module has it's own buildFrom method while in my case I am only altering. What is the correct way of adding an ajax element to an existing form?


texts:
I am currently using Webform 7.x-4.2 and am looking to add a Font Awesome icon inside the placeholder. I did try modifying the settings.php with the following line:

$conf['webform_allowed_tags'] = array('a', 'em', 'strong', 'code', 'img', 'i');

My understanding was that this would allow me to use an 'i' tag on my webforms but it is not working for a placeholder. It does work if I use the tag in place of my label but then when a user gets a confirmation email with a submission summary the label shows the 'i' tag (ex. )

Is there a way to use Font Awesome in a placeholder?

Thanks for any assistance.


texts: Reuse/sync view mode display settings across entity bundles?

texts:
Assuming I have a number of entity bundles (e.g. node types) with a similar structure and behavior. Now I want to show a list of such entities/nodes. I want to use a view mode, e.g. "teaser", to display each node.

I could now configure the "teaser" view mode for all 4 node types, optionally with Display Suite. But the settings should be all the same.

So, which solutions do exist to have the same settings across entity bundles, and keep them synced?

Also, when exporting to a feature, I would prefer to avoid redundancy.

As far as I know, this is not currently possible with view modes in Drupal 7, due to how this feature works. But I am curious for out-of-the-box solutions that do the job.

Disclaimer: This is a question I repeatedly was asking myself in the past. At the time I am writing this, I already created a solution that works for me. I am posting this as a Q/A to share it with others. meta


texts: Getting body of a node to display in a block using PHP code

texts:
I've created a block and put some php in it to display the body of a node using the code form here: http://drupal.org/node/300910#comment-4183142

<?php
//get the ID from the URL
$node_id = basename($_SERVER['REQUEST_URI']);
echo $node_id;
//Load the node object.
$node = node_load($node_id);
//Get the node array into memory.
node_view($node);
//Now you can parse only the body value into a variable.
$node_content = $node->content['body']['#value'];
//Printing content.
echo $node_content;
?>

The page I've tried this on prints the ID in the block (as expected) but not the body of the node with that ID.

My hunch is that $node_content = $node->content['body']['#value']; can't be used in a block.

Any thoughts?
Thanks!


texts: Set the back-office theme to a specific url

texts:
(On drupal 6)

On some of the websites i have to manage, the translation page of a node ( mywebsiteurl.com/node/NodeNid/translate) use the main theme instead of the back office theme.

I have some ideas about how force the back office theme, but i doubt it's the right way.

I create a specific module and use a preprocess_page function to force a

$GLOBALS['custom_theme'] = variable_get('theme', 'mybackofficetheme')

if i am in a translation page. But it doesn't works, so can you suggest me the best practice?


texts:
I have a Taxonomy which looks like this:

Parent1
-Child1
--SubChild2
--SubChild3
-Child4
--SubChild5
--SubChild6
-Child7
Parent2
-Child8
-Child9
--SubChild10
-Child11

I have created a view to display all terms under a specified Parent by setting a context tid . Here you can find the exported view: http://pastebin.com/us7KnKsD

The Problem is that the view only shows the terms which have sub-children.

How can I also display the terms which doesn't have sub-children?
Is it possible with views? In php I would just create some recursive function...


texts: How do I set some script in the  section on a page?

texts:
I solved some question on field type generation and learned how to render my custom field.
Now, I need to use an accessible audioplayer to play my songs. In my custom field formatter view function I set item_output to render this custom field in an unordered list. Each item of this list is a link that calls a javascript function that plays automatically the song.
Unfortunately, to use this player, I must set some script in header section of my page, and style css for this player.
So, I need to set these scripts on ly in a page that displays this field. There is a way? Maybe in $element array returned from field formatter view function?
I hope you can understand me, my english is very bad!


texts:
I'm trying to add two links on custom user form.
The goal is this links to be displayed bellow the submit button.
I've tried with weight property, but it's not working.

What do I miss?

This is my code:

<?php
      function custom_alter_form_alter (&$form, &$form_state, $form_id) {

        switch ($form_id) {
                case 'user_login':

                $form['name']['#title'] = t('Username');
                $form['pass']['#title'] = t('Password');
                $form['actions']['submit']['#value'] = t('Login');
                $form['actions']['submit']['#weight'] = 0;

                $form['page'] = array(
                '#markup' => '
Login
',
                '#weight' => -10,
                );

                $form['register'] = array(

                '#type' => 'markup',
                '#markup' => '
You don't have an account?
                  Click here
',
                '#weight' => 1,
                );

                $form['password_reset'] = array(
                '#markup' => ' You forgot your password',
                '#weight' => 2,
                );

                //krumo($form);
                break;
            }

        }


texts:
I am trying to access the current $node variables in the html.tpl.php within Drupal 7. The problem is that I am running a Analytics software in the backend for which I've to record each page's analytics from html.tpl.php.

If there's a normal page, I have to record generic attributes but if it's a node, I need the following things in the html.tpl.php:-

Title of the Content (Node)
Content Type of the Content

I can do this in node.tpl.php through $node->type;, but unfortunately I need it in html.tpl.php.

Many Thanks.


texts: After preview node is not saving the content.

texts:
I added the data to node, after that i clicked on the preview button and it displaying preview of that node, but the problem is, node not saving the content. When i click the submit button it shows the error message

"The content on this page has either been modified by another user, or you have already submitted modifications using this form."

Please any one help me out.


texts: How to link the file icon to the file and to hide the filename?

texts:
I have uploaded files to be displayed in a table together with some other informations (title, tags etc). One row of this table the filename which links to the downloadable file. Next to the filename a file icon is displayed be daefault, which isn't linked.

That's how it looks now:

I want the filename to be hidden and the file icon linked to the downloadable file.

What functions would I have to override to make that happen? Or what other way may exist?


texts:
In Drupal 7, it's possible to group fields for a content type with fieldsets, vertical tabs and so on.

Where are this options in Drupal 8? I didn't find something in the Manage fields or Manage form display tab.


texts:
If I want to add JavaScript in the head tag, I use drupal_add_js($js, 'inline'). This will add a <script type="text/javascript">.

How do I add the <noscript> tag? I want to add the following in <head> also.

<noscript>
  <meta http-equiv="refresh" content="5;url=<?php echo $file ?>" />
</noscript>

BTW, I'm using a simple module for this.

function custom_download_menu() {
    $items['download-code'] = array(
    'title callback' => 'custom_download_page_title',
    'page callback' => 'custom_download_view',
    'access arguments' => array('access content'),
    'access callback' => TRUE,
    );
    return $items;
  }

function custom_download_view() {
    $js = "var time_left = 5;
        var cinterval;

        function time_dec(){
            if(time_left > 0) time_left--;
            document.getElementById('countdown').innerHTML = 'Your download will start in ' + time_left + ' seconds...';
            if(time_left < 1){
                clearInterval(cinterval);
                window.location = '<?php echo $file ?>';
            }
        }

        cinterval = setInterval('time_dec()', 1000);";

    drupal_add_js($js, 'inline');
}


texts: Using substr() with Drupal search-result.tpl.php returning fewer characters than expected

texts:
In my search-result.tpl.php file I want to return only the first 200 characters of the body field before outputting it to the screen (assuming there are that many characters). I'm trying to use the following code in my search-result.tpl.php file but it's just outputting like the first 32 characters or so...any idea why that might be?

<?php
$body = substr(render($teaser['body']), 0, 200);
if (strlen($body) == 200) {
    $body .= "...";
}
?>

<li class="<?php print $classes; ?>"<?php print $attributes; ?>>

<?php print render($teaser['field_icon']); ?>

<a href="<?php print $result['link']; ?>"><?php print $result['title']; ?>

      <?php print render($teaser['field_type']); ?>
      <?php print render($teaser['field_event_dates']); ?>
      <?php // print render($teaser['field_screenshot']); ?>
      <?php print $body; ?>


texts:
I posted a support request on Drupal.org, but I thought I may find a faster answer here.

I am using the User Relationships module to create mutual relationships between two people with the purpose of viewing content. The node access part of UR seems to work fine. I am having trouble with Views, though.

Can anyone explain to me how I would do the following?

Create a View containing content a user (not current logged in user) has created, filtered by a content type (lets call it Image). This view has a path with an argument like user/%/images.
When the current user goes to user/%/images, it should show the images for whichever user ID is passed as the argument ONLY IF both users are related/accepted relationship. There is only one relationship type on the website. If there is no relationship, I would like to serve Access Denied, or at the very least, Page Not Found. But 403 makes more sense.

I cannot get this to work.

My goal is to show links to different types of contents users have created, and the viewing user (requester?) needs to have a relationship to view the content. Otherwise they should see nothing at all, or return an access denied error.


texts: How to upload static files to a remote server in Drupal 7 instead of local filesystem?

texts:
I've recently had to migrate from Django to Drupal 7 due to web server constraints. One of the aspects of my old Django setup that I would like to preserve is hosting static content like images and other media on a remote server as I have free access to a massive server for this purpose.

With Django, this was as simple as editing a line or two in the settings.py file. My search for how to do this in Drupal has so far been pretty fruitless. Can someone please suggest a relatively simple way of doing this automatically?

The website in question will have multiple contributors, most of whom will be non-technical, so this should be something that is handled automatically.


texts: How to get facets in drupal viewfield module?

texts:
I am using the drupal viewfield module (http://drupal.org/project/viewfield) to show a view as a field in a node. When i have tried it, the content is showed fine but it does not show the facets present in the view.

The facets are generated from apachesolr_views module

Did the module work for anyone else for displaying facets in a view ?

Thank you


texts: How to get custom line item's custom attribute's value after order complete

texts: Using this guide I added a custom line item type to my Drupal Commerce installation and have allowed the customer to add extra data when purchasing an item. When the order is complete I need to get hold of that extra data and use it to build some database rows that will grant them access to the service they have just purchased. I have implemented hook_commerce_checkout_complete($order) but I haven't been able to find the data within $order. I know it is there somewhere because I can view the order on the customer's account and have modified the View to show the data next to Unit price, Quantity and Total columns.


texts: Having issue with multiple calls of same view

texts:
I am using the function views_get_view and it's working fine if am using this once in a function. But when I am calling this function multiple times with different arguments in the same function the result is going to lose. In that case, the result always be same as coming with first-time arguments. Following are my code.

 $viewname = "profile_match_with_job";
  $display_id = "block_3";
  $view = views_get_view($viewname);
  $view->set_display($display_id);
  $view->set_arguments(array(138,70)); // views Contextual filter parameters
  $view->pre_execute();
  $view->execute();
  $myresult =  $view->result;
// here $myresult array showing the correct result

But I am calling the same thing with dfferent argument then the result is not corrct like this

 $viewname = "profile_match_with_job";
  $display_id = "block_3";
  $view = views_get_view($viewname);
  $view->set_display($display_id);
  $view->set_arguments(array(138,80)); // views Contextual filter parameters
  $view->pre_execute();
  $view->execute();
  $myresult =  $view->result;
// here $myresult array showing the same result but in that case I have chnaged the param values from 138,70 to 138,80


texts: Drupal Views rewrite link dependent on boolean value

texts:
I have a view that has a boolean field in it and a field that links to a file.  I want to use the boolean field to where if it is checked, it will direct to a static link, regardless of what file is uploaded.  If it is unchecked and there is no file, I want it to output nothing.  If it is unchecked and there is a file, then output the file link.  I tried setting up Views PHP and setting this up there, no luck.  First question is does Views PHP recognize rewrite rules that you've established in other fields, and if not, how can I accomplish this?  Below is the code I tried in Views php.  All it does is output the node id for every entry.

<?php
  if($row->field_booleanval) {
    echo 'Link';
  }
  else if(!($row->field_booleanval) && !($row->field_file)) {
    echo ' ';
  }
  else {
     echo $row->field_file;
  }
?>


texts:
I'm trying to create a new field, but Drupal came up with the well-known error:

  The machine-readable name is already in use. It must be unique

I'm sure that the field doesn't exist anymore (I checked the fields' list and it doesn't show up). I want to use that specific machine name because I already have developed some functions that are using that name.

So I guess the name is still saved in the database, there is a way to delete it without screw everything up?

Thank you for your time!


texts: Files uploaded via custom configuration form are eventually lost

texts:
This is a difficult one to explain. so, I am hoping that someone else has had a similar problem. I am uploading a file via custom configuration form, my field on the form looks like:

$form['homepage_image'] = array(
  '#type' => 'managed_file',
  '#description' => t('The image used on the home, agents, and featured property pages.'),
  '#default_value' => $config->get('pm_admin.homepage_image'),
  '#upload_location' => 'public://upload/siteimages',
  '#required' => TRUE,
);

My submit handler sets the config property in the bog standard way:

$config->set('pm_admin.homepage_image', $form_state->getValue('homepage_image'));

Initially this all works fine, the image is saved and I can grab it and render it where I want in templates. However, after several hours (I have not figured out the trigger) the image disappears. The configuration form no longer has the value. The file is also removed from the file system.

Not sure what is causing this and would appreciate any help.


texts: Image style doesn't rebuild after image style flushed

texts:
I have practically the same problem as here : https://drupal.org/node/2187443

I've flushed my image style because I edited this image style. Now when I reload the page where the image style should be shown they are missing (404).

What did I missed? shouldn't it be recreated automatically when styles are removed ?

Edit :

I found that images couldn't regenerate if 404 error isn't managed by Drupal. I think its very possible, then I made a change in to my .htaccess file to make Drupal manage 404 errors.

I am now getting the 403 error upon all my files, that are still not loading. :(

Failed to load resource: the server responded with a status of 403 (Forbidden)

Then I add +w on my files directory recursively to make sure the writing permission available for all to avoid 403 but nothing happens.


texts: How can I offer an option for users to switch between Unformatted and Table the Basic Styles section of Views.

texts: I'm using Drupal 6, and the customer has asked for a way for the user to switch between a list-of-nodes view, and a table view. The Basic settings section in Views does not offer a Exposed option, and my Googling has turned up nothing useful in this regard. I'm a somewhat experienced as a Drupal themer, and I could make a duplicate set of Views manually with a different settings to achieve this, but if there's an easier way, I'd like to have your insights.


texts: Ajax HtmlCommand not working on form field in a field group

texts:
I've added a custom ajax callback to a field that I'm trying to update the value of. The Field I'm updating is inside a field group and instead of updating the field it just empties the html.
The form item with the ajax callback
$form['sku'] = [
  '#type' => 'entity_autocomplete',
  '#title' => $this->t('SKU'),
  '#target_type' => 'node',
  '#selection_handler' => 'views',
  '#selection_settings' => [
    'view' => [
      'view_name' => 'parts_reference',
      'display_name' => 'entity_reference_1',
      'arguments' => []
    ],
    'match_operator' => 'CONTAINS'
  ],
  '#weight' => '0',
  '#size' => '200',
  '#ajax' => [
    'callback' => '::oeRefAjaxCallback',
    // don't forget :: when calling a class method.
    //'callback' => [$this, 'myAjaxCallback'], //alternative notation
    'disable-refocus' => FALSE,
    // Or TRUE to prevent re-focusing on the triggering element.
    'event' => 'change',
    // This element is updated with this AJAX callback.
    'progress' => [
      'type' => 'throbber',
      'message' => $this->t('Verifying entry...'),
    ],
  ]
];

The form item that is to be updated
$form['item_specifics_type'] = [
  '#title' => 'Type',
  '#type' => 'textfield',
  '#value' => '',
  '#size' => '60',
  '#group' => 'fieldset_item_specifics',
  '#prefix' => '
',
  '#suffix' => '
'
];

--
$response = new AjaxResponse();
$response->addCommand(new HtmlCommand('#item-specific-type-wrapper', $form['item_specifics_type']));
return $response;

If I remove the group key from the field array so that the field is not in the fieldset then the ajax command replaces the field with the correct html as expected.


texts:
Anyone know of a module that can check the base path of the URL to ensure the user is entering the correct URL?

I.e. the field is asking for the Facebook URL but they put in a Twitter one.

So should the user enter a different URL they won’t be able to continue unless the link contains www.facebook.com/.


texts:
I have a node for different language, but I would like to load node for "en" language only using entity_load after firing entity query.

How can I achieve it using this function in Drupal 7


texts: Is Menu-minipanels reliable to make a mega menu

texts:
I'm going to implement a mega menu in my site and am considering the Menu Minipanels module...

Has anyone tried it? Did you find it easy to use/customize?

What about performance? Panels is often quite a heavy module.


texts: How to bulk/mass import/create webform components?

texts:
Apart from his module : webform_auto_field, is there any way to bulk import or create multiple components in a webform. Even if it is one type of component at a time.

I've already googled on, and didn't get sufficient response..

Thank you all in advance...


texts: Link uploaded file or upload file to new node programmatically

texts:
I have a form, in the site's front end, that upon submission creates a new node.

I've been asked to add a file upload form element, so I used FAPIs 'file'.

I overcame some obstacles, and managed to get the file via the $_FILES array since $form_state has no idea that I uploaded a file (weird), and I performed a file_save_upload on it.

The file is now created, in my directory, and in the database as an entry. All is cool.

How on earth do I link it to the node object I am creating? If I try something like this :

$node->field_file_upload[LANGUAGE_NONE][0] = get_object_vars($file);

where $file is the previously saved file, I get this:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri':

As if the node_save() that happens one line below tries to recreate the file. I am obviously missing something here, any help?


texts:
I have a search results view from Search API where I need to use the excerpt that highlights the keywords being searched. In this instance, that prevents me from using a view mode output as the result.

In this instance, I have a view set up to output title, URI, date modified and search excerpt. I have a decent bit of theming to do around the form and results, but I can't seem to figure out how to view both the template suggestions for each view field, or just theme it manually in the given template views-view--unformatted--search--results.html.twig.

I also tried {{ kint(row) }} and even when viewing on its own page, basically locked up my browser.

So for instance, for the title, I need the markup to be:

Foo Exam

For consistency reasons, I would like to control it from twig templates instead of attempt to do it in the views admin (setting label field etc settings).


texts: When using Search API, editing an index and changing fields that get indexed, you can set the boost for some of the fields. What is this used for?


texts:
I have created a test orb.test for my module and placed it within the module directory. Installed the Simple Test module. When I visit the /admin/config/development/testing my test orb.test its not listed. Here is the code for my test

class OrbTestCase extends DrupalWebTestCase {
  protected $privileged_user;

public static function getInfo() {
  return array(
    'name' => 'Orb Test Case',
    'description' => 'Ensure that Online Booking functions properly',
    'group' => 'Examples',
  );
}

public function setUp() {
    parent::setUp('orb');
    $this->privileged_user = $this->drupalCreateUser(array('allow online  reservations'));
    $this->drupalLogin($this->privileged_user);
}

public function testorbroomavailability() {
  $this->drupalGet('orb');
  $this->assertText('Room Status');
}
}

Have I missed something here?

EDIT 5th August 2014:
My tests written and placed in of my modules do not show up in the list of tests (admin/config/development/testing)


texts: Javascript will not load for anonymous users

texts:
I have a controller with a route that has some javascript attached to it as a library.  When logged in as any user (admin or standard) the JS loads just fine.  When anonymous, the library file is loaded, but Drupal JS is not.
How the library is defined:
my_javascript:
  version: 1.x
  js:
    js/my_javascript.js: {}
  dependencies:
    - core/jquery

In the console the error says:

ReferenceError: Drupal is not defined
< anonymous >                      http://example.com/themes/custom/my_theme/js/my_javascript.js:7:3
< anonymous >                      http://example.com/themes/custom/my_theme/js/my_javascript.js:6:2

The lines in the JS the error is referring to are:
(function ($) {
  Drupal.behaviors.myScripts = {

This is the case for all browsers.  JS works fine when logged in as any user, but when anonymous, Drupal's JS does not load.


texts:
I defined a field myField through admin/configuration/manage fields. Then I implemented hook_user_insert because I want to do something with this field after the user registration. How can I access to myField value? I was trying with $edit['field_myField'] but I get an array.

Any help will be appreciated.