How do I update the CKEditor text widget using CKEditor API I am using Drupal 8's Ajax API to update form fields in a form depending on the input in another field. One of the fields I want to update is a text_format field that uses Drupal's ckeditor.

If I understand the CKEditor API correctly, I should be able to update the text in the ckeditor widget using the setData() method (https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#method-setData). The ckeditor instance should be the textarea id - and that I can easily identify in my AjaxResponse function.

However, I am not sure how to use Drupal's invokeCommand() to make use of the CKEditor API?

In the end I was able to solve this using a custom Ajax command:

In our custom module (called b47_custom_authors) we created a custom ajax command in src/Ajax/B47CustomAjax.php

/**
 * @file
 * Contains \Drupal\b47_custom_authors\Ajax\B47CustomAjax.
 */

namespace Drupal\b47_custom_authors\Ajax;

use Drupal\Core\Ajax\CommandInterface;

class B47CustomAjax implements CommandInterface
{

  /**
   * A CSS selector string.
   *
   * If the command is a response to a request from an #ajax form element then
   * this value can be NULL.
   *
   * @var string
   */
  protected $selector;

  /**
   * An optional list of arguments to pass to the method.
   *
   * @var array
   */
  protected $arguments;

  /**
   * Constructs an b47customajax object.
   *
   * @param string $selector
   *   A jQuery selector.
   * @param array $arguments
   *   An optional array of arguments to pass to the method.
   */
  public function __construct($selector, array $arguments = []) {
    $this->selector = $selector;
    $this->arguments = $arguments;
  }

  public function render(){
    return [
      'command' => 'b47customajax',
      'selector' => $this->selector,
      'args' => $this->arguments,
    ];
  }
}

The custom js (in js/b47customajax.js) is as follows:

Drupal.AjaxCommands.prototype.b47customajax = function (ajax, response) {

// response is an array with the keys
// response.command: the command called (b47customajax)
// response.selector: the selector to be used (NULL)
// response.args: the arguments to be passed as an array: 0: the ckeditor instance, 1: the text (data) to be passed

var ajaxckeditorinstance = response.args[0];
var ajaxckeditordata = response.args[1];
var editor;

var instance = CKEDITOR.instances[ajaxckeditorinstance];

if (instance) {
   // Trying to call setData method: https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#method-setData
   editor = instance.setData( ajaxckeditordata , {
          callback: function() {
                      this.checkDirty(); // true
                  }
          });

};

};
In my ajax callback function I call my custom ajax via:

$response->addCommand(new \Drupal\b47_custom_authors\Ajax\B47CustomAjax('textarea'.$fieldid,[$fieldid, $texttobeinserted]));

The $fieldid is the id of the textarea, and @texttobeinserted is the full html of the text I want in ckeditor.

This now allows me to update the ckeditor based on the text dynamically via my AjaxResponse. The textfield is hidden by default and depending on the input in another field I fetch the text that needs to be placed in the textarea/ckeditor. The form field is then also displayed.

This now works.


Autofill fields on profile form based on previous fields I have a particularly long user profile form on my client's site. Some of those fields can be autofilled using information already entered (such as spouse last name). The filling out needs to be done dynamically on the page. How can I do this?

[Edit]
Adding code for a problem that I experienced (anonymized):

function foo_profile_autofill_form_profile_node_form_alter (&$form, &$form_state){
    foreach(array('field_first_name', 'field_last_name',
            'field_spouse_first_name','field_spouse_last_name') as $fieldName){
            $form[$fieldName]['#attributes']['class'][] = "combname";
    }

    drupal_add_js(drupal_get_path('module', 'foo_profile_autofill').'/foo_profile_autofill.js');

}

You will have to use JavaScript to dynamically copy information from those fields. Depending on the structure of your form, you could also use a form_alter() to assign data- attributes to fields, which will reduce the number of lines of JS and make maintaining easier.

Here's sample code that should explain the idea::

JS:

$('input[data-sync]').change(function() {
  // Including the selector in data-attribute of the field will allow you
  // to have both - IDs and classes out of the box. This means you can
  // change the values of multiple fields, after only one change.
  $($(this).attr('data-sync-target')).val($(this).val());
});

hook_form_alter():

/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'your-form-id':
      $form['some_field']['#attributes'] = array(
        'data-sync' => TRUE,
        // You would use this to target an element with ID.
        'data-sync-target' => '#target-element-id',
        // OR you can use this to target multiple elements with this class.
        'data-sync-target' => '.target-element-class',
      );
      // If necessary, you can add custom CSS classes to elements like so:
      $form['some_field']['#attributes']['class'][] = 'your-special-class';
      break;
  }
}


How to build a simple blog where content could be published securely to user groups? I am developing a PHP application and want to host a blog to communicate with my alpha, beta, and (hopefully) other users.  I have some experience with Drupal, so am planning to put it to use.

I installed Acquia Commons.  It was impressive, perhaps too impressive for my needs.  I started out by trying to remove some of the features, and I found that there's not much documentation freely available for it.  (I don't want a paid service - this startup has not made any money).

I am thinking that Drupal Core with Organic Groups added might be sufficient, but I'm not sure since I have not used Organic Groups before.  And of course, there could be other distributions or modules that I don't know about too.

So, the question is, if your Drupal skills were pretty basic, how would you go about building a simple blog where content could be published securely to user groups?

EDIT: Maybe my usage of the word 'groups' is confusing the issue.  Perhaps I could do this simply by creating different roles, such as Alpha User, Beta User, and assigning users to those roles.  In that case, how would I go about restricting access to content based on role?

As per your "... there could be other distributions or modules that I don't know about too." in your question: have a look at the Group module (commonly perceived as an alternative for Organic Groups).

Group allows for creating arbitrary collections of your content and users on your site, and grant access control permissions on those collections. It is available as of D7, and has a D8 version also. The Group module creates groups as entities, making them fully fieldable, extensible and exportable. Which also makes it integrate very well (out of the box) with commonly used modules such as Rules, Views, etc.

Some more questions you may want to look at for more details:

What are the various roles supported by the Group module?, which explains the various types of roles that can be used.
How to bulk assign existing content to a group created with the Group module?, a typical issue when adding this module to an existing site).
What are the features of the Group module versus Organic Group module?

Resources

Community documentation for the Group module.
Video tutorial "How to use the Group module in Drupal 8 to manage editorial access control to different areas of a web site".


How to change the date on which a user was created? I'm creating users on my new website that were active on my previous website and I'd like to point this out on there profile pages by displaying the correct date in the "Active since" field.

Is there a possibility to change the user-creation date?

Here's a link to expose the creation date for drupal 6 - someone more knowledgeable with the conversion might be able to help you change it over to 7.
Otherwise, if there are not too many users, you could do it manually via database manipulation.

https://drupal.org/node/857846


Next and Previous Button for Pages I have created a 'Content Type' names it Stories. And have created 30 new pages for each stories using the same Content Type. Now how can i add Previous and Next Button under each stories?

Any Article or Video tutorial will be appreciated

Thank You,
Mazhar
P.S I am using D8

I would say that one relatively easy way without relying on any additional modules is to use the book module that comes with drupal core.

If you put the nodes in a book then you can use the book navigation's previous and next button.

You can override book-navigation.html.twig to remove elements of the book navigation that you don't need.


