Is it possible to have a block of content on a taxonomy term page? If I have taxonomy of company and term companyx when I visit www.sitename.com/company/companyx I get a list of posts with that term // vocab. Is it possible to put a block of content above the posts? Or is there another better way of creating 'landing pages' for the taxonomy terms? On Drupal 7.

One way to change the output of these pages is to use a module like Taxonomy Views Integrator. This will allow you to create any number of views for different vocabs or even specific taxonomy terms and drive the presentation of the taxonomy output. I use this regularly to override the default term page and present different layouts of content (typically powered by view modes).

Another way to approach it (creating landing pages) would be to create a content page representing that taxonomy page, then drop a TVI view block on this page under the main content. You could also use Panels to do that, but I don't use Panels, so I can't speak to that.


How can I overwrite taxonomy field link output? I am using Drupal 7 and the Views module. I made a very simple page showing nodes with the Views module, where I want to show only one field, which contains taxonomy terms.

I want to rewrite standard link from this page to my own variant. I selected "Rewrite results" and wrote my link. In the view, those links are not changed: they are going to taxonomy term pages.

I know that if I used a view showing taxonomy terms (not nodes), I could checkout the field for standard taxonomy output, but in a node view there is no such possibility.

You can do that like follows.
Go to your view and click on filed (having taxonomy) to change the settings.

Change the Formatter option to plain text. (If you choose Formatter as 'Link' that won't work even you write Rewrite Results')
Check output this filed as link and enter your path. Or you can also use'Rewrite the output  of this filed'

That's it.


URL rewrites & Drupal functions I have a server that hosts our Drupal 7 development, testing, and production environments:

/var/www/html/dev
/var/www/html/test
/var/www/html/prod

Instead of having dev and test live in subdirectories like http://ourdomain.edu/dev, we want the URLs to be http://dev.ourdomain.edu.

From a Drupal standpoint, is this best accomplished through an .htaccess file in each directory?  Or in settings.php?

At the moment, functions like path_to_theme() aren't working at http://ourdomain.edu/dev since path_to_theme begins with a forward slash.  Consequently, the theme refers to http://ourdomain.edu/sites/all/themes/ourtheme/images/logo.png instead of http://ourdomain.edu/dev/sites/all/themes/ourtheme/images/logo.png

It would be great to know what's considered best practice.

Thanks!

If you are running Drupal in subdirectory named "dev". Then you need to put $base_url = 'http://www.example.com' in your settings.php. You may need to put RewriteBase /dev in your .htaccess but generally that isn't necessary for me.

If you want to run Drupal at http://dev.example.com that is purely an issue of configuring Apache correctly. Your likely need to change your httpd.conf or similar file to setup virtual hosting. Drupal won't need any changes.


Do Simpletests require t()? All Simpletest documentation and examples use the t() function for clickLink() or assertText() for example. However when I read the core issue about testing not working when locale of host session is not English and the patch that got committed (tl;dr it forces English to be the default language) I'm curious if it's really necessary.

MegaChriz has an interesting take on this, as he doesn't t() his string in Feeds tests. Extract from his comment as to why:

  In most cases, the "final" text is checked, thus the text for which the translation placeholders have already been replaced. So there is no original translation string to check for. If I remember well, there were also occasions where only a portion of the text was checked. Since tests are always run in English (at least, by my knowledge), this should have no harm.

If the default language is English, can't we simply remove the t() function from testing? Please note that I'm not looking for opinions but for facts.

I know for a fact (though it is probably not the only reason) that t() allows for replacement arguments:

echo t('my %string', ('%string' => 'Foo'));

Which renders as: 'my Foo' (emphasized text).

If you were to use such placeholders on your site, they will not work unless you wrap them through t() or format_string() (where t() is much much shorter).

Here comes the opinion part; if you only were to use plain text strings it probably wouldn't matter. But if you use t() on the front end with formatting and you would compare that value in the backend with a plain text string, it wouldn't match. And writing all tests to use format_string() instead would be very confusing.

In the end it all depends on your situation and your tests.


How to use PHP Mail function or sendmail to send and/or receive emails from my live site I am hosting my site on OVH and they have told me that sending emails using external SMTP servers is not allowed. I need to use the PHP Mail function or sendmail. I have a Drupal 7 installation and I am completely lost.

Which of these is the best option?
What steps do I need to follow in order to use one of these options?

My site is currently live and I am not able to receive emails through my contact form.

Thanks in advance.

Based on the comments above:

Since your server does not permit direct SMTP communication, and since SMTP Authentication Support specifically overrides the default behaviour "This module allows Drupal to bypass the PHP mail() function and send email directly to an SMTP server."

I would suggest disabling the two modules, SMTP Authentication support and PHPMailer, and use the default drupal mailer which by default uses php mail() as permitted by the server.


How do I correctly load user_profile_form() to use in my theme? I am trying to theme the user profile edit page using user_profile_form() and need help how to achieve this. In my template.php I have the following code:

function marinelli_theme($existing, $type, $theme, $path) {
  $hooks['user_profile_form'] = array(
    // Forms always take the form argument.
    'arguments' => array('form' => NULL),
    'render element' => 'form',
    'path' => drupal_get_path('theme','marinelli'),
    'template' => 'templates/user-profile-edit',
  );
}

function marinelli_preprocess_user_profile_form(&$variables) {
  global $user;
  $form_id = 'user_profile_form';
  $form_state = array();
  $form_state['build_info']['args'] = array($user);

  // Load user.pages.inc and ensure it is automatically reloaded if
  // this form is rebuilt via AJAX or other means.
  form_load_include($form_state, 'inc', 'user', 'user.pages');

  $variables['rendered'] = drupal_build_form($form_id, $form_state);
}

Here is the code you need to follow:-

function THENAME_theme(&$existing, $type, $theme, $path) {

return array(
    'edit_profile_user_profile_form' => array(
        'arguments' => array('form' => NULL),
        'template' => 'templates/edit/user-profile',
        'render element' => 'form',
        ),
);
}

Next thing You need to create a file called user-profile.tpl.php and save it in template folder.

In the user-profile.tpl.php file, write the following code to print out the fields:

<?php print drupal_render($form['field_NAME_OF_FIELD']); ?>


Change UID for watchdog message In Drupal 8 with DbLog logger, I am trying to log some audit messages to a different user than the currently logged-in user. Unfortunately, it looks like something is overwriting my context.

I tried \Drupal::logger("proreos")->info("bla", ['uid' => 5]); and \Drupal::logger("proreos")->info("bla", ['user' => User::load(5)]);, but neither of them worked. In both the cases, the current user ID was instead used.

How can I use a different user ID?

To clarify: This is not about logging another uid, it is about assigning the row in watchdog to a different user.

Logger will always log for the current user, except you provide your own logging service.

The context is used to replace placeholders in the message, see here, so to get the userid in the message, use this:

\Drupal::logger("proreos")->info("bla @uid", array('@uid' => 5));


Restricting Field List Entries Based on User Role in Drupal 7 I'm using the Field permissions module in Drupal 7 to restrict access to a list field I created based on the user's role and that works great.  But is there a way to restrict the content of that list based on the user role?

For example:

for user role 1, I want the custom field list to show:

Apple
Banana
Grape
Orange

for user role 2, I want the custom field list to show:

Apple
Grape

There is a contributed module available in drupal.org 'Field Permissions' .

http://drupal.org/project/field_permissions  We can set the field  permission based on user role.

Hope this will help you.


How to get all records of a view with paging? I have a view with 20 records, displaying 10 records on each page. I have a field check-box with custom handler to check and uncheck each record. I am using the $this->view->results to loop through all the records of view to check or uncheck on different events. This logic is working fine.
Now, I have added a new button to select all the records of view i.e. 20 records of both pages. Is there a way I get all the records of view with paging. In my case I want to get/select all the 20 records which are displayed on two pages. If I print $this->view->results, it has only 10 records which are displayed on page 1. Is there any view array element which have all 20 records?

If you don't mind installing another module, try Views Bulk Operations.  Views Bulk Operations (often abbreviated VBO) allows you to add "select all on page/select all everywhere" checkboxes and also offers additional functions such as using batch API to process operations when there are too many to do at once (if you had 20,000 records instead of 20).

Node One has a tutorial on VBO.


Drupal 8 theme showing Uncaught TypeError: $(…).find(…).once is not a function in console New to Drupal 8.

I've created a demo theme. The .libraries.yml file is below:

global-styling-and-scripts:
 version: VERSION
 css:
  base:
   assets/css/font-awesome.css: {}
   assets/css/bootstrap.css: {}
   assets/css/slick.css: {}
   assets/css/bootstrap-datepicker.css: {}
   assets/css/jquery.fancybox.css: {}
   assets/css/theme-color/default-theme.css: {}
   assets/css/style.css: {}
  theme:
   '//fonts.googleapis.com/css?family=Tangerine': { type: external, minified: true }
   '//fonts.googleapis.com/css?family=Open+Sans': { type: external, minified: true }
   '//fonts.googleapis.com/css?family=Prata': { type: external, minified: true }
 js:
  assets/js/jquery.min.js: {}
  assets/js/bootstrap.js: {}
  assets/js/slick.js: {}
  assets/js/waypoints.js: {}
  assets/js/jquery.counterup.js: {}
  assets/js/bootstrap-datepicker.js: {}
  assets/js/jquery.mixitup.js: {}
  assets/js/jquery.fancybox.pack.js: {}
  assets/js/custom.js: {}
  dependencies:
   - core/drupalSettings
   - core/jquery
   - core/jquery.once