Adding Gmap to webforms I allready download gmap, location and some other modules that in this catagory and still I dont succeed to add a field in gmap type to my webform page so users could put it their location (not in the register of the users, in the form that I build!

How do I do it? I saw this:
https://drupal.org/project/webform_gmap
but it's for Drupal 6 and I'm using 7.

Drupal 7: Webform Gmap Location

https://www.drupal.org/sandbox/drecksau/2096563

  This module adds «Gmap» component to Webform.
  This component allows you to mark the location using the Google map.
  Also below the map can be displayed autocomplete address field.


Can I just have a color coded HTML editor in Drupal 6 that keeps line indentations? I'm trying to get out some minimally designed pages. The WYSIWYG (CKEditor) has a habit of collapsing the code between saves. WHile this is fine and all, I'm finding myself copying copy and pasting it into sublime text in order to reformat. The copy-pasting -- while not difficult -- is thumbing me up a bit. I've copied/pasted the wrong code and had to redo a lot of my work.

So can I have stop CKEditor from minimizing the HTML code? This is a legacy site in Drupal 6.28.

Well I got myself halfway there and without the need to download an additional module, library, or plugin. By checking Apply source formatting and Preformatted, the Disabled Rich Text rendition shows code indented with some of the white spacing preserved.

You can find these settings in D6 via admin/settings/wysiwyg


How to add sorting option to a field in views bulk operation I have created one view with the help of views bulk operations and now I want one of the field to able to sort records according to the field value.

I am attaching image

How can I make the "credits" field as sorting field.

This has nothing to do with VBO. It is simply a setting in the "Table" format. To achieve this:

Click "Settings" besides "Table" format.

And select which field you need to make sortable.


Validation when having 2 webform in same page? On Drupal 6, I have 2 different webforms which I have available as 'blocks'. Then I create a 'page panel' and added the 2 blocks. Everything works just fine but I have 2 problems.

One comes when sending any of the forms and the validation shows up. Both 'name' inputs are red marked.
When the form is correctly sent I'm redirected to the succes page but when I hit the 'back' button it takes me to the webform node instead of the 'page panel'.

Try changing the field name of one of the 'name' fields to that they are unique across both forms.
You'll need to copy the webform-submissions.tpl.php from the Webform module into your theme, and update the link at the bottom.


How to insert a View in a Panel? I want to create a page with a panel (using the Panels module). Then want to put a view in it. But I don't see anything in the content section, this is how it looks like:

I saw the question about "How to add Views into a Panels page", but in my Views display there is no panel pane display.

Where is my problem, do I need some additional module?

Welcome to Drupal, you had just one step more to do that, go to your module list in admin/modules and in Panels package enable Views content panes module then all views exists for using in panels. also it provide a news dispaly in views.

Also you can see this video for more getting involve with views pane


How to apply a Field Formatter to a node field programmatically? I have the following code to get the value that is stored in a field

$nid = 76;
$node = \Drupal::service('entity.manager')->getStorage('node')->load($nid);
foreach ($node->field_aaaa as $delta) {
  dpm($delta->value);
}

With this I can get the correct value let says:

 * id_string1
 * id_string2
 * id_string3

But my field has a Field Formatter named title_formatter that will take the string id_string1 and will show something like this:

String 1

In the UI this works fine if I chose my Title Formatter (title_formatter) for the field I can see the 'String' when I viewing my node.

But how to apply the Field Formatter programmatically to the field values?

The entity view builder provides a method to build a render array for a single field using a field formatter:

Drupal\Core\Entity\EntityViewBuilderInterface::viewField()

  /**
   * Builds a renderable array for the value of a single field in an entity.
   *
   * The resulting output is a fully themed field with label and multiple
   * values.
   *
   * This function can be used by third-party modules that need to output an
   * isolated field.
   * - Do not use inside node (or any other entity) templates; use
   *   render($content[FIELD_NAME]) instead.
   * - The FieldItemInterface::view() method can be used to output a single
   *   formatted field value, without label or wrapping field markup.
   *
   * The function takes care of invoking the prepare_view steps. It also
   * respects field access permissions.
   *
   * @param \Drupal\Core\Field\FieldItemListInterface $items
   *   FieldItemList containing the values to be displayed.
   * @param string|array $display_options
   *   Can be either:
   *   - The name of a view mode. The field will be displayed according to the
   *     display settings specified for this view mode in the $field
   *     definition for the field in the entity's bundle. If no display settings
   *     are found for the view mode, the settings for the 'default' view mode
   *     will be used.
   *   - An array of display options. The following key/value pairs are allowed:
   *     - label: (string) Position of the label. The default 'field' theme
   *       implementation supports the values 'inline', 'above' and 'hidden'.
   *       Defaults to 'above'.
   *     - type: (string) The formatter to use. Defaults to the
   *       'default_formatter' for the field type. The default formatter will
   *       also be used if the requested formatter is not available.
   *     - settings: (array) Settings specific to the formatter. Defaults to the
   *       formatter's default settings.
   *     - weight: (float) The weight to assign to the renderable element.
   *       Defaults to 0.
   *
   * @return array
   *   A renderable array for the field values.
   *
   * @see \Drupal\Core\Entity\EntityViewBuilderInterface::viewFieldItem()
   */
  public function viewField(FieldItemListInterface $items, $display_options = []);

To apply this method on a field object you can use $field->view() or if you only want a single value from a multivalue field without the wrapper and label you can also use it on a field item (delta).

EDIT: With this code you can find the values that you need.

$nid = 76;
$node = \Drupal::service('entity.manager')->getStorage('node')->load($nid);
foreach ($node->field_aaaa as $i => $delta) {
  dpm($delta->value);
  dpm((string) \Drupal::service('renderer')->render($delta->view(array('type' => 'title_formatter'))));
}


How to use another php version for drush 9? On live server I use differents drush and php versions for drupal 8.4 and 7.
I install drush 9 to ~/drush9 directory with composer require drush/drush:9.* command.

On dev server and drupal 8.4 I use site.alias.yml file for drush 9:

live:
  host: hostingexample.com
  user: user
  root: /home/user/example.com/public_html/
  uri: http://example.com/
  paths:
    drush-script: '/opt/php70/bin/php /home/user/drush9/vendor/bin/drush'

And for command drush @site.live ev 'print PHP_VERSION' have an error: bash: /opt/php70/bin/php /home/user/drush9/vendor/bin/drush: No such file or directory

If I add

alias php=/opt/php70/bin/php
alias drush9=~/drush9/vendor/bin/drush

in hosting .bash_profile and change drush-script: '/home/user/drush9/vendor/bin/drush' in site.alias.yml. And have an error PHP Parse error:  syntax error, unexpected '[' in /home/user/drush9/vendor/drush/drush/src/Config/Environment.php on line 98. Because on hosting default php version is 5.3.

How to use another php version for hosting and config it for drush 9 aliases?

Try editing both the .bash_rc and .bash_profile files so that you include the directory where the version of PHP you want is FIRST (before existing PATH):

(add this line or adjust if existing):

export PATH="/opt/php70/bin:$PATH"

As a last ditch effort, you can set the env variable drush looks for as well in these files:

DRUSH_PHP=/opt/php70/bin/php


Why is my field not showing up in the template? I created a new field of the type Link for the Basic page content type and the field name is field_secondary_links.

All the pages on the site operate based on custom templates and I edited node--page.tpl.php in order to show the links on the page. I added this:

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

The div appears in the HTML structure, but it turns out empty, even though I know for sure the fields aren't empty. What am I doing wrong?

Using print_r($node), I found out the field is indeed there:

[field_secondary_links] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [url] => http://www.google.com
                            [title] => Link 1
                            [attributes] => Array
                                (
                                )

                            [html] => 1
                            [query] =>
                            [fragment] =>
                            [absolute] => 1
                            [display_url] => http://www.google.com
                        )

                    [1] => Array
                        (
                            [url] => http://ww.google.com
                            [title] => Link 2
                            [attributes] => Array
                                (
                                )

                            [html] => 1
                            [query] =>
                            [fragment] =>
                            [absolute] => 1
                            [display_url] => http://ww.google.com
                        )

                    [2] => Array
                        (
                            [url] => http://www.google.com
                            [title] => Link 3
                            [attributes] => Array
                                (
                                )

                            [html] => 1
                            [query] =>
                            [fragment] =>
                            [absolute] => 1
                            [display_url] => http://www.google.com
                        )

                )

        )

Your code is right. If field_secondary_links is in $content, it should be rendering it out. You might want to double check that the field is named correctly. If you have devel installed, try using dpm($content) to make sure the field is in there, that it is named right, and the the correct data is getting pulled in.

EDIT =======================================================
If $content is unavalible for whatever reason, you can still render this from $node, but it's a bit diffrent. Your code should look like this:

<?php  print render(field_view_field('node', $node, 'field_secondary_links', array('label'=>'hidden'))); ?>

You can remove the array('label'=>'hidden') from field_view_field() if you want the label to show up.

That should prerender and then render the field for you. Not sure why your $content is missing though, but this should be a workable work-around.


drupal_is_front div changer I'm trying to find out how I can use drupal_is_front in order to remove the content_side DIV and rename the content_main DIV (for use with responsive design)

Actually there is no function (built into core, at least) called drupal_is_front(). I believe what you're looking for is drupal_is_front_page() and in your case you could use it like this:

<div id="content_<?php if (drupal_is_front_page()): print 'main'; else: print 'something_else'; endif; ?>">
  ....

Or

<?php
if (drupal_is_front_page()) {
  $divid = 'content_main';
}
else {
  $divid = 'content_something_else';
}
?>
  <div id="<?php print $divid; ?>">
    ....

I think it's also worth mentioning that if you're applying the code to a template file, you should also be able to use the variable $is_front in place of the function drupal_is_front_page(). The difference might be minuscule, but using a variable rather than a function should save you a little bit of overhead on your server.


Test if Anonymous users can sign up for a new account In a Drupal theme, how can you test if Anonymous users are able to sign up for a new account?

Background:

I am theming my user login form according to this tutorial.

On my themed user loser login form, there is an option for users to sign up if they do not have account.

On my site, I periodically disable anonymous sign ups, so when this happens, I want the sign up link in my theme to be not printed out.

If you look at the implementation of the login block in the core user module:

$items = array();
if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
  $items[] = l(t('Create new account'), 'user/register', array('attributes' =>
    array('title' => t('Create a new user account.'))));
}

you'll see that it queries a variable name user_register. If you disable anonymous registration, this becomes 0, and the link to "Create a new account" doesn't show.

This logic should work, no matter how you theme your site.

If your theme breaks this logic in the core user module, then you need to rework your theme until it don't break the core user module.

(Btw - this also tells you how to "test if Anonymous users are able to sign up for a new account" - check the status of the user_register variable, and if it is non-zero they should be able to sign up.  But this does not belong in your theme.  It belongs where it already is: In the core user module. I will advice against putting it in the theme.)


After D8-rc1 install, homepage work but all other links gives a "page not found" I upgraded my Xampp to version Xampp 5.6.12 since Drupal 8 need PHP to be 5.5.9 or better.
I checked out a couple of my Drupal 7 website under the htdocs dir.  They are working fine.

I installed clean drupal 8 in the same htdoc dir under "newd8" folder. I used instructions so that I don't do make any mistakes.

The installation is fine and the default homepage came up at "http://localhost/newd8" and admin login account is working.

BUT clicking on any of the admin menu items, I get "page not found" drupal error. for example, if I click on "people", it goes to the link "localhost/newd8/admin/people" but I get a "page not found"  page.

If I modify the URL to include index.php, thus "localhost/newd8/index.php/admin/people", it works.  I get the right page.

This seem to be for all the pages.  if I manually add "index.php" at the appropriate place, I get the required page.

I have modified the base URL in the  setting.php file then its css file is not loaded properly even home page layout is totally disturbed

What am I missing?

I fixed this.. Thanks to Sumit, I read the .htaccess file more carefully.. Inside the default .htaccess file that comes with the Drupal 8 download, around line 108, comments tells what to do if d8 is installed in a sub-directory instead of document root. I modified line to "RewriteBase /newD8" and now the site works. Even though the same comment is in the D7 version too, On the same Apache server and same document root, D7 works without the modification of the line but D8 needs the change. I don't know why. Because of Symfony perhaps?


How to limit access to certain nodes to certain users only? I am considering Drupal for a project with following features:

I need two content types: Supplier and Client.
I want my clients to be able to follow the progress of their orders (each order will be a node).
My suppliers will have access to their invoices, documents, etc. (which are nodes as well)

Any ideas on how to achieve this?

Example:

Client Alpha will have access to node/34 and node/46 only.
Supplier Beta will have access to node/38 and node/50 and their attached files only.
And so on ...

Is this possible with Drupal (6, 7) ? If so how can I do this, do I need custom coding or are there any other solutions for it?

Depending on how much more deep you want to take the logic of your project, you might not even need custom coding.

Start with Drupal 7 minimal installation profile
Install the modules views, entity, entity reference and their dependencies.
Create the content type "order" and add the fields you need to it. Add other content types as well like "invoice" and document, these last you might want to add a "reference" field to the order content type if they are connected.
Setup the user roles "client" and "supplier" and you might want to install the "ACL" and "content access" modules as well to define who has access to what, like "only"3 the author of the node can see it, edit it and delete it.
To make it easier for the user to see the nodes they have access to, you can create a tab on their user account using views listing only the node where they have access or where they are the authors.

Notes:
You might want to test the system before going live to make sure the right person can access the right content. Also if no anonymous user is meant to use the system disable content access to the anonymous users.


Howto pass the uid of a node to a view inside a dynamic display suite field? I have 1 node of the content type "tourism" and 2 nodes of the content type "tourism news". All 3 nodes belong to the same author (uid 33).

The "tourism" content type has a dynamic display suite field "news" which includes the content pane of a view. This view should displays all "tourism news"-nodes depending on the uid of the requestet "tourism"-node.

When I enter the uid 33 in the preview, the view works as it should:

But when I open the "tourism" node - depending on my configuration - all news or no news are displayed. How do I have to configure the view and the dynamic field to pass the uid to the view?

Thanks in advance.

You are incorrectly setting the 'Argument input' for the Content Pane. It needs to be Node -> Author

Then you need to make sure that you pass the correct argument to it from the Dynamic Field in Display settings for the node. Make sure that you select 'View Panes' and not 'Views'. When you do it will show you the View pane view that you created, and when you select that it will present you with a select list titled: 'Content: Author uid', from which you select the only choice available, which is 'Node being viewed'.

I also do not think that setting the 'When the filter value is not available' in views will have any effect at all. This content pane display is only used for the dynamic field which will always get an argument.


Drupal Views: Create 3-Column Home Page with Taxonomy Terms I am looking to create a 3-column home page design for my site that segregates 3 different items of a given taxonomy type (News, Training Alerts, and Advisories) into 3 separate columns. Each column shows not only the taxonomy term, but pulls the content associated with it (e.g. a teaser view of each item marked 'News').

I am not very familiar with Drupal themes, but currently I have been able to accomplish everything I've wanted with my site using the Bartik theme. Are there any ways I can accomplish this using Views and without having to change much about the Bartik theme? Or alternatively, is there a way to just create a table with PHP code that pulls the content associated with each taxonomy type into each column of a 3-column table?

You can do that easily with your bartik theme.
You can use Panels and page manager with views.

It's not easy to use but it's worth it. There is a great screencast series in nodeone.se.

To be short:

In views: you'll make a content pane (not a block or page)
With panel you can retrieve all the information from this pane and choose your layout and where you want to put all your fields inside it.
In your case you can make 3 content pane, each one with a specific taxonomy. After that you'll choose in which columns you'll want to put them.


Display comment count in a view Using views I would like to display the number of posts by a user. This will include a count of nodes as well as comments.

e.g.

Jon
Nodes: 10
Comments:6

Jane
Nodes: 22
Comments: 9

etc....

I have created a view of type user. I can find the user: content relationship and with aggregation turned on, I can get the node count. However I do not see a user: comment relationship o get the comments that the user has created. Am I missing something?

This small Views user: comments relationship patch should be just the ticket: http://drupal.org/node/1773966

  ...I ended up creating a "User: Comments authored" relationship. Very
  useful. Combined with aggregation and using "count distinct" it allows
  a user view to include # comments authored and # of nodes authored.

Direct link to patch: http://drupal.org/files/views-uid_comment_relationship.patch


What should I enter as "Database file" for a SQLite database? So I've practiced making Drupal 7 before using XAMPP and I want to try to make a Drupal 8 page but I have no clue about what to put in the field you can see in the picture below. I made a database in PHPmyadmin.

What should I enter in the Database file field?

This configuration dialog is for SQLite-type databases only, it might be that your installation only has activated the PHP modules for this type of databases (for MySQL databases, you need pdo-sql, see here: https://www.drupal.org/node/2219779).

If you wish to use a SQLite database (which should work fine for testing purposes), you can either indicate a location for your SQLite database file, or leave the default, which should work fine. The Drupal installer will create the SQLite database for you in that location; you don't need to create it separately.


how can i remove the login form from the home page I'm trying to remove the login form from the front page, but i see both frontpage and user/login page are using the same template file: page--front.html.twig.

Is there a way to use two different template files for each page?

Try going to Admin/Structure/Blocks and set User account menu's region to None.


Imagecache Custom Actions - Imagemagick I cannot get my imagecache custom actions to work at all?

When returning $image in any way, it gives me an error, which can be resolved by adding in the first line here:

if (!$image_context['entity']) { return 'No referring entity'; }
$image->ops[0] = "-resize 1600x1600";
return $image;

That should simply just resize my images now?

Essentially, my end goal is to check the value of a field submitted with the node which also submitted the original image, and then based on its value, apply a watermark. I am just toying about with custom PHP right now... but I can't seem to get any custom actions to work right now... Any help would be great, thanks! :D

Juste return "TRUE", not "$image", It is works for me.

 $image->ops[] = "-resize 1600x1600";
 return TRUE;


view 3: filter for datetime field is not working I have created a customised module that export the content of a remote database tables to the view interface, every thing works fine except of the filter of the datetime field. In my file: mytable.views.inc

function mytable_views_data() {
  $data = array();
  $data['table1'] = array (
  'table' =>
   array (
    'group' => 'table1',
    'base' =>
     array (
      'field' => 'id',
      'title' => 'table1',
      'help' => 'table 1',
      'weight' => 10,
      'database' =>'database-name',
    ),
  ),
  'id' =>
   array (
    'title' => 'Id',
    'help' => 'Id',
    'field' =>
     array (
      'handler' => 'views_handler_field_numeric',
      'help' => 'Id',
      'click sortable' => true,
    ),
    'filter' =>
    array (
      'handler' => 'views_handler_filter_numeric',
      'allow empty' => true,
      'help' => 'Filter on Id',
    ),
    'argument' =>
    array (
      'handler' => 'views_handler_argument_numeric',
      'help' => 'Id',
    ),
    'sort' =>
    array (
      'handler' => 'views_handler_sort',
      'help' => 'Sort by Id',
    ),
  ),

     'date' =>
      array (
      'title' => 'Date',
      'help' => 'Datetime field',
      'field' =>
       array (
      'handler' => 'views_handler_field', // I tried also 'views_handler_field_date' and 'views_handler_field_datetime' but view displays the message field handler is broken
      'help' => 'Date',
      'click sortable' => true,
    ),
    'filter' =>
     array (
      'handler' => 'views_handler_filter_date',
      'allow empty' => true,
      'help' => 'Filter on Date',
    ),
    'argument' =>
    array (
      'handler' => 'views_handler_argument_date',
      'help' => 'Date',
    ),
    'sort' =>
    array (
      'handler' => 'views_handler_sort_date',
      'help' => 'Sort by Date',
    ),
  ),

);

return $data;
}

all the data fields are displayed properly in the view interface :

and the filter of the field datetime is displayed also:

The problem is the filter have no effect on the datetime field, I tried to filter the field but the filter has no effect and the data was not filtered, I think that there is a non compatibility issue between the field handler and the filter handler but once I tried to use the field handler: 'views_handler_field_date' or 'views_handler_field_datetime', the views didnt displayed the data of the datetime field and it has indicated that the field handler is broken, and with the handler 'views_handler_field' every things is displayed well but the filter is not working!

Try this handler views_handler_field_date, then uninstall and reinstall the module and try. Otherwise your changes will not affect.


How to get the user entered input value to do calculation? I am developing bank loan application in drupal 7. In my first page there is a option to enter the loan amount then --> Search the available loan. In a second page(form) i need to display the available loan offers, interest, etc... based on the user entered value in page-1. Now i need to get the user entered value on page-2 and have to check with DB(Database) and then needs to display the results. Help me to get out the solution.

Store the loan amount in session when user submit the form1, and when rendering the form take that session value and display a suggestion field.

The code will be like below,

function form1_submit($form, &$form_state) {
  $_SESSION['loan_search_amount_field_value'] = $form_state['values']['loan_search_amount_field_name'];
}

function form2() {
  $form = array();
  $loan_amount = $_SESSION['loan_search_amount_field_value'];
  //db_query using $loan_amount
  //$db_result_array = db_query();
  $form['load_options'] = array(
    '#description' => t('Loan options'),
    '#type' => 'select',
    '#title' => t('Field type'),
    '#options' => $db_result_array,
    '#size' => 2,
  );
  return $form;
}


How can I render or change programmatically the responsive image style for an image field for a paragraph? I want to allow the editor user to be able to select different responsive image styles to render an image field from a paragraph field. So I have defined another field where the user can select the responsive style they want.

The problem is that I can't apply that responsive style on the fly on the twig template, so I tried to altered the field or create the picture element and assign it to a variable I can access from the template in the hook_preprocess_field, but I can't access the url of the image in the variables. So I don't know how to carry on.

Is there a way to achieve this?

You don't need to swap the image, only the information how to render the image. And you can't do this in a field template. This is only possible in the paragraph template, where both fields are available:

function mytheme_preprocess_paragraph(&$variables) {
  if ($variables['paragraph']->hasField('field_image_style')) && isset($variables['content']['field_image']['0']) {
    $image_style = $variables['paragraph']->field_image_style->value;
    $variables['content']['field_image']['0']['#responsive_image_style_id'] = $image_style;
  }
}


Display node local tasks on custom page I've created a custom route for each nodes, let's say /custom-page/{node}, which renders some specific stuff from a Controller.
On this custom page, I'd like to automatically display the same local tasks as displayed on nodes canonical pages (In my case : View, Edit, Delete, Devel)
I know I can set dynamic local tasks using a Deriver in links.task.yml but how can I load local tasks from another route ?
Or maybe there is a way to tell Drupal to display local tasks as if it was for the route "entity.node.canonical" ?
Thank you for your help !

Ok actually this was a stupid question...
I was trying to add the node tabs on my custom page without adding a tab to this custom page on the node view itself (entity.node.canonical)
Simply adding the new local task on the node view automatically displays other tabs when viewing any of the tabs
my_module.links.task.yml :
my_module.my_custom_tab:
  route_name: my_module.custom_page
  title: 'Custom'
  base_route: entity.node.canonical


Views field for content access? I'm building a membership site and I'm trying to find the best way to tease content that's only available to subscribers but show it in the same view as content available to all.

I'm currently using the content access module and while I'm able to generate the view that includes both open and restricted content I need a way to attach a lock icon to the rows who have restricted access. My thought was to have the view output the content access permission as a field but content access doesn't appear to have anything currently exposed to views.

Has anyone done something like this before? I'm open to using a different access control module as long as I can set permissions on a per-node basis.

I haven't used this in a while (2 years), but it did what you described back then!

https://www.drupal.org/project/field_permissions


What is the correct way to update existing module's rules programmatically? I want to provide an update for my custom module, which also has some rules provided via hook_default_rules_configuration.

Now, how can I update those existing rules? Can I re-import them? Override them somehow? I cant find anything about this in the documentary or an respective hook.

There seems to be a hook to respond to rules being updated, so I guess there must be a way to provide updates for custom rules...

At first I thought it was hook_default_rules_configuration_alter but it doesnt seem to work as expected since I just want to import JSON.

For instance, using views I can simply load all .inc files and save them via views_save_view like in this question - isnt there a similar way in rules?

You can export the rules configuration via the Rules UI and then implement hook_default_rules_configuration_alter() like this:

/**
 * Implements hook_default_rules_configuration_alter().
 */
function MODULENAME_default_rules_configuration_alter(&$data) {
  if (isset($data['commerce_cart_add_to_cart_message'])) {
    $data['commerce_cart_add_to_cart_message'] = entity_import('rules_config', '{ "commerce_cart_add_to_cart_message" : {
        "LABEL" : "Display an Add to Cart message",
        "PLUGIN" : "reaction rule",
        "OWNER" : "rules",
        "TAGS" : [ "Commerce Cart" ],
        "REQUIRES" : [ "rules", "commerce_cart" ],
        "ON" : { "commerce_cart_product_add" : [] },
        "IF" : [
          { "data_is" : { "data" : [ "commerce-order:commerce-nocart" ], "value" : "0" } }
        ],
        "DO" : [
          { "commerce_cart_add_to_cart_message" : { "commerce_product" : [ "commerce-product" ] } }
        ]
      }
    }');
  }
}