If I deleted all the .js from this file, I see no errors in the console however, the images, and slideshows etc are not properly rendering.

You're loading 2 versions of jquery:
assets/js/jquery.min.js: {}
- core/jquery

That's most likely your issue. Try removing the assets/js/jquery.min.js entry and flushing your cache. That will mean you're just using Drupal's core jquery which hopefully your plugin should work fine with


Additional validation after successful login I want to implement some additional validation steps right after a user has logged in to a Drupal site.

So far, I have implemented the additional validation inside hook_user_login. If the validation fails, I am forcing the logout by calling user_logout.

EDIT: Part of the users are authenticated through an external SSO, so altering the login form to add an additional validation does not seem to be a good solution.

Is this the most standard way to do it, or is there a better way?

If You want to abort login I think You should try to add own validate function to user_login whith hook_form_alter (https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_form_alter/7)

<?php
/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_login') { // or $form_id = 'user_login_form'
    $form['#validate'][] = 'check_username_against_ad_hoc_service';
  }
}

function check_username_against_ad_hoc_service($form, &$form_state) {
  $name = $form_state['values']['name'];

  if($name == 'NoGo') {
    form_set_error('name', 'You're an Ad-hoc!');
  }
}
?>

You can also use function hook_form_FORM_ID_alter (https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_form_FORM_ID_alter/7)


How to refresh entity from entity_load(), reloading the entity as it is now? If an entity has already been loaded, entity_load() retrieves it from memory rather than reloading it. Makes sense.

But: what can you do when you need to reload an entity that has already been loaded - when the entity's data has (or, may have) been changed in the database since it was loaded by another function, and you need the changed version?

The closest I can find to a way to reload an entity is to call entity_load() with the 4th parameter of entity_load() to true - for example, entity_load( $entity_type, $entity_id, null, true ); - however, this does much more than just reload the entity.

It also appears to reset the cache on the server, which can have a lot of undesired side effects (for example, I'm finding that calling this as a step in the process of saving an entity causes a cache to be created for the entity's fields that is missing field data, and this faulty created cache persists even as the entity is saved, causing it to seem like the entity's fields failed to save and a blank entity was saved, at least until caches are cleared). From googling around, I get the impression that setting this parameter is generally considered to be A Bad Idea (posts I've seen aren't specific about why, but my experience offers a clue).

So, how can I re-load an entity that has already been loaded but which I suspect has been changed since being loaded, with minimal other consequences?

Drupal 7, and while core-based answers are best any answers that use the Entity API contrib module or other robust contrib modules are fine.

There is entity_load_unchanged(), which does a reset cache itself as well, but however only for that specificy entity id.

This is already available by default in presave and insert/update hooks as $entity->original.


A "No results" View problem I would just like to hear a confirmation from someone:
If I have a View A that displays View B in case of No results, does the View B display with all its attachments? Somehow I cannot get this cascade to work. The attachment does not show and I'm not sure it's because of limitation or is it me (again)...

OK, it was me, I have not provided the specific view display, and the "default" did not work. No wonder. Sometimes asking a question in the air makes the answers come along magically.


View Group By field with mult-value field I have a field that contains multiple boolean values ( similar to a tag or taxonomy term) which indicates status.  So the field is like this.

application="received, data complete, references, financials,"
I'd like to create a tabular report grouped like this:

Received:
Item A
Item C

Data Complete:
Item A
Item B

References:
Item A
Item B

The problem is that grouping on the field is like this:
Received, Data Complete, References:
Item A

Data Complete, References:
Item B

Received:
Item B

So I need to break up the field in views.  I realize I can create a view in a view or view field, but wondering if there is anything more simple/elegant.

You can also uncheck the box "display all values in the same row" under the multiple field settings menu in the configure field settings. Doing this "denormalizes" the data. This works for both content and taxonomy terms - in my case accessed via entity reference. This way you can make the best choice between content and taxonomy in your design.


Drush Permissions Issue With the help of the support team of my dedicated server, I have setup Drush globally on my server. Now I can run multiple Drush versions like drush6 status, drush7 status, drush8 status with a little tweak in my .bashrc file

One problem I am unable to resolve is that when I download or update drupal it starts giving 500 Internal server error.

My Support Team Told me

When you use Drush to download Drupal, it gives files 664 permission. The PHP handler in the server is suPHP, which requires 644 file permission, so you need to run the file permission fixing script for the account after using Drush install/update commands.

Is there any way we can instruct Drush to download the files with 644 permission?

Drush does not handle platform-specific issues such as file permissions. To get rid of group write, just run chmod -R g-w /path/to/drupal. If you wanted to do this automatically, you could make a post-update hook for the pm-updatecode command.  See the example Drush pm_update hook file for one example post hook function.

In your case, you would want something like this:

function drush_myhook_post_pm_updatecode() {
  passthru('chmod -R g-w .');
}

Save that in a file named myhook.drush.inc, and put it somewhere that Drush will find it, such as DRUPAL_ROOT/drush.  Then run drush cc drush, and your hook should run the next time you call drush pm-update.


Drupal 8 Custom Migration We are trying to do migration of joomla database to drupal 8. We are using migrate and migrate plus modules to accomplish this task. We took migrate example module(beer migration) which came with migrate plus module as reference and trying to customize it according to our requirements. But when we try using our custom migration names instead of beer_term the migrations are not registering. Is there a way that we can register them.

There are several things to check for when troubleshooting migrate/migrate plus.

Based on "not registering" make sure you set id: my_migration instead of id: beer_term or it won't show up when you run drush ms. That's the easy one, hopefully it's that. If not...

Failures resulting from errors in your migration configs will be silent most of the time. When they're not silent, they tend to send you on a wild goose chase for something pretty unrelated to what failed. This can make it frustrating to pinpoint what went wrong. Quadruple check your .yml syntax.

Secondly, make sure your config (.yml) files are named correctly. They should be named and placed exactly like /drupal/modules/custom/my_module/config/install/migrate_plus.migration.my_migration.yml The config files should NOT be named my_module.migration.my_migration.yml. As @mike ryan points out, resist the temptation to do so.

If you've done all of the above after uninstalling and reinstalling your module, your migration should show up when you do a migrate status check.


error history view_galleriffic I'm using Views Galleriffic (6.x-1.x-dev) and Node Gallery module and there is an error.

In the Firebug console, my error is shown as:

$("a[rel='history']").live is not a function in line 93 $("a[rel='history']").live('click', function(e) in file view_galleriffic.js

I uploaded jquery.history.js in module view_galleriffic/js/...
my website link :http://demo.dolphin-sch.ir/nagara/fa/galleriffic/95
help me

The live() method wasn't added to jQuery until v1.3. Your site is currently using the standard jQuery library included in Drupal 6, v1.2.6.

To fix this all you need to do is download and install the jQuery Update module. That will upgrade your site's jQuery library to v1.3.2 and you should stop getting the errors.


How to add global variable in custom js file I've added my custom script wrapped in :

(function ($) {

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

But can't create a global variable inside it

You can do something like

(function ($, Drupal, undefined) {
    var my_global;

    Drupal.behaviors.exampleModule = {
        attach: function (context, settings) {
            my_global = 1234;
        }
    }
})(jQuery, Drupal)

and the Javascript scope-chain rules will make my_global visible to your whole closure.  If you need a true global, move the declaration of my_global:

var my_global;

(function ($, Drupal, undefined) {
    Drupal.behaviors.exampleModule = {
        attach: function (context, settings) {
            my_global = 1234;
        }
    }
})(jQuery, Drupal)

Personally, my JS files for Drupal start out as

var MYMODULE = (function(me, $, Drupal, undefined) {
    me.name = "MYMODULE";

    function attach (context, settings) {
        console.log(me.name + ".attach()");
    }

    Drupal.behaviors[me.name] = {
        attach: attach
    };

    return me;
}(MYMODULE || {}, jQuery, Drupal));

and I then add locals for module-wide variables, or directly to the module if other modules need them.  The article JavaScript Module Pattern: In-Depth explains this very well.


Migrating content with referenced taxonomy field is to be migrated by term name Is it possible to migrate content with term reference fields, but instead of referencing terms by their tid they are referenced by their term name?

instead of this:

field_tags:
  plugin: sub_process
  source: field_tags
  process:
    target_id: tid

Do something like this:

field_tags:
  plugin: sub_process
  source: field_tags
  process:
    target_id: [term name]

i guess entity_lookup what you looking for:
here is an example from migrate_plus/src/Plugin/migrate/process/EntityLookup.php

field_tags:
       plugin: entity_lookup
       source: tags
       value_key: name
       bundle_key: vid
       bundle: tags
       entity_type: taxonomy_term
       ignore_case: true


How to render a link as a button I am using Drupal 7 and I would like to render a link (anchor tag) the same as a submit button. Does Drupal 7 allow for this (say by using the button type) or do I have to use CSS to accomplish this?

You need to, and should, use CSS to style this.

.buttonize {
  -webkit-appearance: button;
  -moz-appearance: button;
  appearance: button;
  padding: .5em;
  /* whatever other styles you want */
}

I added a jsfiddle.

You can look this up, but I'll note that appearance is different on OS's


theming user profile with "User Field Privacy" - but no "Privacy" available My setup is like this: multiple additional user fields (not using profile2) and the module "User Field Privacy" is enabled.

I am currently theming user profile pages through a preprocess function and the corresponding  user-profile.tpl.php… Now I have some fields that should be visible to some roles, but hidden to others. I trigger this through the module  "User Field Privacy". Looking for variables in the devel dump does not bring anything for "User Field Privacy" .

 [field_telefon] => Array
         (
           [und] => Array
              (
                [0] => Array
                   (
                     [value] => +01 234 567 890
                     [format] =>
                     [safe_value] => +01 234 567 890
                    )

               )

          )

When not theming through preprocess and .tpl, everything is fine – the fields marked hidden are actually hidden from regular and anonymous users, but shown to users with the appropriate permission.

How/where can I find the "marker" or "flag" for the User Field Privacy setting ?

Any pointers, hints and tips welcome!

update/solved: I did solve my problem now with very basic measurements: for each field I wanted to have a 'privat option' for, I added an extra checkbox field ("public/private"). This setup just works fine no need to have "User Field Privacy" installed – at least for me. Hope this might help somebody some day.


How to hide a custom user field in user profile? In Drupal 7, what is the best way to prevent any non-administrative user from changing a custom user profile field?

Use case: I've created a user field called "Customer ID" that I do not want the user (any of my actual customers) to change. The field exists for my own reference and for programmatic usage in other modules. I don't mind the user seeing Customer ID, but they should not be able to edit it.

Should I override the page template for the user profile page? If so, how is the template changed to make a field read-only or invisible?

Thank you very much for your help!

Chris

I think Field Permissions is what you are looking for. Here is a quote about it (from the module's project page):

... allows site administrators to set field-level permissions to edit, view and create fields on any entity.
Features:

Enable field permissions on any entity, not just nodes.
Role-based field permissions allowing different viewing patterned based on what access the user has.
Author-level permissions allow viewing and editing of fields based on who the entity owner is.
Permissions for each field are not enabled by default. Instead, administrators can enable these permissions explicitly for the fields where this feature is needed.
Field permissions overview


Strange Issue with displaying information of the current term I have built a series of views to build a Drupal Commerce display for products based on the Taxonomy terms of those products. These terms have a hierarchy. There are nearly 40,000 products being imported through Commerce Feeds, the taxonomy terms are attached to the products during the import.

Currently I have a series of 3 views working together to achieve what I want and am attempting to build a fourth view that I am having a strange problem with. View http://cde.gttechlife.com/products for reference.

View 1(Product Taxonomy Children) pulls in all Taxonomy terms based on the Parent Term context in the URL. (Term Alias is the name displayed, Product Code for Image pulls in an image based on product code) It pulls that in through Term Name converted to ID and turns term name spaces into dashes. See Below:

View 2((Top Level Products) Pulls in all Taxonomy Terms that do not have Parents and displays them. View 2 is attached to view 1 if View 1 has no results based on the Contextual URL, this is the only time view 2 is displayed. So no contextual filter on the URL it displays all terms with no parents.

If View 2 DOES have a contextual URl, there it displays a no results attachment View 3. View 3 pulls in all products with that Term Name in the URL.

All of these views work exactly as needed. But I want to add another view. I want View 4 to also be pulled into view 2 with view 3. View 4 (Taxonomy Description). View 4 pulls in the Taxonomy Term Description and the custom field Category Alias, and Product image of the current term in the URL. Oddly enough this ONLY works for contexts with no dashes. Just like the other Views I made sure to check "Transform dashes in URL to spaces in term name filter values" but for some odd reason it still only works for one word terms. For example (cde.gttechlife.com/products/vibratite) works fine but (cde.gttechlife.com/products/Gasket-Flange-Sealant) does not. It seems like such a simple problem to have but I have hit a wall looking for the solution. Any help would be appreciated.

Also trying to figure out the best way to get the Breadcrumbs to reflect the parent terms and even ideally in the url, but I still have some effort to put in on that end. Have been using the Crumbs module thinking I will be able to do what I need if I put in the time. But the problem stated above has me stumped because I can't think of why it wouldn't work correctly.

If the contextual id is working on the 3rd view, then you should set the validation criteria to convert the term to an id:

That might fix the "inherit filters" of your views footer.

EDIT: An answer to your second question about reflecting your architecture in the url structure and breadcrumbs.

I have made two videos where I've concocted two different ways to make a Drupal Commerce Catalog using hierarchical taxonomy (either with one vocabulary or multiple vocabularies). Both of these ways of using Views and Taxonomy creates urls that reflect where you are. I'd bet with a little creativity you could make views create a breadcrumb as well.

Hierarchical Views Catalog using Taxonomy
Multi-vocabulary Hierarchy Views Catalog

Hope that helps!


Hide already purchased products (or allow purchasing the product only once) I have a view with a list of product displays, and I would like to hide all the products that are already purchased by the current user. This would allow purchasing products only once per user.

I've tried to modify the view and add a relationship with the order, but I can't find the relationship "Order".
As explained in the similar issue http://drupal.org/node/1221372 , I also tried to create a view of "Commerce Order". I think this would work for displaying a list of purchased products, but not for displaying a list of non-purchased products, because a view of 'Commerce Order' displays results with orders, not results without orders.

Can anyone help me? :)

I would use Content Access to restrict access to nodes by role, then I would make a special role that is required for viewing this product. Then I would create a Rule where buying that product triggers that  role being removed from the user.


How do I activate Google Custom Search? I've just installed the Google Custom Search Module.

I've activated the module and inserted the API. The search is is till not working.

Something I'm missing?

Note: I've realized I need the paid version. is there a free Google Custom Search, free option?

As you can read in README.txt file:

*** About Google Site Search module
---------------------------------------
This requires "Site Search Edition" (paid version of Google's Custom Search).

You need to have a paid Google Site Search engine, so you can receive results in custom format (e.g. XML).

If you've free version, check the alternatives modules such as: Google Search Appliance or Google Custom Search Engine. Or use alternative services such as Yahoo YQL (e.g. YQL Views).


Accessing custom block fields from a template file I have a sidebar region "Sidebar Ad" and placed in that region is the custom block "Sidebar Ad" of type "Image" which has two fields "Image" and "Link".

When I output the block on my page using {{ page.sidebar_ad }}, I get the image and the link separate from each other, which is to be expected. What I can't figure out, and I've been trying for around 5 hours now, is how to reference the fields separately so I can wrap the link around the image.

Does anyone know how to reference those fields? Am I going about this the wrong way?

I've successfully pulled the link URL by overriding the specific block template and referencing:

{% block content %}

{% endblock %}

Referencing the image URL still eludes me.

This was the final solution.

{% block content %}

{% endblock %}


Use a different template file if use is on a mobile device I currently am using page-front.tpl.php to display my Blog content type in a View. I want to use a different template if the user is on a mobile device, and have them either redirected to the mobile view, or have the Drupal theme layer use a different template.

To do this you need to setup some method that will detect whether the use is coming from a mobile device and than add a function in your template.php file to switch to your mobile template.

For the mobile detection, there are a number of modules available for this but for this specific use case, I would recommend Mobile Switch because it provides a specific variable you can use for testing in your theme (others like Mobile Tools might as well, this is just one I've used before). From documentation:

Development with Mobile Switch.

The module provides four system variables:

1. mobile_switch_ismobiledevice
2. mobile_switch_istablet
3. mobile_switch_ismobiletheme
4. theme_mobile

From here, you just need to add a template suggestion to your theme through the preprocess_page function using this variable, ex:

function YOURTHEME_preprocess_page(&$variables) {

  global $mobile_switch_ismobiledevice;

  if ((request_path() == 'YOUR_PATH') && $mobile_switch_ismobiledevice) {
    $variables['template_file'] = 'mobile-YOURTEMPLATE';
  }

}

This method assumes you want to specifically switch between two template files, if you would prefer to use a separate mobile theme, than the Mobile Switch or Mobile Tools module have configuration options to help you do this.


Help with hovering field data Drupal demi-gods,

I have a scenario as follows in a "Reference data" content type

Code                 Description
NY                    New York
CA                      California
CO                       Colorado and so on

I want to have say an Address content type that references these state codes, simple enough, define a node reference for the content type, but in addition, i want to be able to hover over the drop down box of states, in the address content, and for Drupal to list the state in a hover text.

Can anyone tell me if there is any functionality that provides this, or does it require coding? If it does require coding, which file should I be modifying?

Thanks heaps, I've been struggling with this for a few days now.

Geoff

A view with an exposed filter is what you are looking for.

Create a view with the fields that you want to show, and select the state code field as an exposed filter. Then the view will display only the content related to the state code selected by the user. The view may contain only one field, or many. If the relevant fields are in different entity/content types, you will need to define a Relationship in the view to connect them using an entity or node reference field.

Using Views you can get almost everything that you want if all the data involved is related. If you give us more concrete details about what you want to achieve, I could give you precise details of how to configure the View that will solve your problem.


7Random ASCII chars in footer? goes away when I clear the cache but comes back as soon as I visit another page.

new standard installation (drupal 7.32)
lighttpd + php 5.4 (fpm)
mariadb

this looks like a collation issue in your database tables. Perhaps you copy and pasted some text from a Word file or other file that had a weird character set encoding and when it was saved to the database the proper text was lost in the transition.

I recommend looking at where the text in your footer is coming from originally, a foreign webpage, an MS Word file, an XML file -- and what encoding it has.

Then I would recommend you look at the Collation Fixer module which is designed to help with this issue. It will properly set your set tables to 1 Collation -- you must then provide the correct text/prose/verbiage into your footer so that its in the same character set the database expects.

  A 'runtime' requirements checker (admin/reports/status) for checking
  all database tables have the right database collation (probably very
  MySQL centric).

  Offers the ability to fix tables with wrong database collation.

  The collation is either specified in your database settings or in
  hook_schema() or hook_schema_alter().

  This can be useful when developing non-english sites.

  Example of specifying in database settings in settings.php (will
  affect all tables - it's probably better to do it in hook_schema() or
  hook_schema_alter()):

<?php
$databases = array(
  'default' => array(
    'default' => array(
      'database' => 'my-db',
      'username' => 'my-user',
      'password' => 'my-password',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
      'collation' => 'utf8_danish_ci',
    ),
  ),
);
?>


How to change the SID of webforms to increment from a new starting number We launched a new website that uses webforms but need to make sure our webforms are using an SID for results larger than the last number used on the old site.

Please note that I am not referring to the serial for the webform submission but Drupal's SID.

For example, on the new site, the first submission ID was 1. I need it to be 10000.

If it's a Drupal 7 site:

Edit the webform.
Go to the "Form settings" subtab of the Webform
tab.
Scroll down and expand the Advanced Settings section.
There's an exposed field for the Next submission number.

If it's a Drupal 8 site:

Edit the webform.
Go to the "settings" subtab of the Webform
Scroll down and expand the Submission Settings section.
There's an exposed field for the Next submission number.


How can I limit submissions within a period of time? How can I limit submissions within a period of time?

I am moving from webforms to entity forms and need to limit the number of submissions a user can make within a given time. I want to restrict access to form based on this. This would be only apply to anonymous users.

List item

1 Submission per week
3 submission per day
etc. Similar to the setting on webforms

You need to identify a unique identifier.

It can't be the UID as schlicki mentioned in the comment.

You can add an email field. But if you don't add validation to this, people can just make up something up.

If you're going to add email + validation, would an account on the site be worth it?

Another option is a combination that identifier the browser as unique. You can look into https://github.com/Valve/fingerprintjs2. You can take all those properties and hash all of those together. That should give you a good identifier.

THIS CAN BE FOOLED. BY DEFAULT THEY WILL BE ABLE TO SUBMIT A FORM PER EACH BROWSER ON EACH DEVICE THEY HAVE.

If it doesn't have to be super strict, it would work.

This link, https://panopticlick.eff.org/ may have more information on what you're exploiting.

What I would do,

Generate a hash based on all the properties from fingerprintjs2.
Take that hash and add it to a hidden field
On submit, you can check the value

Validate that it's not empty.
Check the value in the database (you'll need a table for this)
If it is on your table,

Check when was the last time this was submitted
Apply your rules.

If it can be submitted again, perfect.
If it can't be submitted again, show a message. You can show how much time they need to wait for the next submission.

If it's not on your table,

Add the value to the database
Allow the submission through

That's the logic that you would have to apply.


I would like to display only the teaser view of nodes I hope someone can help me. Here's my issue:

I'd like to create a content type - let's call it News Story.

Amongst its other attributes, this content type will have a taxonomy field.

I would like to be able to create a number of views around my site to display a subset of the News Story content, based on its taxonomy value.

However, I do not want the News Story to generate a standalone node/page - I only want the news stories to appear in views of news stories.

Have you done this before? How did you do it?

I'd be really grateful for your help.

Thanks

One solution would be to use the Rules module.
Add a new rule and set this:

Condition:

Node is of type: News Story
Custom PHP: check display_id == full
User rôle: not admin/editor (so you can still view/edit if you're not anonymous)

Action:

Redirect to the page you want (404 or your news list for example)


How do I create a simple breadcrumb with pathauto? I'm using Pathauto to setup my url paths like this:

www.blah.com/parent1/parent2/page-name

I want my breadcrumbs to mirror this on every page:

Home >> Parent1 >> Parent2 >> Page Name

I've installed custom breadcrumbs but it wants me to create a custom breadcrumb for each content type. Can I just create one to use site wide? Preferable add via a block or view.

I guess easy_breadcrumb module would be good to use for this scenario.

  The Easy Breadcrumb module provides a plug-and-play block to be embedded in your pages, typically at some place near the page's header. Easy Breadcrumb uses the current URL (path alias) and the current page's title to automatically extract the breadcrumb's segments and its respective links.

Example: URL like gallery/videos/once-a-time-in-cartagena, Easy Breadcrumb will automatically produces the breadcrumb as

  Home >> Gallery >> Videos >> Once a time in Cartagena

or

  Home >> Videos >> Once a Time in Cartagena

Again, the breadcrumb presentation will vary depending on your module's settings.


How to add custom class in body tag on form submit? I have created custom module with custom form, in which I have added input type select. Form submission is working fine, but I wanted set select option value as custom class for BODY tag.

You can add through custom hook.

 function mytheme_preprocess_html(&$vars) {
  $vars['classes_array'][] = 'new-class';
}

OR

function YOUR_THEME_preprocess_html(&$vars) {
  $path = 'your-drupal-page';
  if (drupal_match_path($_GET['q'], $path) || drupal_match_path(drupal_get_path_alias($_GET['q']), $path)) {
    $vars['classes_array'][] = 'page-my-css-class';
  }
}

If you have any query related how to create then you can check this LINK.


How to create a View that shows other nodes that have the same entity reference as the current page I have job nodes, that relate to organizations. I want a sidebar block that will display other jobs that are related to the same organization.

I have tried a lot of different permutation of contextual filters and relationships, but so far I have not been successful.

I can only get the nid of the current node via a contextual filter, but that filters the content directly. I need just to get the referenced organization node, and then filter the view by that reference, but I can't seem to make it work.

(This question is for Drupal 7 with entity reference. The same question for Drupal 6 is here).

Here is a solution using the Entity Reference module to display other nodes that reference the same node that the current node references. No need for relationships, just follow these steps:

Make sure you're filtering the view by the content type you want to view a list of, not the one you're trying to reference.
Add a contextual filter using the entity reference field.
For the entity reference field, choose to provide a default value in PHP ¹.
Adapt the following code to your field names ² and save the contextual filter:

$node = menu_get_object();
$referenced_node = $node->field_YOUR_FIELD_NAME['und'][0]['target_id'];
return $referenced_node;
Save the view and check it out.

¹Disclaimer: PHP should never be used in the UI due to concerns with security, performance, & lack of version control. As a result, the proper way to implement this solution involves writing your own simple module that creates a block that passes the argument into the view as you render it in the block. I'm still including this because whether people ignore this warning or use it to write a module, hopefully it helped.

EDIT: If you also want to exclude the current node, you'll need to add an additional contextual filter for NID and make sure to select the "exclude" option.

² Not sure what your field names are? Install and enable the Devel module and visit a node. Click the 'devel' tab and navigate through the list to find your desired entity reference field.


How to sync users profiles and user tables in 2 drupal sites I have a website with 14K registered users. There is new section of that website which has been developed as a separate Drupal installation. The users in the old website should be able to login with their username and password to the new site.

My questions are :

is there a way to connect new site "user registration/login/forget
password" features with the old one?
Should i sync the databases all
the time? Or when the new user registers, his information is added
in to new and old site ( and Vice Versa)

What is the best practice in such cases.

thanks :)

There are many ways you can sync Drupal accounts.

Using Drupal OpenID-Single-Sign on (OMniauth) which very common method for the big organisation who manage a number of drupal/websites. more on that please refer to Comparison of Single Sign On (SSO) Modules
You can also look into Account Sync module which I haven't tested myself yet and it has a very limited number of site "130" reported using it so you better be careful with it. The module provide basic single sign-on support.
The other way will be to export users from sites using User Export module. then use Feeds module to import site. You can use Rules module to to export and import users between both sites, probably by running crone on both sites in sequence.
Take look into Bakery Single Sign-On System, which is useful single sin-on for the sites that based on the same second-level domain "example.come, test.example.com".
Domain Access module which suite of modules that provide tools for running group of affiliated sites from on drupal installation and single shared database. The module allows you to share users.


Controller classes in Entity API I'm trying to follow this article to build my first entity using Entity API module. I'm unclear about the dependency between controller classes and include files. If it says:

'controller class' => 'ExampleTaskController',

does this mean the class has to be in a separate file named exactly as the class name (as it is in Views)?

No.

'controller class' => 'ExampleTaskController',

  controller class: The name of the class that is used to load the
  objects. The class has to implement the
  DrupalEntityControllerInterface interface. Leave blank to use the
  DrupalDefaultEntityController implementation.

Says nothing about where the class code actually lives in Drupal. The easiest place to put it is in the same file your declaring hook_entity_info. Because since it's in the same file it will be found by PHP because the class will have the same file scope as your hook_entity_info implementation, and likely the other hook functions needed for your entity.

In PHP there are only 3 scopes: file scope, function scope and global scope.

So how can it live outside of say YOURMODULE.module. You declare where this class can be found in your YOURMODULE.info file with the files[] directive.

Such as:

name = my custom module
package = other
files[]= EntityClassController.inc

Files defined by the files[] entries are scanned for class definitions and included automatically by Drupal in its bootstrap phase to be available as-needed by running code. So your class would live in the file location of DRUPAL_ROOT\sites\all\modules\mymodule\EntityConroller.inc as an example.

Alot of times to organize code better developers add subfolders, or submodules to their modules you could for instance declare the class to live in an includes folder in your modules folder with:

files[]= includes/ExampleTaskContoller.inc

Some hook functions such as hook_views_api and hook_menu allow you to define a file location where the page callback function can be found (in the case of hook_menu) or where your views implementation classes/handlers/etc may be found in the case of views.

For instance hook_menu allows for the following 2 keys to better organize where page callback functions live in your source code:

  "file": A file that will be included before the page callback is
  called; this allows page callback functions to be in separate files.
  The file should be relative to the implementing module's directory
  unless otherwise specified by the "file path" option. Does not apply
  to other callbacks (only page callback).

  "file path": The path to the directory containing the file specified
  in "file". This defaults to the path to the module implementing the
  hook.

Views allows 1 to define where views includes lives via hook_views_api:

  path: (optional) If includes are stored somewhere other than within
  the root module directory, specify its path here.

  template path: (optional) A path where the module has stored it's
  views template files. When you have specificed this key views
  automatically uses the template files for the views. You can use the
  same naming conventions like for normal views template files.


Filter view by taxonomy terms of current user I've done lots of work with Drupal 6, but currently have no more ideas how to approach this problem in D8. Please help me :)

I have added taxonomy term field to user profile and would like to filter a view allowing only content having terms listed in user profile.

For example: User has terms "manager" and "south" is presented with content having either of this term without having to select exposed filters etc.

The point is not to restrict content (like with taxonomy access control), just to provide more relevant content.

It's the same process as D7 (see related thread)

But all you need to do is add a relationship to the taxonomy term and then add a contextual filter with the Term ID set as the fixed value.


Drupal image style issues I have a peculiar problem. I have 3 sites on a Debian/Nginx setup.
Let's call them site1.com, site2.com and site3.com.
After upgrading to 7.20, site2.com and site3.com image styles stops being created while site1.com is working. I installed fresh Drupal 7.22 in a subdirectory in site1.com and site2.com (also upgraded all the sites to 7.22). The fresh installations won't create image styles either. I thought the fresh installation in site1.com subdirectory will work since site1.com itself works fine but that's not the case. I'm totally lost here. The Nginx site conf settings are the same for all the sites so I'm not sure it's a server issue. I have spent the past few days reading about this but can't an issue similar to mine.

I just followed the instruction here http://drupal.org/node/244924 to fix any file permission issues but the image styles are still not generated. I also tried this module http://drupal.org/project/image_allow_insecure_derivatives, it didn't work either.

It was my sever setup after all. Thanks to this post: Is there a common nginx conf for Drupal 7 sites?, I was able to fix the issue. Image styles now work on all my sites.

My initial setup was

    location ~ ^/sites/.*/files/styles/ {
            try_files $uri @rewrite;
    }

The above setup worked for a while and was working for one of my sites but won't work after upgrade for the others for some reason.

I changed it to this

    # Image styles for D7
    location ~* /sites/.*/files/styles/ {
            access_log off;
            expires 30d;
            try_files $uri @rewrite;
    }

and it's working now.


From what directory should "drush cc all" command be run? I've always ran drush cc all this way:

 C:\example\sites\all\modules>drush cc all

But can I also run it this way?

 C:\example>drush cc all

Does the second option fully clear the cache and the first one only the modules cache?

I never thought about this, always did it the first way...)

It's irrelevant. The command:

drush cc all

clears all caches. The directory has no affect on what is cleared. If you want to target modules use:

drush cc module-list

Or if you want to target another cache use:

drush cc

which will prompt you for a cache to target.


How do I migrate block content from a dev to a production site? I've finally started looking at Drupal 8 seriously and I'm particularly interested in the configuration management. I've come across something that could be a little bit problematic and that's regarding custom block content.

I can see that the configuration management system is able to export block configuration - region, theme, weight, visibility etc. however the actual block content does not come across in the config export, which is reasonable and understandable.

On importing that block config to a production site, what appears to happen is the block config is created and a holding message is put in place, reporting the block is broken or missing. Obviously the block content doesn't exist on the production server.

How can custom blocks be migrated from a dev/staging server to a production server? I realise that blocks in Drupal 8 are fieldable entities like nodes and so will need to be migrated in the same way and I understand there is a Migrate API in Drupal 8 but this appears to be built for migrating content from Drupal 6 and 7 sites to Drupal 8 as opposed to Drupal 8 to Drupal 8 sites.

This issue is specifically regarding custom blocks as blocks generated by other modules such as Views will obviously migrate across as configuration.

Another answer I haven't seen mentioned here is to use the Simple Block module, which is pretty much identical to core's 'Custom Block' setup, but instead of having a weird hybrid of content + config, you have all the Block settings and content stored in configuration, which can be cleanly exported and imported.

See, for further discussion in Drupal 8 core: Custom blocks cannot be properly exported and imported.


Services api set browser cookie I would like to use Services to programmatically login a user from another website.

So for example if site.example.com uses the services login endpoint on example.com in Chrome, when that user moves over to example.com they will already have a valid session and cookie for accessing the site.

I have looked into adding the cookies.txt file via my CURL request, and have tried the various different Drupal authentication method like user_login_submit() and drupal_session_regenerate() but none of them are working.

When i navigate over to example.com the user is still seen as being anonymous.

Just for anyone who is looking to implement something similar, i done this using a http redirect to an authentication page, passing and authenticated using the token generated from drupal_get_token() (important not to use the session id).

The important steps to follow are to override the GLOBAL $user with the newly generated session user details and then regenerate the session using drupal_session_regenerate().


Drupal 7, Aggregator, RSS no longer imported: The feed from $ seems to be broken, due to an error "Invalid document end" on line # I run a Drupal 7 website and have a separate WordPress blog. The blog generates a feed, which I display (RSS2 version) in a Block on the Drupal website via the Aggregator core module. This worked fine until somewhere in December.

The last update post/feed shown on the Drupal website is from 24 Nov. '17. The newer 2 posts have not made it onto my Drupal website. However, when I check the feed itself, the posts are present in the feed.

Drupal website: https://www.lovedominique.co.za/

Feed of blog: https://lovedominique.co.za/blog/feed/

The error message that Drupal shows is:

  The feed from New On Our Blog seems to be broken, due to an error
  "Invalid document end" on line 128.

I checked the feed on http://www.feedvalidator.org/ (link). There is no mention of line 128 on feedvalidator. But, another error shows up for line 187:

  line 187, column 0: url must be a full URL:
  https://lovedominique.co.za/blog/wp-content/uploads/2017/10/adding_texture.mp4

I don't understand why I am getting these error messages. The lines look okay to me.

Installed updates
I deleted my browser's cache (Firefox ESR).
I deleted the Drupal cache (on the server).
I added a new test post to the blog, and confirmed that it shows on the feed (https://lovedominique.co.za/blog/feed/). Yet, it does not get imported by Aggregator.

It turns out that a simple smiley :) wrought all the havoc. The smiley was situated in the first paragraph of a post and was therefore transferred via the feed to Aggregator.

Removing the smiley removed the errors and now the feed is showing correctly again.

I don't know what exactly is wrong with ':)', but somehow it messed things up. Explanations are welcome.


Commerce - how to allow users to buy 2 free products For a current site I am building, authenticated users should be able to order 2 free products (of a certain type), after which the prices are back up to full price. Is there any solution which allows this kind of functionality? I can't seem to find the right words to search as nothing is coming up.

If not, any ideas on how to implement this with Rules / code?

I imagine I would have to add a new line item for the 2 free tickets at $0, and deduct these 2 products from the original line item, but I'm not sure at what stage in the process to do this. Any help?

By using the Goals module (disclosure: I'm its maintainer) you can have the Rules module take care of "monitoring users about buying their first 2 products" (as in your question). The advantage of using the Goals module, is that you can keep track of all sorts of events that are happening asynchronously (which you cannot do by only using Rules and its events).

So with that it seems that your question (challenge) is reduced to finding a way to configure the appropriate set of Goals and related Tasks. For a basic introduction about Goals, have a look at:

How to implement gamification in a Drupal site and award incentives?
Its video tutorial.

Here is what it would take to implement something like a frequent buyers program:

Goal = "New customer", with only 1 Task = "Buy 1 product" (say with machine name = buy_product).
Goal = "Existing customer", with Task = "Buy 2 products".

The interesting part of this is that you'd only have to write 1 rule (related to that machine name = buy_product) to keep track of the progress of any user to become either a "new" or "existing" customer (check the video for a similar sample).

Homework: how should a rule look like to indicate that a user bought a product (either the very first one, or yet another one)?


How to limit adding content of a specific content type to paid memberships only? I have created a user role "seller"

when user enters to their account a "Add blog post"-tab is shown to  user when user click on it he/she can add "Add blog posts"

"Add blog posts" is a node form which contains field "title","image upload","body"

I want to add restriction to "seller" type user
Only those users can add post who paid (paid membership) for it to add "Add blog posts" (I have created a special role for paid membership).

Notes:

I have created a special role for paid membership.
When a user clicks on "Add blog post"-tab, the user must be redirected to checkout page if the user didn't paid in past. Users who already have the paid membership role should be able to create, edit and delete blog posts.

Assuming that your "Add blog post" matches with an URL like node/add/blog, you can use the Rules module to stop any user who is trying to use that URL, if that user does not have access to the role "Paid membership" that you have in place. Here is the actual rule to do so (in Rules export format, just import it in your own site and enable it there to see it at work):

{ "rules_limit_access_to_node_add_blog" : {
    "LABEL" : "Limit access to node\/add\/blog",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "NOT user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "4" : "4" } }
        }
      },
      { "text_matches" : { "text" : [ "site:current-page:url" ], "match" : "node\/add\/blog" } }
    ],
    "DO" : [
      { "drupal_message" : {
          "message" : "Adding content for selected content types (such as for \u0022\u003Cstrong\u003E[site:current-page:path]\u003C\/strong\u003E\u0022) triggers some extra (Rules) logic, as you can see here. I.e. for anyone who does not have the role to do so.",
          "type" : "error"
        }
      }
    ]
  }
}

The assumption in this rule is that your role "Paid membership" has a role-id of "4" (if not just adapt the role after you imported the rule to make it fit, or change the value of "4" before importing the rule). And if your URL is different from node/add/blog, then adapt that also to make it fit for your case. Obviously, the actual error message being shown may need tuning also. And if the machine name of your content type is not "blog", but "whatever", just change all blog occurrences to "whatever" before importing this rule.

Happy Rules-ing!


Why my button element don't trigger the submitForm method? I have a form with a <button> element

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['address'] = array(
      '#type' => 'textfield',
      '#autocomplete_route_name' => 'geocoder_autocomplete.autocomplete',
      '#title' => '' . t('Find an adoration place') . '',
    );

    $form['submit'] = [
      '#type' => 'inline_template',
      '#template' => '<button type="submit" class="glyphicon glyphicon-search"></button>',
    ];

    return $form;
  }

When I click the button the page is refreshed but the submitForm() method is not called. If I add an <input type='button'> element in the form and I click the <button> or the <input type='button'> the submitForm() is called.

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['address'] = array(
      '#type' => 'textfield',
      '#autocomplete_route_name' => 'geocoder_autocomplete.autocomplete',
      '#title' => '' . t('Find an adoration place') . '',
    );

    $form['submit'] = [
      '#type' => 'inline_template',
      '#template' => '<button type="submit" class="glyphicon glyphicon-search"></button>',
    ];

    $form['submit1'] = [
      '#type' => 'submit',
      '#value' => $this->t('Submit'),
    ];

    return $form;
  }

I'm missing something here? Why my button element don't trigger the submitForm method?

Your first "submit" button doesn't get recognized by Drupal as a button because you use an inline template.

If you want to add a class on your button use:

$form['submit'] = [
  '#type' => 'submit',
  '#value' => $this->t('Submit'),
  '#attributes'=> ['class'=>['glyphicon', 'glyphicon-search']],
];


How to show another text if field val 0? {% for item in items %}
    {% if item.content %}

balance

Yes {{ item.content }}

    {% else %}

balance

Nope

    {% endif %}
{% endfor %}

My field is integer.
I try all if (is null, is same as, etc...) but nothing works.

AFAIK  this is the correct way:

{% for item in items %}
    {% if item.content == 0 %}

balance

Yes {{ item.content }}

    {% else %}

balance

Nope

    {% endif %}
{% endfor %}


Module to search node titles only Is there a module that allows me to restrict searches to node titles, rather than any node content?
Preferably the user would choose between titles only or everything.

You could use Views Search and build a views with only the title of nodes as an exposed filter, then this module convert your exposed filter in a search option.


is it ok to have multiple versions of jquery? I'm facing some peculiar problems(my devel_themer is also not working). There are multiple versions of jquery included. Its not me who included them, its different modules:

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>window.jQuery2 = jQuery.noConflict();</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
window.jQuery || document.write("<script src='/drupal/sites/all/modules/contrib/jquery_update/replace/jquery/1.10/jquery.min.js'>\x3C/script>")
//--><!]]>
</script>

I don't know if any of the following errors relate to problems:

SyntaxError: Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead jquery-1.9.1.min.js:1
Error: http://code.jquery.com/jquery-1.9.1.min.js is being assigned a //# sourceMappingURL, but already has one
SyntaxError: Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead jquery.min.js:1
Error: https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js is being assigned a //# sourceMappingURL, but already has one

should I remove them?

Try using the jquery multi module. Drupal core relies on specific versions of jquery, but this module allows you to control which environments use which version.
https://drupal.org/project/jqmulti

You shouldn't add jquery manually, nor should any modules. Drupal adds its own in core. Your errors may well be related, but that's hard to tell from the info you give. Do you know which module has added this?


Drupal 7 Bootstrap Subtheme update I'm trying to understand the flow of the bootstrap subtheme. The subtheme on my site was originally installed by a developer. I have since edited the css file to my liking and made adjustments to the bootstrap_subtheme.info, header.tpl.php, page.tpl.php, template.php and others.

The thing I don't understand is how to update the subtheme or even if I have to. I have been told by a developer that the bootstrap files are 5 years old. I apply each update as it comes into the list of updates and it is up to date in that respect. Do I have to update the subtheme manually from the basetheme? How do I find out the age/version of the subtheme?

The subtheme should inherit all of the basetheme files by default. So in theory you should be able to update the base bootstrap theme and your subtheme will gain all the benefits of those updates (Apart from things you're base theme has overwritten.)

E.g. if in bootstrap you have a page.tpl.php and you also have one in your subtheme then updating the bootstrap page.tpl.php won't have any effect as your subtheme has its own version of page.tpl.php

But anything that hasn't been overwritten/customised by your sub theme should be automatically be picked up by your subtheme. So you don't need to know what version your subtheme is, its effectly whatever the current bootstrap version is your subtheme is a ofshoot of that.


How can i use DB Connection of another site of my multisite? Following situation:
I have a multisite with several sites. The codebase is the same but every site has his own database. Now i'm creating a module where i want to make adjustments in the databases for all sites at the same time. So i have to be able to make database connections to the other sites.

I already was able to get the settings from the other sites with that:

$sites = glob(DRUPAL_ROOT . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR);

foreach ($sites as $site) {
  $site_path = str_replace(DRUPAL_ROOT, '', $site);
  $siteName = str_replace('/sites/', '', $site_path);

  if (is_readable($site . '/settings.php')) {
    $siteConfigs[$siteName] = [];
    $settings = [];
    $databases = [];
    $app_root = DRUPAL_ROOT;

    require $site . '/settings.php';
    $siteConfigs[$siteName]['settings'] = new Settings($settings);
    $siteConfigs[$siteName]['databases'] = $databases;
  }
} ```

How can i use DB Connection of another site on my multisite installation?
I tried different things like:

foreach ($siteConfigs as $siteConfig) {
  Database::addConnectionInfo('default', 'default', $siteConfig['databases']['default']['default']);
  $db = Database::getConnectionInfo();
  var_dump($db);

}

But it always returns just the current site.

Thanks for any advice!

You can initialize multiple database connections like this in your settings.php file:

<?php
$databases['default']['default'] = array(
    'database' => 'sitedb1',
    'username' => 'admin',
    'password' => 'admin',
    'prefix' => '',
    'host' => 'localhost',
    'port' => '3306',
    'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
    'driver' => 'mysql',
);

$databases['yellow-site']['default'] = array(
    'database' => 'sitedb2',
    'username' => 'admin',
    'password' => 'admin',
    'prefix' => '',
    'host' => 'localhost',
    'port' => '3306',
    'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
    'driver' => 'mysql',
);

$databases['green-site']['default'] = array(
    'database' => 'sitedb3',
    'username' => 'admin',
    'password' => 'admin',
    'prefix' => '',
    'host' => 'localhost',
    'port' => '3306',
    'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
    'driver' => 'mysql',
);

Then you can get the connections with your module etc.:

<?php
$greenSiteDatabase = Database::getConnection('default', 'green-site');
$yellowSiteDatabase = Database::getConnection('default', 'yellow-site');
$defaultDatabase = Database::getConnection('default', 'default');

You can query a database like so:

$banana = $yellowSiteDatabase->select('SomeTable', 'st')
  ->fields('st', ['fruit'])
  ->condition('fruit', $someCode)
  ->execute()
  ->fetchObject();


Building a view with arguments from a search select list I have a block with custom search options based on taxonomy terms (hierarchical dropdown).
When you submit the form, it renders the ID of the taxonomy terms. I want to have a query in another block on the same page which renders all nodes containing the taxonomy terms.
How can I link the IDs?
Is this possible to do it with Views? Should I build a custom view through a hook, or is there another way to achieve this goal?

I am using the 7.x-3.x-dev version of Views.

In the block display, add a contextual filter for your taxonomy term field. Set it to Provide a default value when the filter value is not in the URL. Use Taxonomy term ID from URL as type for this default value and select Load default filter from term page.


How to let the users input the filters in views I have enabled Exposed Group Filters in views. When I set the option to "input required" no results are shown, also does not give me an option to input any filter from the selected option. All I get is an Apply button.

My Query is:

How do I let the users see all results in the view first, let the user input their filter criteria from the allowed list & then show them the results basis of the filters?

I have tried Better Exposed Filters, its still not giving me an option to input my query.

Please advice.

Thanks

The exposed filters are not displaying because the view is empty and therefore not rendering.  As per this issue, if you give your view something to display when it is empty (i.e. a no results behaviour setting), it will show your filters.

Then, if you really don't want to show 'no results' (which is what most people put in there) you could hide it wish CSS.


Is it bad practice to add markup to title or label fields? The title might not make sense because I'm not sure what the correct wording is. But here is the example that explains what I mean.

I am creating a block view to go at the bottom of a node page that links in extra info relevant to the node (a users blog post on their profile page).

I titled the block Blog Posts but it was small and smashed up against the bottom of the content above it. So I tried calling it
Blog Posts
 and it displayed as an
. So I got more creative and now the title is

Blog Posts
. It looks nice and works the way you would expect (with the html being rendered properly).

This method kind of seems like a bad hack, but inexperienced as I am with Drupal, I'm not sure why.

Is this bad practice, and why?

That'll work, but best practice is to theme it. The following answer describes how to theme a custom block: https://drupal.stackexchange.com/a/39270/23063


Is it possible to override/replace an event subscriber I would like to replace an event subscriber. Is there any way that I can write my class implementing EventSubscriberInterface which would replace another existing event subscriber instead of being performed earlier or later that the one existing.

You can do this by creating a ServiceProvider class.

Example service provider class to override the path_subscriber service.

namespace Drupal\MY_MODULE;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;

// @note: You only need Reference, if you want to change service arguments.
use Symfony\Component\DependencyInjection\Reference;

/**
 * Modifies the path_subscriber service.
 */
class MyModuleServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    // Overrides language_manager class to test domain language negotiation.
    // Adds entity_type.manager service as an additional argument.
    $definition = $container->getDefinition('path_subscriber');
    $definition->setClass('Drupal\MY_MODULE\MyCustomPathSubscriber')
      // Custom arguments.
      ->addArgument(new Reference('some_argument'));
  }
}

Another solution is to override the service in MY_MODULE.services.yml, like this:

path_subscriber:
  class: Drupal\MY_MODULE\MyCustomPathSubscriber
  arguments: [# The arguments]


views with a SOAP back end views3 supports plugable backends rather than a RDBMS, there are backends for solr, sparql, mongodb.

Is there such a plug in to enable views to be a front end for a SOAP api? I have found a number of modules to do with services, soap, etc. But nothing which would clearly fill this role.

I can't speak for Drupal 7/Views 3, but with Views 2 I used the Services module several times to expose content via Views, e.g. Services + SOAP Server + Views to make a bespoke Drupal-powered SOAP API. Perhaps that's not what you're after? SOAP Server would need porting anyway, but perhaps you could experiment with Views 3 and Services 3 and if it works ok with XML-RPC then consider helping port SOAP Server. It probably wouldn't take much work.


Use EntityFieldQuery to load by node ID How to use EntityFieldQuery to load the nodes based on available nids. I tried,

$query->propertyCondition('nid', $nid);

and

$query->entityCondition('nid', $nid);

Both of the above didn't work. What would be the right way?

There's no point doing that, use node_load() or node_load_multiple() instead (or entity_load()). EFQ exists to return you the IDs of entities, essentially so you can use them in an entity load function. If you already know the ID beforehand, then using EFQ is a waste of a database query.

To illustrate, if you were to add a nid condition to your query, then these:

->entityCondition('bundle', 'article') // ex. article
->propertyCondition('uid', $uid) // node written by a specific user
->propertyCondition('status', 1);

are all redundant, your query will just be:

$query->entityCondition('entity_type', 'node')->propertyCondition('nid', $nid);

and the only useful data you'll get is the node ID, which you already have.


How to display custom field using Views module at front end I have created custom content type having below fields

Title, Description, Small Image, Large Image and Category

I am using Views module to display that content  (only small image) in Grid format with 4 columns. Issue is that i don't find any option (Settings of my view) to display only custom field  at front end. The only thing i can see is title is being displayed in grid format.

Does that mean Views module does not show custom fields created for a custom type content at front end?

*SOLVED*

Never mind guys. I got solution. Once you go to your view (created using views module) edit page then at the bottom of the page there is a section called Content having options to add custom fields in view.

Views has the option of adding a custom field.
You need to search for global custom text field in the views
You can add a global custom text field as custom text field and alter the value using hook_views_pre_render(&$view)

function YOUR_THEME_views_pre_render(&$view) {

  switch ($view->name) {
    case 'YOUR_VIEW_NAME':
      //  override the global custom text field value
      $view->field['nothing']->options['alter']['text'] = 'My custom text';
    break;
  }
}

Click on the add as shown in the Image

Then search for Global custom text field as shown in the Image

You will see global custom text field which is custom text for views and you can alter it using above code or u can alter by entering html text into configure option for the field as shown in the image below :


New users not created when migrate source is nodes instead of users I'm working on a D6-> D7 user migration where I need the source to be a node, not a user. To get around the restriction of only one author per node, in the source D6 site we created a Source content type, and then in other node types (article, video, etc), we created field_source as a node reference field to reference Source nodes.

So now, in my user migration to D7, I need to get the data from the Source nodes instead of users. Here's what I have so far.

/**
 * Override of DrupalUser6Migration.
 */
class CNSUserMigration extends DrupalUser6Migration {
  public function __construct($arguments) {
    parent::__construct($arguments);

    $this->addFieldMapping('name', 'title');
    // Set a default password for all users.
    $this->addFieldMapping('pass')->defaultValue('Pass!234');
    $this->addFieldMapping('field_twitter', 'field_twitter_id_value')->description('Twitter ID');
    $this->addFieldMapping('field_job_title', 'field_source_title_value')->description('Job title');
    $this->addFieldMapping('field_bio', 'body')->description('Bio');

    // By default, the primary key is the uid from the users table,
    // but since our user source is a source nid, need to replace
    // uid with the nid of the source node.
    $this->map = new MigrateSQLMap($this->machineName,
      array(
        'nid' => array('type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'description' => 'Source node nid',
          'alias' => 'n',
        ),
      ),
      DrupalDestinationUser::getKeySchema()
    );
  }

  /**
   * Override of DrupalUser6Migration::query()
   *
   * @return mixed
   */
  protected function query() {
    // Create query from scratch to get source nodes referenced from field_source
    $query = Database::getConnection('default', $this->sourceConnection)
      ->select('node', 'n')
      ->fields('n', array('nid', 'title'));
    $query->innerJoin('content_field_source', 'cfs', 'cfs.field_source_nid = n.nid');
    $query->innerJoin('content_type_source', 'cts', 'cts.nid = cfs.field_source_nid');
    $query->fields('cts', array('field_source_title_value', 'field_twitter_id_value'));
    $query->innerJoin('node_revisions', 'nr', 'n.nid = nr.nid');
    $query->fields('nr', array('body'));
    $query->distinct();

    return $query;
  }
}

So my query works fine and gets all the relevant Source nodes, but when I ran it the first time, I realized I had to change my source PK to be the nid of the Source node instead of the default uid from the users table. As you can see above, I overrode the map with a new MigrateSQLMap object in my constructor.  However, when I run the migration, it creates the first user from the query, but then all of the subsequent source records also point to that first new user instead of creating new users. Now that I've defined a new source PK, do I also need to do something on the destination side to cause it to create new users?

Thanks.

Since you know SQL, It would be simpler and definitely quicker to use SQL and SELECT the users from the source nodes and INSERT it into the user table rather than attempting to write a PHP script.


RDF core module doesn't seem to work after security upgrade I updated from Drupal 7.36 to 7.38 for security reasons. Now the nodes don't get displayed in RDF any more. For example: http://bartoc.org/en/node/112, add .rdf and you get the message "The requested page "/en/node/112.rdf" could not be found." The RDF core module is checked. Am I missing something?

Here is a workaround at #9 that solved the problem for me.

  As workaround, you could use the RDFa Distiller and add the
  following code to .htaccess:

<IfModule mod_rewrite.c>
   RewriteEngine on
+  # call W3C RDFa Distiller to extract .rdf/.ttl/.nt files
+  RewriteRule (.*)\.rdf$ http://www.w3.org/2012/pyRdfa/extract?uri=http://%{HTTP_HOST}/$1&format=xml [L,R=307]
+  RewriteRule (.*)\.ttl$ http://www.w3.org/2012/pyRdfa/extract?uri=http://%{HTTP_HOST}/$1&format=turtle [L,R=307]
+  RewriteRule (.*)\.nt$ http://www.w3.org/2012/pyRdfa/extract?uri=http://%{HTTP_HOST}/$1&format=nt [L,R=307]
+
   # Set "protossl" to "s" if we were accessed via https://.  This is used later
   # if you enable "www." stripping or enforcement, in order to ensure that
   # you don't bounce between http and https.

Many thanks to jneubert!


Cron jobs in Drupal 7 I have a PHP file that does some task in consistent intervals.

I have placed that PHP file inside a custom module folder, but I found that Drupal functions like drupal_set_message() are not available inside the PHP file.

How do I include Drupal functions inside this PHP file?
How do I set up this php file to be run as a cron job?

You need to implement hook_cron() in your module and execute these tasks there.

Then, drupal will automatically execute these tasks during the default cron handling.

You probably have used drupal_set_message() only as an example but note that using that function in a hook_cron() implementation makes no sense because there is no user to read these messages. As an alternative, you could log messages with watchdog().


How do I get rid of a table doesn't exist warning? I have a Drupal 6 installation for my website, and over time, without any doing on my part, I started getting an error, below:

  user warning: Table 'pharmtec_pharmtechinc.xmlsitemap' doesn't exist
  query: SELECT * FROM xmlsitemap WHERE type = 'node' AND id IS NULL in
  /home/pharmtec/public_html/sites/all/modules/xmlsitemap/xmlsitemap.module
  on line 544.

I have no clue what the issue is.  I did find out, though, that it does come up for both existing and new pages.

I'm stuck because I can't update the content of the site.  When I add information and preview, it shows all the source code for the entire page, rather than just the text.  :(

Thanks for any help you can provide.

If ok with some code, you could also try running

drupal_install_schema('xmlsitemap');

and that should recreate the xmlsitemap tables, backup db first.

more info:

xmlsitemap_install
xmlsitemap_schema


Meta title content based on node fields Is there a module that will allow me to set the default meta title for a content type to be the title field of the node displayed?


Drupal permission table If u have seen drupal permission table, that is like

structure 1

pid rid    perm                   tid
1    1   view f1, edit f2          0
2    2   view f1                   0

what is good with  structure1?

why drupal doesn't use this structure?

table1

    fid      name
    1      view f1
    2      edit f2

table2

pid  rid  fid
1     1    1
2     1    2
3     2    1

Table 1 matches how it is in Drupal 6, table matches more or less how it is in Drupal 7.

So to answer your Question, the newest Drupal does indeed use a schema close to what you proposed.


How do you get Solr Views to query Acquia Search? I'm looking to build a set of sites which are all indexed by Acquia Search into a single index.

I also plan to build an umbrella site to help people discover content on the sites below. I was looking to the Apace Solr Views module for this. How do I get this module to build views from the Acquia Search index?

Acquia search :
A search service provided by acquia which in-turns uses the Apache Solr search inside. Currently they are updated their acquia search with Solr 3.5.
Apace Solr Views module :
Module when enabled converts the views query from a database query to apache solr search query.
While enabling the Apache Solr Views module it will look for the apache solr configured in the drupal system automatically.


DB API: How to get a list of nodes ordered by highest comment creation date? The DB API is once again kicking my tail...

I've got a bunch of nodes of a certain type, each of which can have any number of comments, all in the usual way.  I'm trying to do a db_select()-based query that will give me the set of nodes of that type, ordered by the creation dates of each node's comments: The first node in the set would be the one that has the most recent comment, the second node would be the one that has the second most recent comment, and so on.  I'm sure / strongly suspect that this takes some sort of subquery, but I'm just not getting it right.  Can anyone offer some help?  Thanks!

The best place to query for that is the node_comment_statistics table.

It contains the relevant comment statistics such as comment count and last comment timestamp for a node.

e.g: Query for article nodes ordered by last_comment_timestamp DESC

$query = db_select('node_comment_statistics', 'c');
$query->join('node', 'n', 'n.nid = c.nid');
$query->fields('c', array('cid', 'last_comment_timestamp')); // fields
$query->fields('n', array('nid', 'title'));
$query->condition('n.type', 'article'); // e.g filter for articles only
$query->condition('n.status', 0, '>');
$query->orderBy('c.last_comment_timestamp', 'DESC'); // Order by last commented
$results = $query->execute();

foreach($results as $row) {
  drupal_set_message('<pre>'.print_r($row,1).'</pre>'); // debug
}

node_comment_statistics table schema:

mysql> desc node_comment_statistics;
+------------------------+------------------+------+-----+---------+-------+
| Field                  | Type             | Null | Key | Default | Extra |
+------------------------+------------------+------+-----+---------+-------+
| nid                    | int(10) unsigned | NO   | PRI | 0       |       |
| cid                    | int(11)          | NO   |     | 0       |       |
| last_comment_timestamp | int(11)          | NO   | MUL | 0       |       |
| last_comment_name      | varchar(60)      | YES  |     | NULL    |       |
| last_comment_uid       | int(11)          | NO   | MUL | 0       |       |
| comment_count          | int(10) unsigned | NO   | MUL | 0       |       |
+------------------------+------------------+------+-----+---------+-------+


How Can i control the way the tabels in the admin panel build? How Can i control the way the tabels in the admin panel build?
i want to make the system more comfortable for the people how will be doing all the content edit in my site.

Like change the way this build -

Matan

If you just want to style the D7 administrative theme (called "seven") differently, you can create a sub-theme of that theme and then customize. Docs are here: https://drupal.org/node/225125

Once you have a sub-theme, you can add you own css, templates, etc to change the way things look.

Because of the inheritance you get when sub-theming, you only have to add what you need to the new theme. For example, you could just have an .info file and custom css file.


Format plural problems in Views module I built a Drupal 7 site using the Views module and I am using the "comment count" field.

If I choose the format plural checkbox, with a comment, it will output "1 comment", and when there are zero comments, 2 or more comments, it will output the number of comments followed by comments. If I want to output "no comments yet" when the comment count is 0, I can use the "No result  behavior (Count the number 0 as empty)" option.

The problem is that the format plural option is not working together with the "No result  behavior" option. When I use both of them, I get "0 comments" instead of "no comments yet."

How can I achieve my goal?

I managed to get this working by using the following settings for the Content: Comment count field:

Format plural checked
Singular form: @count comment
Plural form: @count comments

Under No results behavior:

No result text: no comments yet
Count the number 0 as empty checked
Hide if empty  checked
Hide rewriting if empty checked


How to hide/show view based on field's value? Problem: I have a user directory that anyone can access, with pages for each user. However, there is a view (that's a block) with personal info that I only want shown to the user who's page it is, or users with an admin role. They are not the authors of the page. I know how to fix the admin role issue, and how to get the username using php, but not how to get the field containing the username of the person who owns the page. I can't use Views PHP, just Views. Thanks!

EDIT: I tried doing something where in the view's header I had

if ($current_user == "[field_user_name]") { ?>

Then in the footer of the view:

<?php } ?>

But that hasn't worked.

Okay, I think I got it now. Already tested.

Override the view's template (Tutorial)
Include global $user; somewhere in the first php tag.
Use an if statement: <?php if (strip_tags($view->render_field("YOUR_FIELD", $id)) == $user->name): ?> with YOUR_FIELD as the field's replacement pattern without brackets. (remember the <?php endif; ?>)

Sample view template (for unformated view display):

<?php

/**
 * @file
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */
global $user;
?>
<?php if (!empty($title)): ?>

<?php print $title; ?>

<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <?php if (strip_tags($view->render_field("title", $id)) == $user->name): ?>
    <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
       <?php print $row; ?>

  <?php endif; ?>
<?php endforeach; ?>


New content type not listed in content types First time I created the content type 'address', I simply clicked save, not 'save & edit fields'. As a result, my new content failed to be listed under admin/structure/types. Then I simply tried the same thing again, with the same result of nothing being listed. When I did this though, A Drupal message said that the content type 'address' had been updated.

3rd time I clicked 'Save & edit', I wanted to manage fields, but that generated a URL that said www.domainname.com//fields instead of www.domainname.com/address/fields. Also a notice came : Notice: Undefined index: address in _field_ui_bundle_admin_path() (line 325 of C:\xampp\htdocs\hosting\sites\drupal7\modules\field_ui\field_ui.module).

Note that I'm using the module Automatic nodetitles

The problem you're facing is producing symptoms very similar to the ones in this bug. Especially because one of the symptoms you mentioned is that after you create any new content type with the same machine name that had a problem ('address' in your case) you get the message:

  The content type XXX has been updated

This issue is because one of the content types that you previously created originally had a machine name of 'address' but was renamed to something else. This is because Drupal actually preserves the original machine name of any content type in the DB Table named "Node_Type" in the column "Orig_Type".

Firstly, I suggest that you open the "Node_Type" table and try to investigate. You will most likely find that one of the listed Content Types has 'address' in its "Orig_Type" column.

The bug I've linked above contains patches in order to prevent this kind of issue from happening in the future. Unfortunately, in your case, the issue had already happened and you must now clean-up.

I'm not an expert in this field as I've only been involved with drupal for 6 months. However, I'll try my best to list the steps you need to do to remedy the issue. Note that there may be better/cleaner methods than the ones I've listed below so please be cautious:

Step 1 - Please carefully investigate the "Node_Type" table in your Database as I've mentioned above before proceeding. You may be facing a different issue and this solution may or may not work in that case.

Step 2 - Backup your Database before proceeding

Step 3 - Please try to perform one of the following procedures, preferably in order until one of them works for you:

A. Try the Deletion URL

Try to go to the URL YOUR_SITE/admin/structure/types/manage/MACHINE_NAME/delete and delete the content type
Check the "Node_Type" table to see if the problematic content type was deleted.

B. Programatic Deletion

Try to programatically delete the unwanted content type by running node_type_delete($type) and then optionally node_types_rebuild(). In order to use these 2 functions in a module you must use the hook_node_info(). Something similar to this code may work in your module's ".module" file:

<?php
function MYMODULENAME_node_info()
{
  node_type_delete("address");
}

Check the "Node_Type" table to see if the problematic content type was deleted.

C. Manually Replicate node_type_delete($type)

Visit the node_type_delete($type) hyperlink, and carefully read all the functions that it invokes. They are all clickable hyperlinks too.
Either write code to use each of its functions individually.
Or, replicate the actions that all the functions perform exactly and manually in your Database.

@Mods. The site restricts me from posting more than 2 hyperlinks because of my reputation, so apologies for lack of links.


Why does core uses the lib directory instead of the src one, for its classes? Drupal 8 now uses the PSR-4 specification for namespaces and auto-loading; module developers need to keep their PHP classes in their module's src directory.
However, if you look in the core directory, Drupal keeps all these in the lib directory.

Why is this so?

The following document explains the differences between PSR-4 and PSR-0, and the reason why PSR-4 was suggested.

It also explains that PSR-4 complies with the PSR-0.

Basically, when working with packages (modules) PSR-4 is preferable.
But the base package can still use PSR-0 and be readable.


How to add a custom widget to a node creation form Drupal 6 This may be a dumb question, but nothing I could find really told me what I was looking for. Without furthur ado:
I need to add a custom widget that will edit node reference fields on CCK content types. This widget needs to show up in the node creation form, and should consist of a textbox and a button. When the button is clicked, the widget should take the contents of the textbox and use it to create a new node of a different content type and then store a reference in the field it edits.
I need the D6 hooks which I need to implement this. Links to their documentation would be helpful.

I'd take a look at two modules, the base level Hierarchical Select module and its Hierarchical Select Node Reference submodule.  The second module allows you to create "on the fly" a node referenced by the parent node being created and may do what you need without custom coding on your part.


Per user language selection I need to do the following on my Drupal 7 site:

Anonymous users should see the website in Ukrainian (I mean not the content, but the elements like "Login", "Register" etc.)
Administrator (the user with all permissions) should see the admin panel in English.
Editor (custom created user that can create pages) should see his admin interface in Russian.

I suppose it can be done with a per-user language setting, but I cannot find how to do this. I already have all the translations installed.

"Follow the user's language preference" option in Drupal language preferences does the trick.