Just change the instances of $data['commerce_cart_add_to_cart_message'] to use your rule machine name and replace the export string with your own.

You can also use rules_import() instead of entity_import(). Either is acceptable.

Since the rules module loads default rules from code into the database and from then on loads them from the database, it won't immediately pick up your override.
To make it do so navigate to the Rules UI and revert the rule. It will revert back to the default code, which will be your override.

To programmatically revert a rule you can do this (again replacing the rule machine name):

if ($rules_config = rules_config_load('commerce_cart_add_to_cart_message')) {
  $rules_config->delete();
}

An example usage of that may be to do it during an update function for a custom module.

It may seem wring to be deleting it but delete and revert are equivalent for rules that are provided by code because delete means delete from the database. If this was a rule created via the UI then it would be gone, however a rule from code will just delete from the DB and then read in again from the code.

Unfortunately there are currently only drush commands for enable/disable of rules.
There is a feature request for a delete/revert command at https://www.drupal.org/node/2507187


Can I sort a view by a custom date field without the date module? I would like to organize products in my site by year of production.
And sort them in a view. With the date(year) as exposed filter, in this format:

Products :
From  year :…
to year:….

Can I do this only by creating a CCK text field with a list of years?
Or should I use the date module instead?

If I have to use this module , How can I change the format in which the date is input. By default, it shows years ,months and days. I want it to show only years.

Using date field gives you more flexibility, but year made with text field would work also.

But in my opinion after your site grow larger you will probably say to yourself: "Gosh, now I wish to order with moths and days..." and you'll regret not using date field at the beginning.


How to programmatically get the Title for a Local Menu Task? I have a long list of menu items so i'll cut it short here:

$items['admin/skyview'] = array(
    'title' => 'Skyview Main Page',
    'type' => MENU_NORMAL_ITEM,
    'access callback' => TRUE,
    'page callback' => 'skyview_main_page',
);
$items['admin/skyview/tab1'] = array(
    'title' => 'Skyview',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'access callback' => TRUE,
    'weight' => 0,
);
$items['admin/skyview/tab5'] = array(
    'title' => 'Sites',
    'type' => MENU_LOCAL_TASK,
    'access callback' => TRUE,
    'weight' => 4,
    'page callback' => 'skyview_sites',
);

But my question is how do I programmatically get the title of 'Sites' for tab5? When I use menu_get_active_title it returns 'Skyview Main Page' instead.

I've looked through phpstorm for what options it gives me, but I really don't find anything to get the title of a menu local task, however I noticed this can be done in D8 but can it be done in D7?

I figured out how to finally get the title.

I was using dpm(menu_get_item()); which listed an array, but I had no idea how to access it. I just had to turn it into a variable to hold that data, then I could access it!

$db_site = menu_get_item();
$db_site = $db_site['title'];


views showing only 1 node with specifiec field value Displaying problem with views.
I am trying to make a ranking for my track club.

Every result by someone is a node.
I can make a global ranking with views showing all results sorted by running time (lowest time is first item).

Ranking total view looks like.

name    - time  - place
runner1 - 12.00 - city1
runner2 - 12.01 - city1
runner3 - 12.10 - city1
runner1 - 12.15 - city2
runner1 - 12.20 - city1
runner3 - 12.25 - city5
runner4-  12.40 - city1

I need a ranking system with only the best performances. Curently a have used VIEWS AGGREGATOR PLUS (view first item on name) to help me filter some nodes. So my bad 'best results view' looks like:

name    - time  - place
runner1 - 12.00 - city1
runner2 - 12.01 - city1
runner3 - 12.10 - city1
runner1 - 12.15 - city2
runner3 - 12.25 - city5
runner4-  12.40 - city1

I can't seem to only select the node with the best perfomance if there is another node from the same runners result in another city.

My ranking should look like:

 name    - time  - place
 runner1 - 12.00 - city1
 runner2 - 12.01 - city1
 runner3 - 12.10 - city1
 runner4-  12.40 - city1

So my views should :
Select node where 'time' is lowest per 'name'.

How can I do this?

Views is a simple query builder. It is good at building 1 query, or many simple queries. There are times when relying solely on Views, and the assumption that your logic and be easily tailored to Views may fail.

This is such an example where it would benefit you to do some of this work outside of Views itself and store and compute metdata on to more easily generate reports.

For example you could install Nodequeue, Views Bulk Operations and Rules to perform the following tasks:

create a nodequeue for city_fastest_times_results. Create 1 nodequeue per city.
Write a Rule that upon saving of a track time examines if it is the fastest time yet recorded for that city. If so, insert it into the appropriate nodequeue.
Using VBO to reuse the rule you defined in 2 to run this processing on any previously entered data on the website.

note: a SmartQueue may be able to allow you to encode this logic as well, as opposed to Rules.

Instead of Nodequeue you could also use the Relation module to relate cities, runners and times.

So, the nodequeues can store the fastest times per city and self-update based on Rule logic, or occassionaly by an admin using a VBO form. To show a report you would then just have SELECT * FROM {nodequeue_N} ORDER BY time DESC, which is trivial using Views.


How to delete content type menu item in .install file on module uninstall /disable I have a module that adds a content type in the .install file. When I disable the module how do I remove the content type entry from the menu?

Using a hook_uninstall() in your .module you can implement.

/**
 * Implements hook_uninstall().
 */
function YOURMODULE_uninstall() {

  // List custom content types that you want to delete
  $custom_ctypes = array(
    'blog',
  );

  // Go through each and unlock the content type
  foreach ($custom_ctypes as $ctype) {
    db_query("UPDATE {node_type} SET `custom` = 1, `locked` = 0 WHERE `type` = :ctype", array(':ctype' => $ctype));
  }

  // Clean Drupal cache; this is necessary for the "Delete" link to appear
  drupal_flush_all_caches();

}

Now you'll see the delete link on the menu and you can delete the content type. I think it's the only way you can delete the content type with fields.

But you can try using the function below too, afaik it will not delete the content fields:

/**
 * Implements hook_uninstall().
 */
function MYMODULE_uninstall() {
  // delete the content type
  node_type_delete('CONTENT_TYPE_NAME');
  variable_del('node_preview_CONTENT_TYPE_NAME');

  // node type rebuilds
  node_types_rebuild();

  // rebuild the menus
  menu_rebuild();
}


How do I add a link to a table row in a custom module? I am making a sortable table in a custom module. If I put the whole link as part of the row information, the URL does not come out right.

I tried the following code.

  array(
    'data'=>array(
      '#title' => $entry['name'],
      '#type' => 'link',
      '#url' => $entry['link_url'],
    )
  )

I also tried what suggested on https://www.drupal.org/node/745272,  which describes how to do it for Drupal 7.

I also tried this code.

 $rows[] = array(
   array(
     'data' => array(
       'name' => new FormattableMarkup('@name', [':link' => $entry['link_url'], '@name' => $entry['name']])
     )
   )
 );

Neither displays anything.

How do I achieve this for Drupal 8?

This worked for me

use Drupal\Component\Render\FormattableMarkup;
  $rows[] = array(

      array('data' => new FormattableMarkup('@name',
        [':link' => $entry['link_url'],
        '@name' => $entry['name']])
      ),


Customize Search Form Block Text I'm attempting to customize the search form block. I'd like to be able to change the search submit button, by either changing the text, or turning it into an icon and other various changes.

I assumed I'd be able to make these changes within a template, but the default block--search-form-block.html.twig only contains

{%
  set classes = [
    'block',
    'block-search',
    'container-inline',
  ]
%}
<div{{ attributes.addClass(classes) }}>
  {{ title_prefix }}
  {% if label %}
    <h2{{ title_attributes }}>{{ label }}</h2>
  {% endif %}
  {{ title_suffix }}
  {% block content %}
    {{ content }}
  {% endblock %}
</div>

I don't see anyway I can change anything such as the submit text. Is there any way to make direct changes to the search form block?

try something like

#search-block-form input[type="submit"] {
background-color: white;
padding: 15px 25px;
color: black;
border-radius: 0px;
border: 1px grey dotted;
background-image: url(http://cashbin.win/sites/default/files/favicon.ico);
background-size: 30px 30px;
background-repeat: no-repeat;
background-position: left;
padding-left: 30px;
}

This is an example obviously replace the image and/or border, color, background, position, and padding options.

Add this into you /sites/all/themes/CURRENT_THEME/css/style.css

Hope this helps, God Bless!


Fraud detection on hotmail from Simplenews Newsletter I send newsletters from my Drupal-7 website using Simplenews newsletter module.
But when a user has hotmail, the mail comes with a flag "Be careful. This sender is not approved by our controls for fraud detection."
I googled this and I saw that it has to do something with SPF but I don't understand what this is and what steps do I have to do to fix this issue.
Is there an option from administrator or a line of code I can use?
Thanks in advance!

There are a few steps you can also carry out by looking here How can I prevent my mail from being classified as spam?. It includes setting up Domain Keys, SPF etc.

You can also refer to some steps for Microsoft here How to prevent email sent from drupal from going into spam box.


Distance / Proximity from cck location field ? not from user or node location? I try to get a distance between cck location nodes / users but I didn't succeed at that point because the only avalaible views field to do that is  "EMPLACEMENT : DISTANCE / PROXIMITY" which concerns node location or user location, not cck location field.

How to get that point ?

Regards,
Yoann

Results may vary based upon your drupal version, but basically when you create a proximity filter:

the first option is "Node location" but when you click on that:

it will allow you to use a Location CCK field as well.


Cannot login to turn off maintenance mode after 7.24 I am new to Drupal, and although I managed to understand most of its principles, it seems I broke my site when trying to update it to the latest 7.24 release.

As instructed in UPDATE.txt, I entered maintenance mode and deleted all folders except sites/, which I had backup of course. I then copypasted all the new folders (including .htaccess) to my installation, and tried to run the update script. However, the update script said there were no pending updates. After that, the site was in maintenance mode, and even from my already logged in account I could not turn it off. I tried logging in again, and now I'm stuck in maintenance mode, and /user page redirects me to the main one. I tried emptying the cache tables, but nothing happened. I also tried copying the folders again, with no results. I enabled "update_free_access", and tried running the update script again, but no results.

Is there any way to avoid a blank installation?

7.24 has a security update and needs to add or change your .htaccess file for you public and temp files directory.

See what you have to add/change in drupal.org and here. I haven't done the 7.24 update yet so, this is as much i can help.


nodeapi with op = load being ran multiple times I am currently creating a custom module. I am trying to alter a node's body before it is displayed to the user. So I used hook_nodeapi();

I did something like

function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
  if($node->type=='page' && $op =='load'){
    dsm($op);
    //the rest of my code goes here
  }
}

When ran, this displays  8 "load"s when viewing a page.

Why is that? I think it is because of the other modules I have that may be calling node_load, but I am not really sure.

Can anyone shed a light here? And how do I make it possible so that my code is not ran multiple times (in this case, 8 times)?

Thanks.

UPDATE:
I forgot to mention a couple of key things.

I am using the revisioning module. The page I am viewing is an unpublished revision. I tried this:

function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
  if($node->type=='page' && $op =='load'){
    dsm($node->nid);
   dsm($node->vid);
   //the rest of my code goes here
  }
}

I get 8 similar nids, and then 7 similar vids (the unpublished revision), and then 1 vid (the currently published revision)

916
4544

916
3740

916
4544

916
4544

.. and so on

You need to use view $op

function hook_nodeapi(&$node, $op, $teaser, $page){
  if($node->type=='page' && $op =='view'){
    if ($teaser) {
      drupal_set_message("I am viewing page content type teaser");
      //the rest of my code goes here
    }
    if ($page) {
      drupal_set_message("I am viewing page content type full node view");
      //the rest of my code goes here
    }

  }
}

  view: The node content is being assembled before rendering. The
  module may add elements $node->content prior to rendering. This hook
  will be called after hook_view(). The format of $node->content is the
  same as used by Forms API.

And you need to check for teaser view or full node view using $a3 or $a4 respectively.

Check how many nodes you are rendering in a page. For example if you are in a view where view is displaying 10 nodes then 10 times message will appear.

Hope it answers your issue !


How to use predefined drupal elements in a custom block/module? This is regarding the user block but the question is general and could be related to any standard block/module: How to use in a custom block elements that have been defined in standard modules? (for example the "username" field defined in the user block)
What is the way to access these elements in my code?

If the above is not clear, in other words what I would like to do is to use the "username" , "password" , "..." and all the elements defined in the user module, as independent elements in my custom block. And then build my own Submit which will include both standard drupal and custom items.

I think hook_form_alter will not do this trick because it is 1 level higher, right? i want to go one step more into details and manipulate the form items, no the form itself.

When building your own form in your module, you can simply read your defaults from $user variable. Then, in your submit function, use user_save() function to update your user.


Embed block into a custom views template I created a custom views template that I have called views-view--page.tpl.php. Now I would like to add a block into the template file.

In my page template file I was able to render a region and do this:

<?php print render($page['leftsidebar']); ?>

But it seems like this will not work for a views template. I am not the best with PHP so any help would be great!

I'm using Drupal 7.

Using the answer given to me in the comments by @subhojit777 I was able to call it up using this code:

<?php
  $block = block_load('MODULE_NAME', 'DELTA');
  $output =      drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
  print $output;
?>

I don't know if this is the best way, but it's working for now. :)


ERR_EMPTY_RESPONSE during installation with PHP 7.3 I'm trying to install Drupal 8 with PHP version 7.3.0RC4.

When I go to http://localhost it redirects me to http://localhost/core/install.php with the empty response error.

I checked the Apache error log, nothing, edited the PHP config (php.ini) to display all errors but nothing shows up.

However, when I downgrade to PHP 5.6 it works. Is Drupal ready for PHP 7.3?

Drupal doesn’t officially (or unofficially as far as I’m aware) support PHP 7.3 at time of writing.

You should downgrade to PHP 7.2, and probably consider revising your operating procedures so you don’t end up using pre-release versions of PHP.

If you still see a problem, you probably haven’t configured Apache and mod_php correctly for the new version.


No Settings for SMTP module I installed SMTP module for Drupal 7.
I enabled it and press Settings button to go to Settings menu.
But there is no Setting menu there...
How to reach it?

The SMTP module configuration page is at admin/config/system/smtp.

Make sure that you have the permission change the SMTP configuration.


Views Page not showing pager I've got a Views Page showing Article teasers. There are lots of Articles in the db and I'm only showing 5 per page in the View, but the Pager is not showing up at all. Here is my Views configuration, am I doing something wrong? Is there a bug?

The preview in the Views screen does not show a Pager at the bottom of the content teaser and it also doesn't show on the real page.

Any ideas?

This can have a whole bunch of reasons. I'm just providing the imho most probable non-obvious one:

Go to "pager settings" (on your screenshot click "Paged, 5 items") and change the "pager id". Docs say this is only needed when there is more than one view on a page, but i saw live examples where this fixed a non-showing pager on a single-view page.


Drupal 6 Views Slideshow configuration I am trying to create a gallery like this.

It's been a while since I worked on a D6 site I am sure I have done this before on a few 2/3 year old websites.

However, when I try configuring Views to generate my image gallery I don't get a slideshow style option. I have attached an image to show the View configuration area to see what I mean.

Can anyone help me with this, please?

It's looking like you have Views 2 installed, so, make sure you have the right Views Slideshow module installed as there is one for Views 2 and another for Views 3 per the Views Slideshow Module page on drupal.org:

Requirements

Views Slideshow 2.x requires Views 2.
Views Slideshow 3.x requires Views 3.


How to display Rate module widget by php I'm using the Page Manager (Panel) to customize the node layout, and the Rate module to rate them.

How to print the rating widget of the current node using php ?

I've tried to use this code but no result.

<?php  print rate_embed($node, 'page_rating', RATE_FULL);  ?>

print rate_embed($node, 'plus1', RATE_FULL);

Here, first parameter($node) is the entity where you want to vote
'plus1' is the type of widget that you want to add
RATE_FULL is the display type of widget . Either it can be full or mini.

Try by passing $node =node_load(10). Where 10 is id of some node that exists in the site

Hope it will help


How to open User registration in a pop up? I'm using Fancybox to open user registration page in a pop up window. Here is the code

$('.fan_popup').fancybox({
  type: 'iframe',
  href: '/user/registration',
  width: 800,
  padding: 5,
  height: 600
});

The pop up window is shown but the page gives message like "You are not authorized to access this page.". How to overcome this.

Probably your server's settings prevent opening registration pages within frames. This prevents embedding your registration form in 3rd party webpage to create spam users et cetera. That is usually a good thing, even if what happens to you is over-restrictive.

Now, why to reinvent the wheel? There is a Modal forms module ready.

  Modal forms make use of the modal feature in the ctools module to open some common forms in a modal window.
  Supported forms

  Log in (modal_forms/nojs/login)
  Request new password (modal_forms/nojs/password)
  Create new account (modal_forms/nojs/register)
  Contact (modal_forms/nojs/contact)
  Comment (modal_forms/nojs/comment/reply/%node)
  Webform (modal_forms/nojs/webform/%node)

Emphasis mine.

It has some bugs, but for first 3 it works pretty well. Or at least it used to.


Weird gibberish characters appearing on bottom of Drupal 7 pages What are some reasons to why there would be weird gibberish characters appearing on the bottom of a Drupal 7 site? I work in a linux environment, but sometimes I copy the files over from windows. I'm not sure if that is the culprit, but how would one even debug something like this?

Since these characters appearing within certain section of the website, you need to identify the source of it and which rendering element is responsible for it (either template file or some function).

The easiest way would be to track it down by enabling theme_debug variable in your settings file which enable you to debug the output of the rendering engine.

So please add this line into your settings file:

$conf['theme_debug'] = TRUE;

then refresh the page and check the source code to see which rendering element is outputting this.

For more advanced solution, use PHP debugger such as phpdbg (in PHP >=5.6 core) or XDebug (which allows you to generate a trace file and find the source of the problem). Here is sample xdebug.ini config, so in your scenario you just need to enable xdebug.auto_trace, generate a trace file for single page load, then disable the setting (since it hugely impacts the overall performance). Then open a generated trace file, look for gibberish where they've started to appear and find out which code is generating it.


Open node as popup with Lightbox 2 I recently upgraded my site to Drupal 7 and felt a need for opening some specific node as popup using Lightbox 2.

I have been through the documentation, and I found out that in Drupal 7 this feature can be implemented by adding a new template file in theme's directory named page--node--[nid].tpl.php.

The problem is that, when I implemented it this way, I wasn't able to view the node content properly as in the template I removed the header, sidebars etc.

So when I try to access the node via www.example.com/node/[nid] only content would appear without showing any headers or sidebars.

So has anyone implemented this feature using Lightbox 2 in Drupal 7?

In your tpl.php file only have the following

<?php print render($content); ?>

If you want to style it you can wrap divs around.

Then add a rel="lightframe" attribute in your link that will trigger lightbox.

Link


Views entity reference field condition OK, so this is a bit tricky, let's see if you can follow my problem:
(just let me know which part you don't understand 1,2,3...) I am using Drupal 7

1) I have 2 content types: Workers and Documents

2) In the content type Documents I have the entity reference field of all the workers. (Eg. I want to add a document/node that refers to a specificic worker John)

3) In the content type Documents there is a list field the user can select two options: red or green (it's a field where the user can say the document is OK to use)

4) Everytime I add a Document, I have to select red or green in that field.

5) Right now, I am displaying a view with all the nodes/documents from the content type Documents refering to the title and List field (red or green). Something like this:

Document 1 ------------------ red

6) On another page, I am displaying a view with a list of all workers (Content type Workers) and here comes the tricky part:

I want to add a field in this view displaying red or green based on this condition: IF (all the Documents from the entity reference "specific worker" have "green" on the field): display green.
IF (one of the Documents has the field "red"): display red

It will diplay something like:

John --------------- green

How can I achieve this with views? Do  I need to write code? Thank you.

Here is a zero coding solution.

Create a new view:

CONTEXTUAL FILTER add Node id (since workers is a content type), so we have the id of the worker.
RELATIONSHIP add Referecing Entity, checkmark require relationship.
Fields: Add Title

At top you will see a select box, select the relationship option.
Unchecked Link this field to the original piece of content
Click on NO RESULT BEHAVIOUR, put Green
Click on REWRITE RESULTS, checkmark Rewrite the output of this field, put Red

In FILTER CITERIA add type and select Workers.
In FILTER CRITERIA add the List Field (the one that contains Red or Green) and put is equal to Red and select relationship option at top.

for PAGER put 1 item.

Install and enable Views Field View

Now in your List of All Workers view:

In FIELDS add Node ID and checkmark hide field from view.

In FIELDS now Add the View Fields view field.

Select the previous view we created.
For argument, Click on replacement patterns, and use the Node ID token to pass as an argument.


How to duplicate a line item in shopping cart programmatically At certain point in the checkout process I'd like to seperate line items with quantity more than one into individual line items with quantity 1.

So for example if I have a line item in cart with quantity 5, I'd like to create 4 new line items just like the original one, add them to the cart with quantity 1 individually.

I tried cloning the line item entity into a new variable and use commerce_line_item_save() with it, but it doesn't work.

Does anybody know how to achieve something like this from a module?

Thank you!

You can clone a line item and save it without any problems:

$cloned_line_item = clone($line_item);

But if what you want is to add it back to the order, you'll probably want to call commerce_cart_product_add to add your line item back to your order:

commerce_cart_product_add($uid, $line_item, FALSE);

Be careful with setting the combine options correctly if you don't want your line items to be aggregated.

$line_item->data['context']['add_to_cart_combine']

Update: Adding more details on the combine part.

In case you don't want to combine any line items for that product type:

Be aware that the combine options are at formatter level for the add to cart button, so you need to set them everywhere you're using this formatter, in manage display settings for all your view modes, in views... the configuration is not shared. This is very important as there might be hidden places you forgot to configure (if I had a penny every time I forget to configure this in "Teaser", i.e....)

In case you want to combine some times and others not:

The function commerce_cart_product_add above has a combine parameter to make Drupal Commerce try to combine or not and add a new element to the cart or just increase the quantity of an existing one.
On top of that, there's something called comparison properties, by default these are all the fields that the line item has:

foreach (field_info_instances('commerce_line_item', $line_item->type) as $info) {
  if (!empty($info['commerce_cart_settings']['field_access'])) {
    $comparison_properties[] = $info['field_name'];
  }
}

So one way you've got to hook into this process is hook_commerce_cart_product_comparison_properties_alter to define more comparison properties.


How do I unset/hide certain fields from being indexed by the core search module? If a content type has additional text fields, search core automatically indexes them because search core extracts all text from the result of node_view()

I can easily add extra index data via MODULE_node_update_index( $node ). This particular hook argument, $node, is passed by value and not by reference which means I can't unset certain items.

I hook into node_view, and alter it there but I don't want to change the output of the node normally, only when it's being indexed.

Goto the Manage Display page for each content type (eg, admin/structure/types/manage/page/display).

Click on the tab for Custom Display Settings.

You will see the view modes that your system knows about.  Tick Search Index and save.

You can now configure which fields get indexed from the tab for that new display mode (eg admin/structure/types/manage/page/display/search_index)

Dump the search index from Configuration -> Search -> Search Settings ( admin/config/search/settings), and cron runs will re-index everything.  Or, do a drush -y search-reindex; drush -y search-index from the command line.

Start reading from node_update_index() which is invoked from search_cron(), and you will eventually see a node_view($node, 'search_index');, which is how that display mode gets used.


Custom comment access I need to prevent users from posting comments based on some conditions but I can't find any hooks I can implement.

For nodes we have hook_node_access() but apparently there is no hook_comment_access()

Any ideas on how I can implement this?

I have tried something like this but apparently it doesn't work:

function my_module_entity_info(&$entity_info) {
  $entity_info["comment"]["access callback"] = "my_module_comment_access_callback";
}

function my_module_comment_access_callback($op, $comment){
  // some custom logic and return false...
  //...
  return comment_access($op, $comment);
}

My form is a custom form, displayed on multiple pages. I would like to prevent access to the comment entity and not to the form or page.

You can get code from Comment Permissions and Comment Access modules.

something like

function comment_perm_form_alter(&$form, $form_state, $form_id) {
  #comment_node_merci_reservation_form
  if ($form['#id'] == 'comment-form' and arg(0) == 'comment') {
    $types = variable_get('comment_perm_node_types', array());
    $form_id_types = array();
    if (is_array($types)) {
      foreach ($types as $type) {
        if ($form_id == 'comment_node_' . $type . '_form') {

          $nid = $form['nid']['#value'];
          if (! comment_perm_access($nid)) {
            // for comment reply pages, redirect back to the node
            if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) {
              drupal_set_message(_comment_perm_access_denied_message($nid), 'error');
              drupal_goto('node/' . arg(2));
    }
  }

          if (arg(0) == 'comment' && arg(2) == 'edit' && is_numeric(arg(1))) {
            if (! comment_perm_edit_access($nid)) {
              drupal_set_message(_comment_perm_access_denied_message($nid), 'error');
              drupal_goto('node/' . $nid);
            }
          }
      }
  }
    }
  }

}

then you can add you own condition.

You can also use above module ,if it is fulfilling your requirement.


How to give user permissions to edit other user fields except user id & pwd? Hi i am using drupal 7 website in my site having 3 different role of users 1st role of users need to edit 2nd role of user fields  except user id & pwd & email & roles.i have tried with administer user permissions,it is possible to edit user id and pwd.Also i have tried with user protect module no use,Any suggestions on this it will be very helpful.Thanks in advance.

I think what you want is Restrict Password Change module.

Related modules:

https://www.drupal.org/project/user_readonly
https://www.drupal.org/project/userprotect


Change field requirements on validation? I am new to Drupal so forgive my newb question.

I am trying to remove the required true from a form field if a user clicks on a certain button  so i tried to do it via form validaiton:

$form['#validate'][] = 'my_from_after_build'; //Calls function

function canvas_from_after_build($form, &$form_state) {
  echo "this is the form after building";
  $form['field_title_tag_list_article']['widget'][0]['#required'] = FALSE;
  return $form;
}

but it still gives a "this field is required" error.

The validation function in the Form API is meant to evaluate the user input and report the errors back to the user if any.

You could change your logic in this way to facilitate your implementation:
 - The field _field_title_tag_list_article_ is not required by default
 - In the validation function, you would check whether the value of a second field (i.e. _field_validate_titles_) is set to a given value (i.e. _field_validate_titles_ == 'needs validation').

It would look something like this:

if ($form_state['values']['field_validate_titles'] == 'needs validation' &&
  empty($form_state['values']['field_title_tag_list_article'])) {
  form_set_error('field_title_tag_list_article', t('The title tags are required.'));
}

You could download the Drupal Examples modules and install the _form_example_ module, then check the example number 6.

Advice for new users

In general, I suggest you browse the examples so that you are familiar with this handy reference.

Quite often, you will find that someone else had the same problem before. Sometimes, there is a community contributed module that solves your problem.

In your particular case, the conditional fields module could help you accomplish your goal without having to write a single line of code:

Conditional fields module page.
Conditional fields module documentation.


How to set the behavior for Pathauto when a duplicate exists? I'm creating a Drupal 7 site which will consist of information about many different organizations across North America. The profiles will be submitted by the organizations themselves and it is very likely that there will be duplicate names.

What I'd like to do is have Pathauto create the url: orgs/OrganizationName for the first such organization and after this create: orgs/OrganizationName-City.

Is there any way to change how Pathauto behaves when duplicates are found?

You could create a module and use the hook_pathauto_alias_alter function to override the path alias before saving it.

function mymodule_pathauto_alias_alter(&$alias, &$context) {

  $temp = $alias;
  $newalias = pathauto_alias_uniquify($temp, $context['source'], $context['language']);
  if ($newalias !=$alias)
  {
    $alias .= $context['data']['node']->field_city[$context['data']['node']->language][0]['value'];
  }

}

The pathauto_alias_uniquify function checks if there is an alias already existing and if it does then would return the updated alias and if not return the same alias. now the one you get it different from the one we already have then we would could append the city name to the alias.

I have created a field called city with a field machine name field_city you will have to change your values accordingly.


How to set a flag at node when user view node? I have a content type 'page'. When a user views this node, I want a flag to be set automatically not by flage module link.

Any help?

Using the Rules module seems like a no brainer to me to get this to work, with no custom module(s) needed ...

Here is how your custom rule should look like (a kind of getting started with Rules):

Rules Event: When viewing content.
Rules Condition: Check the content type that matches your needs.
Rules Action: Flag the node being viewed by the current user.

Ps: I'm assuming this is about D7.


add block programmatically How can i add a block from mymodule. The content for the block is a form which contain a dropdown listing the themes. I tried with the following code. but it is not working.

function mymodule_block($op = 'list', $delta = 0){
$block = array();
    switch ($op) {
     case 'list':
       $blocks['mymodule_preview'] = array(
      'info' => t('mymodule Preview'),
      'region' => t('header'),
      'weight' => 0,
      'status' => 1
  );
  return $blocks;
case 'view':
  switch ($delta) {
    case 'mymodule_preview':
      $block = array(
          'content' => mymodule_theme_form(),
      );
      break;
  }

  return $block;
}
}

function mymodule_theme_form() {
global $custom_theme;
$themes = system_theme_data();
uasort($themes, 'tmymodule_sort_modules_by_info_name');
$themeOptions[] = 'Select';
$rolesOptions[] = 'Select';
foreach ($themes as $theme) {
    $themeOptions[$theme->name] = $theme->name;
}

// themes dropdown
$form1["themes"] = array(
    '#type' => 'select',
    '#title' => t('Preview the page with themes available'),
    '#options' => $themeOptions,
    '#default_value' => $custom_theme,
    '#attributes' => array('onchange' => "form.submit('themes')"),
);
//Submit button:
$form1['submit_'] = array(
    '#type' => 'submit',
    '#value' => t('Submit '),
        '#attributes' => array('style' => 'display: none;'),
);

return $form1;

}

This creates the block but content just prints "Array" only.
i am using drupal 6 .
 What is wrong in this code?  Pls help me

$block = array(
      'content' => drupal_get_form('mymodule_theme_form'),
  );


How do I display username in a custom block? Am new to Drupal so this is a very fundemental question.

How do I display the current username ? In a custom Block? I beleive is the $user->name session variable.

Do I create a Custom Block Type?  If so how do I reference the username?

Do I edit files on the file system?  If so which files?

Do I create new files? If so where?

In other web frameworks the templating engine allows server script tags... ex.. like

<%= username %>

Ive tried putting

$user->name  and {{app.user}}

into the custom block editor but nope, I've learned it's a WYSISYG with no way to render

All I want to do is display a user name in a block I can add a label too.

Any help appriciated.

You can do this in sevaral ways, one of this could be use a preprocess function. In your custom module in the .module file or your custom theme in the .theme file (recommended) write this:

/**
 * Implements hook_preprocess_HOOK().
 */
function [my_module_or_theme]_preprocess_block(&$variables) {
  $variables['username'] = \Drupal::currentUser()->getUsername();
}

and then in your template suggestions of block.twig.html print the variable {{ username }}


Views, Taxonomy, multiple parameters using contextual filters A view has been created to display related content types via their taxonomy terms, using contextual filters.
Currently the view is able to display content based on the first param  eg. about
The goal is to abe to display content based on the second param, being the child term and hide the parent eg. about/meet-the-team.

Here is a break down

Url :    page/parent term

parent term
    Content item referenced to parent term
    Content item referenced to parent term
    Content item referenced to parent term
    Content item referenced to parent term

Url: page/parent term/child term

child term
    Content item referenced to child term
    Content item referenced to child term
    Content item referenced to child term
        Content item referenced to child term
    Content item referenced to child term

Url: page/parent term/child term/child child term

Content item referenced to child child term
Content item referenced to child child term
Content item referenced to child child term
Content item referenced to child child term
Content item referenced to child child term
Content item referenced to child child term
Content item referenced to child child term

And this will continue on

Eg Url: page/parent term/child term/child child term/child child child term/child child child child term.

To do like this too much contextual filters needed, i think it's better to manage the URL in template.php and/or with hook_menu and use views_embed_view() to pass arguments to Views

$arg =array (1,2,3);
print views_embed_view('view_name', 'page_1', implode('+',$arg)); // OR
print views_embed_view('view_name', 'page_1', implode(',',$arg)); //AND


How do I create e-products, and store order id+uid in my own tables in case of successful purchase via PayPal On a website I'm developing, there's a plan that users could buy some "online" products (or e-products) cheaply via PayPal, and than give these products to each other as a present.
For example, one user could buy a star (or more) for 1€, and send this star to another user he/she likes as a gift.
So nothing would be shipped, nothing would be downloaded.
I already have Ubercart set up with a PayPal Sandbox API key (there will be other products too), so I can see that online transactions seem to work successfully for products that can be shipped.

How can I create products that can not be shipped, can not be downloaded, just simply purchased and registered, assigned to a given user (like an "online" product, which users can utilize on an online surface)?
I could create a "star" product in my Ubercart webshop, let users buy it, and than check this type's stuffs in Ubercart tables.
After a successful purchase, how could I check the order id (for the "star" product), and store the purchase process in my own tables to let users present these "online" products to each other (there would also be a field to whom it was sent) and register when this whole thing happened, and that one user already took this opportunity?
(To let you understand why it's needed: there would also be a little icon on the site indicating that users already have e.g. 12 stars that could be virtually given to another user; besides, there would be another icon indicating the user got a star from another user [which user gave it, and when]. I would also like to generate an own unique code for these stars to utilize them later for example for a draw!)

Any good ideas are appreciated. Ask if anything isn't quite clear!
Thank you in advance!

OK, solved it with Conditional Actions!

I created a new product class on /admin/store/products/classes site. Let's call it "My Stuff" (class id: my_stuff).
The previous step created a new content type with the "My Stuff" name. So I went to "Create content > My Stuff" (/node/add/my-stuff).
I left "Product and its derivatives are shippable." UNCHECKED (as I didn't to be shipped). Gave it an own SKU, sell price, description, uploaded an image, etc. as usual. OK, product created.
Went to "Conditional actions" (/admin/store/ca ; don't forget to enable this module), "Add a predicate" (/admin/store/ca/add).
Gave it a title, set "Customer completes checkout" trigger, gave a description, set my own class, set status to Enabled, pushed "Save predicate" button.
Under "Conditions" tab, selected "Check an order's products", pushed "Add condition" button.
Under "Product models:", I selected the SKU given in step 3.
Clicked on "Actions" tab. Selected "Execute custom PHP code", pushed "Add action" button.
Here I could "play" with the $order and $account variables in my custom code, and this was the key. This way I could loop through $order->products array (with for or foreach), reach the customer's user id via $order->uid (or $account->uid), read quantities (in the loop, with e.g. $order->products[$product_index]->qty, where $product_index is the actual index of the loop steps) and save them in my own database tables with db_query() function. Everything needed could now be saved in my own tables where they could be handled the appropriate way, so everything works fine now. I'm happy.


SagePay iFrame Theme Integration I am using the SagePay Integration Module.  I have created template file for the cart summary / overview (page--cart.tpl).  I have also crated hooks to alter forms on the next two pages mytheme_form_commerce_checkout_form_checkout_alter and mytheme_form_commerce_checkout_form_review_alter and configured template files for them using the mytheme_theme hook.  The templates are commerce-checkout-form-review.tpl.php and commerce-checkout-form-checkout.tpl.php.

Next I created a template file for the payment page, page--checkout--payment.tpl.php.

SagePay is configured to (only) use Sage Pay Server Integration - specifically Display payment form in an iFrame (can be found at /admin/commerce/config/sagepay).

After investigating the $page variable using Deval/kpr I decided to render

$page ['content']['content']['content']['system_main']

Here is a copy of the code in the template file (page--checkout--payment.tpl.php).

<?php if (isset($page['header'])) {?>
  <?php print render($page['header']); ?>
<?php }?>

<?php kpr ($page); ?>

PROCESS PAYMENT

          YOUR BASKET
          BILLING DETAILS
          PAYMENT OPTION
          PROCESS PAYMENT
          CONFIRMATION

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

<?php if (isset($page['footer'])) {?>
  <?php print render($page['footer']); ?>
<?php } ?>

The problem is this.  The line

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

renders the iFrame, but once that is done, the rest of the page does not get rendered.  So the last part which needs to render the page[footer] is not executed.

I tried to save a copy of page[footer] at the beginning of the file, and then render this copy, but same result - footer does not get rendered.

I am assuming either the $page variable is lost / corrupted during the iframe render (unlikely), or the code stops executing after the iframe is rendered and we never get to the footer part (probably - but not sure why).

If I remove the line to render the iFrame, then footer prints out just fine.

My question is this - how I can render the SagePay iFrame form (in an iFrame) ensuring all relevant form fields (hidden, links, etc) is rendered correctly, and still render this inside one of my template files.

So I had a couple of people asking about this here and on drupal.org - so I figured it would be easier to just tell you what I did.

in commerce_sagepay/inc/commerce_sagepay_server.inc around line 120 there is a piece of code that reads:

  '#markup' => '<iframe style="width: 600px; height:500px" scrolling="no" frameborder="0" name="iframe_sagepay" id="iframe_sagepay" src="' . url('commerce_sagepay/sagepay_waiting_page') . '" />',

I changed this line to

  '#markup' => '<iframe style="width: 600px; height:500px" scrolling="no" frameborder="0" name="iframe_sagepay" id="iframe_sagepay" src="' . url('commerce_sagepay/sagepay_waiting_page') . '"></iframe>',

in other words - explicit close the iframe tag.  It solved the problem for me.

Hope this helps someone.


Vertical Tabs in Panel Pages I am trying to have three forms available to the public on my site and would love to have them configured in in the vertical tabs layout. Initially I was going to have them available through node/add/form but I have since decided I would rather have them in a panel page to lose that path of node/add. Now that I have the forms in the panel page they no longer have the vertical tab/fieldset layout. How would I go about putting the forms back in that tabbed layout while staying in a panel page?

It looks like someone has fixed this in style!
https://drupal.org/project/node_vertical_tab_elements

Haven't tried it myself, but it looks made exactly to fix this issue.


How to include jQuery UI on a page without PHP? I want to include jQuery widgets on my Drupal 7 page. So, I started the way is described here:

drupal_add_library('system', 'ui.dialog');
drupal_add_js('jQuery(document).ready(function(){jQuery("#dialog").dialog({ modal: true });});', 'inline');

However, there are two problems with this approach. First, I would prefer to keep the pages themselves HTML (with JavaScript, of course - but without PHP). And these two lines are the only PHP lines on a large HTML/Javascript page.

Second, JavaScript itself is in quotes which prevents some visual assistance from the editor (since everything is in the string) and forces me to use only double quotes or escaped single quotes inside.

So, I was wondering if there is a way to specify drupal_add_library outside the page, and get Drupal to read <script> tags and JavaScript inside those tags.

In general, I didn't find relevant documentation on Drupal side (relevant being not for theme or module developers but for those who want to use JavaScript / JQuery / JQuery UI as part of site building). If I missed it, I apologize!

How about creating a 'scripts.js' file in your theme folder and then simply either add it in using the drupal_add_js method in template.php (the same method you are using above) or if it's something that's more global, include it in your theme's .info file. You will need to tweak the JQuery call according to 7 standards. I use both of these methods all the time and it works great.

So in your 'scripts.js' file you will have something like this:

(function ($) {
Drupal.behaviors.myTheme = {
attach: function(context, settings) {

// your custom JQuery here

}
};
})(jQuery);

... and then call that however you wish as I have described above. You can also have a look at this post: Managing JavaScript in Drupal 7


Setting a field collection default value for a field using form I'm trying to set up a default value programmatically to my field which is in field collection. This has proved quite hard and I cant seem to get around it. Any assistance will be appreciated. This is the code i have tried to far without any success.This field is a select list with different select items. Now i want it to pre-select one of the items.

$field_collect = $form["field_fielc_collection_group"][LANGUAGE_NONE];

                            foreach ($field_collect as $fielders){
                                        if(is_array($fielders)){
                                        $somethin = $fielders["field_to_set_default"][LANGUAGE_NONE]["#default_value"];
                                        $default_val =array(t('something'));
                            array_push($somethin,$default_val);

This is how I resolved this.

$language = $form['field_fielc_collection_group']["#language"];
                    $iterates = $form['field_fielc_collection_group'][$language];

                foreach($iterates as $multi__key => $iterate){
                            if (is_integer($multi__key)){
                                        if(is_array($iterate)){
                                            $delt = $form['field_fielc_collection_group'][$language][$multi__key]["#delta"];
$form["field_fielc_collection_group"][$language][$multi__key]["field_to_set_default"][$language]["#default_value"][$delt] = 'default_value' ;
                                        }
                            }
                }


How can I print the translated entity title in a template? I have a reference field for nodes and I have a field template to render the the fields.
{{ item.entity.title.value }}

But I can't get the translated title of the node.
Can someone help?

If you configure the reference field to display the entity title it should be translated automatically, as @leymannx commented. But if you get the title from the entity directly you have to make sure the entity is in the correct language. If you don't want to use PHP you can do this with the help of Twig Tweak:
{{ item.entity|translation.title.value }}

See https://git.drupalcode.org/project/twig_tweak/-/blob/3.x/docs/cheat-sheet.md#entity-translation


A search feature for fields? I've looked at the core search module, and from what I've been able to tell so far, it searches on the body of a node.

What's the best way to get a search feature for a site that will search on specified fields of a content type?

You can use Views module http://drupal.org/project/views.

With Views module, you will have a flexible method to pull content according fields of your content that you want to show, and with Exposed Filters feature of Views module (or with modules like Better Exposed Filters), you can search/refine by field of your content.

here is a documentation about Views: http://drupal.org/documentation/modules/views

here is an example: I want to filter and search by Title of my content. Then I can add to my View a filter to search by Title, then in Filter Criteria I can select Title and expose that filter to use, for example, a text field for search Titles:

this screen shot is about where is located the Filter Criteria area, and where is the option to add filters:

this screenshot is about where you can select if you want expose a text box to search/filter, in this example, by Title. The operator is very important to filter. In this case I will select Contains that seek a word that is part of title:

Also remember that you can add another filter, the filter by content type, to filter results by list of content type desired. This filter can be not exposed, or if you want, can be exposed to allow to users filter and search, according content types:

And finaly this screenshot have the View with a text field for filter and search by titles of my content:

I hope information be useful.


Regions do not display in "Demonstrate block regions" I wonder why some regions of my theme don't display in section 'Demonstrate block rerions'.
This happens with some themes which I downloaded from Drupal.org, for example with the Software theme.
Here is part of its 'info' file (showing multiple regions):

And this is what 'Demonstrate block rerions' for this theme looks like:

My question: What could be causing this?
I use SEVEN as admin theme. On page admin/structure/block I see the link  "Demonstrate block regions (Software Responsive Theme)" and all regions that defined in .info file. But when I click this link, I see ONLY SOME OF IT BUT NOT ALL .
I try to change admin theme, but it is not help.
Maybe problem in this particular theme?

Try switching the administration theme you're using, to a theme shipped with Drupal core.
Or refer to the article "Demonstrate block regions" missing in Drupal 7 for some more hints about this. Here are some quotes from it:

On a fresh install, you should see "Demonstrate block regions" when you go to admin/structure/block.  If somebody has played around with the block settings on your Admin theme, this selection might disappear.
Make sure that “System help” is assigned to a region (probably ‘Help’) in your Admin theme (probably 'Seven’).  Go to 'configure’ for the 'System help’ block and make sure that the visibility settings are not restricted in some way.

Another possibilities you may want to try (haven't had a chance myself to try that, sorry):

inspired by Issue # 996214, which is about another theme though:

Verify if the "System Help" block is placed in the help region.

inspired by Issue # 1392206, which is about another theme though:

You might need to turn on the Help module in core modules.


Deny/allow access to group-content only for some roles I have a private group with a "notebook"...most pages of that notebook may be accessed by all members of that group, but some pages shouldn't. I tried to control access with the module "Content access" but that only works with node types that are not part of any group because organic groups seems to grant access to all nodes if the user belongs to that group.
Is there a way to deny access (based on roles) to nodes that belong to a group if the user is in the group?

Install the Module Grants module. It will solve the conflict. Actually, it will take the conflict into account, which Drupal does not.

  Module Grants makes modules that deal with content access permissions operate better on unpublished (as well as published) content. It also makes sure that access grants behave in an orderly fashion when such modules are used together.


Commerce Kickstart change full text search product display to https I am currently developing a drupal commerce site with commerce kickstart. I've set the site up so that it's mixed mode SSL using securepages, all seems to be working fine. However, I've found a bug with the full text search (used in the main products display view) which could potentially put customers off as they may think the site is unsecure. Plus the certificate does not show the EV SSL Green bar / padlock, it display's with a yellow warning.

All browsers apart from chrome work ok and from doing my research it looks like it's only the full text search which is causing the issue (when testing using chrome by pressing ctrl + shift + j it shows the error code) on line 223:

Mixed Content: The page at 'https://www.whiterabbitengland.us/contact-us' was loaded over a secure connection, but contains a form which targets an insecure endpoint 'http://www.whiterabbitengland.us/products'. This endpoint should be made available over a secure connection.

Has anyone else encountered this issue and found a way to set the full text search over https?

Thanks
Max

Maintainer of Commerce Kickstart.

I just checked out the site, and it's using a relative path like Drupal forms are expected to do. From your source:

<form action="/products" method="get" id="views-exposed-form-display-products-page" accept-charset="UTF-8">

The search form is a Views exposed filter exposed as a block. There isn't much trickery going on with the form beyond typical site building.

Also, I did not get mixed content warnings.