title: Problems to sync databases with drush

text:
# Question
Title: Problems to sync databases with drush
I have some problems with drush sql sync function

When the password prompt comes up I've used the Linux root user pass of the remote servers root user

Has anyone an Idea what I could do to fix this?

Here is the content of my alias file

```
$aliases['live'] = array(
  'uri' => 'www.eso-meetu.de',
  'root' => '/var/www/virtual/eso-meetu.de/htdocs',
  'remote-user' => 'root',
  'remote-host' => 'eso-meetu.de',
  'ssh-options' => '-o PasswordAuthentication=yes',
  'path-aliases' => array(
    '%dump-dir' => '/tmp',
    '%pubimg' => '/var/www/virtual/eso-meetu/htdocs/sites/default/files',
  ),
  'command-specific' => array(
    'sql-sync' => array(
      'no-cache' => TRUE,
    ),
  ),
  'databases' => array(
    'default' => array(
      'default' => array(
        'driver' => 'mysql',
        'database' => 'meetu_original',
        'username' => 'usernameremoverd',
        'password' => 'passwordremoved',
        'host' => 'localhost',
        'prefix' => '',
        'collation' => 'utf8_general_ci',
      ),
    ),
  ),
);

$aliases['self'] = array(
  'uri' => 'www.drupal.dev',
  'root' => 'var/www/',
  'path-aliases' => array(
    '%pubimg' => '/var/www/sites/default/files',
  ),
  'databases' => array(
    'default' => array(
      'default' => array(
        'driver' => 'mysql',
        'database' => 'drupal',
        'username' => 'drupal',
        'password' => 'drupal',
        'host' => 'localhost',
        'prefix' => '',
        'collation' => 'utf8_general_ci',
      ),
    ),
  ),
);

```

Here comes the output from drush verbose:

```
user@drupal:~/html$ drush sql-sync @self @live -d -v
 Bootstrap to phase 0. [0.01 sec, 4.35 MB]                                   [bootstrap]
 Drush bootstrap phase : _drush_bootstrap_drush() [0.01 sec, 4.36 MB] [bootstrap]
 Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
 [0.01 sec, 4.45 MB]
 Cache HIT cid:                                                                         [debug]
 7.0-dev-commandfiles-0-d59e04c348899678368fc648b2c8da2b [0.01 sec,
 4.46 MB]
 Bootstrap to phase 0. [0.06 sec, 11.35 MB]                                 [bootstrap]
 Bootstrap to phase 0. [0.09 sec, 11.35 MB]                                 [bootstrap]
 Found command: sql-sync (commandfile=sql) [0.09 sec, 11.35 MB]        [bootstrap]
 Including                                                                           [bootstrap]
 /home/user/.composer/vendor/drush/drush/commands/sql/sync.sql.inc
[0.15 sec, 11.39 MB]
Calling hook drush_sql_sync_validate [0.15 sec, 11.46 MB]                    [debug]
Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
[0.15 sec, 11.48 MB]
Loaded alias @live from file                                                       [notice]
/var/www/sites/all/drush/aliases.drushrc.php [0.28 sec, 11.49 MB]
Backend invoke: /usr/bin/php  -d magic_quotes_gpc=Off -d                  [command]
magic_quotes_runtime=Off -d magic_quotes_sybase=Off
/home/user/.composer/vendor/drush/drush/drush.php --php=/usr/bin/php
--php-options=' -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off
-d magic_quotes_sybase=Off'  --backend=2 --verbose --debug
--root=/var/www --uri=http://default  sql-conf   --all 2>&1 [0.37
sec, 11.51 MB]
/usr/bin/php  -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off -d     [notice]
magic_quotes_sybase=Off
/home/user/.composer/vendor/drush/drush/drush.php --php=/usr/bin/php
--php-options=' -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off
-d magic_quotes_sybase=Off'  --backend=2 --verbose --debug
--root=/var/www --uri=http://default  sql-conf   --all 2>&1 [0.37
sec, 11.51 MB]
You will destroy data in eso-meetu.de/meetu_original and replace with data from drupal.
Do you really want to continue? (y/n): y
Returned from hook drush_sql_sync_validate [4.84 sec, 11.53 MB]            [debug]
Calling hook drush_sql_sync [4.84 sec, 11.55 MB]                               [debug]
Starting to dump database on Source. [4.91 sec, 11.56 MB]               [ok]
Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
[4.91 sec, 11.57 MB]
Backend invoke: /usr/bin/php  -d magic_quotes_gpc=Off -d                  [command]
magic_quotes_runtime=Off -d magic_quotes_sybase=Off
/home/user/.composer/vendor/drush/drush/drush.php --php=/usr/bin/php
--php-options=' -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off
-d magic_quotes_sybase=Off'  --backend=2 --verbose --debug --strict=0
--root=/var/www --uri=http://default  sql-dump   --gzip --result-file
2>&1 [5.02 sec, 11.7 MB]
/usr/bin/php  -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off -d     [notice]
magic_quotes_sybase=Off
/home/user/.composer/vendor/drush/drush/drush.php --php=/usr/bin/php
 --php-options=' -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off
 -d magic_quotes_sybase=Off'  --backend=2 --verbose --debug --strict=0
 --root=/var/www --uri=http://default  sql-dump   --gzip --result-file
  2>&1 [5.02 sec, 11.71 MB]
  Bootstrap to phase 0. [5.05 sec, 4.35 MB]                           [bootstrap]
  Drush bootstrap phase : _drush_bootstrap_drush() [5.05 sec, 4.36 MB] [bootstrap]
  Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
 [5.05 sec, 4.45 MB]
 Cache HIT cid:                                                             [debug]
 7.0-dev-commandfiles-0-d59e04c348899678368fc648b2c8da2b [5.05 sec,
 4.47 MB]
 Bootstrap to phase 0. [5.1 sec, 11.35 MB]                                   [bootstrap]
 Bootstrap to phase 0. [5.13 sec, 11.36 MB]                                 [bootstrap]
 Found command: sql-dump (commandfile=sql) [5.13 sec, 11.36 MB]        [bootstrap]
 Calling hook drush_sql_dump [5.19 sec, 11.42 MB]                               [debug]
 Drush bootstrap phase : _drush_bootstrap_drupal_root() [5.19 sec,     [bootstrap]
 11.42 MB]
 Initialized Drupal 7.30 root directory at /var/www [5.2 sec, 13.09       [notice]
 MB]
 Drush bootstrap phase : _drush_bootstrap_drupal_site() [5.2 sec,      [bootstrap]
 13.09 MB]
 Initialized Drupal site default at sites/default [5.2 sec, 13.1 MB]      [notice]
 Cache HIT cid:                                                                         [debug]
 7.0-dev-install_profile-66ecfeb9791a023150773849f1550c5d [5.2 sec,
 13.1 MB]
 Cache HIT cid:                                                                         [debug]
 7.0-dev-commandfiles-2-f1f919de142adb82dd89194b63606c3b [5.2 sec,
 13.11 MB]
 Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [5.21[bootstrap]
 sec, 14.53 MB]
 sql-query: SHOW TABLES; [5.22 sec, 14.73 MB]                               [status]
 Executing: mysql --defaults-extra-file=/tmp/drush_KDqlDn --database=drupal --host=localhost --silent  < /tmp/drush_TpJfBn
  actions
  authmap
  batch
  block
  block_custom
  block_node_type
  block_role
  blocked_ips
  breakpoint_group
  breakpoints
  cache
 cache_block
 cache_bootstrap
 cache_entity_comment
 cache_entity_file
 cache_entity_message
 cache_entity_message_type
 cache_entity_message_type_category
 cache_entity_node
 cache_entity_og_membership
 cache_entity_og_membership_type
 cache_entity_registration
 cache_entity_registration_state
 cache_entity_registration_type
 cache_entity_taxonomy_term
 cache_entity_taxonomy_vocabulary
 cache_entity_user
 cache_field
 cache_filter
 cache_form
 cache_image
 cache_libraries
 cache_media_oembed
 cache_menu
 cache_metatag
 cache_page
 cache_panels
 cache_path
 cache_rules
 cache_token
 cache_update
 cache_views
 cache_views_data
 ckeditor_input_format
 ckeditor_settings
 comment
 ctools_css_cache
 ctools_object_cache
 date_format_locale
 date_format_type
 date_formats
 facetapi
 field_config
 field_config_instance
 field_data_body
 field_data_comment_body
 field_data_field_address
 field_data_field_approving_user
 field_data_field_bio
 field_data_field_confirmation
 field_data_field_date
 field_data_field_facebook_url
 field_data_field_file_image_alt_text
 field_data_field_file_image_title_text
 field_data_field_group_logo
 field_data_field_linkedin_url
 field_data_field_location
 field_data_field_logo
 field_data_field_media
 field_data_field_membership_token
 field_data_field_message_rendered_body
 field_data_field_message_rendered_subject
 field_data_field_my_request
 field_data_field_name_first
 field_data_field_name_last
 field_data_field_number_of_attendees
 field_data_field_offsite_url
 field_data_field_og_access_default_value
 field_data_field_og_subscribe_settings
 field_data_field_organizers
 field_data_field_original_og_membership
 field_data_field_radioactivity
 field_data_field_registration
 field_data_field_registration_type
 field_data_field_related_question
 field_data_field_requesting_user
 field_data_field_response_date
 field_data_field_target_comments
 field_data_field_target_nodes
 field_data_field_target_users
 field_data_field_topics
 field_data_field_twitter_url
 field_data_group_access
 field_data_group_content_access
 field_data_group_group
 field_data_message_subscribe_email
 field_data_message_text
 field_data_og_group_ref
 field_data_og_membership_request
 field_data_og_roles_permissions
 field_data_og_user_group_ref
 field_data_og_user_node
 field_data_og_user_user
 field_data_title_field
 field_data_user_trusted_contacts
 field_revision_body
 field_revision_comment_body
 field_revision_field_address
 field_revision_field_approving_user
 field_revision_field_bio
 field_revision_field_confirmation
 field_revision_field_date
 field_revision_field_facebook_url
 field_revision_field_file_image_alt_text
 field_revision_field_file_image_title_text
 field_revision_field_group_logo
 field_revision_field_linkedin_url
 field_revision_field_location
 field_revision_field_logo
 field_revision_field_media
 field_revision_field_membership_token
 field_revision_field_message_rendered_body
 field_revision_field_message_rendered_subject
 field_revision_field_my_request
 field_revision_field_name_first
 field_revision_field_name_last
 field_revision_field_number_of_attendees
 field_revision_field_offsite_url
 field_revision_field_og_access_default_value
 field_revision_field_og_subscribe_settings
 field_revision_field_organizers
 field_revision_field_original_og_membership
 field_revision_field_radioactivity
 field_revision_field_registration
 field_revision_field_registration_type
 field_revision_field_related_question
 field_revision_field_requesting_user
 field_revision_field_response_date
 field_revision_field_target_comments
 field_revision_field_target_nodes
 field_revision_field_target_users
 field_revision_field_topics
 field_revision_field_twitter_url
 field_revision_group_access
 field_revision_group_content_access
 field_revision_group_group
 field_revision_message_subscribe_email
 field_revision_message_text
 field_revision_og_group_ref
 field_revision_og_membership_request
 field_revision_og_roles_permissions
 field_revision_og_user_group_ref
 field_revision_og_user_node
 field_revision_og_user_user
 field_revision_title_field
 field_revision_user_trusted_contacts
 file_display
 file_managed
 file_metadata
 file_type
 file_usage
 filter
 filter_format
 flag_content
 flag_counts
 flag_types
 flags
 flood
 history
 image_effects
 image_styles
 media_oembed_provider
 menu_custom
 menu_links
 menu_router
 message
 message_type
 message_type_category
 metatag
 metatag_config
 node
 node_access
 node_comment_statistics
 node_revision
 node_type
 og_membership
 og_membership_type
 og_role
 og_role_permission
 og_users_roles
 page_manager_handlers
 page_manager_pages
 page_manager_weights
  panelizer_defaults
  panelizer_entity
  panels_display
  panels_layout
  panels_pane
  panels_renderer_pipeline
  pm_disable
  pm_index
  pm_message
  poll
  poll_choice
  poll_vote
  queue
  quicktabs
  radioactivity_decay_profile
  radioactivity_deferred_incidents
  radioactivity_flood_map
  radioactivity_history
  rate_bot_agent
  rate_bot_ip
  rdf_mapping
  realname
  redirect
  registration
  registration_entity
  registration_state
  registration_type
  registry
  registry_file
  role
  role_permission
  rules_config
  rules_dependencies
 rules_tags
 rules_trigger
 search_dataset
 search_index
 search_node_links
 search_total
 semaphore
 sequences
 sessions
 shortcut_set
 shortcut_set_users
 system
 taxonomy_index
 taxonomy_term_data
 taxonomy_term_hierarchy
 taxonomy_vocabulary
 url_alias
 users
 users_roles
 variable
 views_display
 views_view
 votingapi_cache
 votingapi_vote
 watchdog
 Calling system(mysqldump --defaults-extra-file=/tmp/drush_QUVbLn  drupal --host=localhost --result-file
 /home/user/drush-backups/drupal/20140802092251/drupal_20140802_092252.sql --no-autocommit --single-transaction --opt -Q  && gzip -f
 /home/user/drush-backups/drupal/20140802092251/drupal_20140802_092252.sql);
 Database dump saved to                                                          [success]
 /home/user/drush-backups/drupal/20140802092251/drupal_20140802_092252.sql.gz
 [5.85 sec, 14.83 MB]
  Returned from hook drush_sql_dump [5.85 sec, 14.83 MB]                       [debug]
  Command dispatch complete [5.85 sec, 14.79 MB]                                [notice]
  Timer  Cum (sec)  Count  Avg (msec)
  page   0.637       1       637.04
 Peak memory usage was 15.17 MB [5.85 sec, 14.99 MB]                          [memory]
 Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
 [5.85 sec, 15.01 MB]
 Starting to discover temporary files directory on Destination. [5.87 [ok]
 sec, 11.77 MB]
 Backend invoke: ssh -o PasswordAuthentication=yes root@eso-meetu.de     [command]
 'drush  --backend=2 --verbose --debug --uri=www.eso-meetu.de
 --root=/var/www/virtual/eso-meetu.de/htdocs  php-eval '\''return
 drush_find_tmp();'\'' 2>&1' 2>&1 [6.04 sec, 11.78 MB]
 ssh -o PasswordAuthentication=yes root@eso-meetu.de 'drush                 [notice]
 --backend=2 --verbose --debug --uri=www.eso-meetu.de
 --root=/var/www/virtual/eso-meetu.de/htdocs  php-eval '\''return
 drush_find_tmp();'\'' 2>&1' 2>&1 [6.04 sec, 11.79 MB]
 root@eso-meetu.de's password:
 Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
 [15.38 sec, 11.84 MB]
 Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
 [15.39 sec, 11.84 MB]
 Backend invoke: /usr/bin/php  -d magic_quotes_gpc=Off -d                  [command]
 magic_quotes_runtime=Off -d magic_quotes_sybase=Off
 /home/user/.composer/vendor/drush/drush/drush.php --php=/usr/bin/php
 --php-options=' -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off
 -d magic_quotes_sybase=Off'  --backend=2 --yes --verbose --debug
 --root=/var/www --uri=http://default  core-rsync
 '@self:/home/user/drush-backups/drupal/20140802092251/drupal_20140802_092252.sql.gz'
 '@self:/tmp/drupal_20140802_092252.sql.gz'   --remove-source-files
 2>&1 [15.54 sec, 11.85 MB]
 /usr/bin/php  -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off -d     [notice]
 magic_quotes_sybase=Off
 /home/user/.composer/vendor/drush/drush/drush.php --php=/usr/bin/php
 --php-options=' -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off
 -d magic_quotes_sybase=Off'  --backend=2 --yes --verbose --debug
 --root=/var/www --uri=http://default  core-rsync
 '@self:/home/user/drush-backups/drupal/20140802092251/drupal_20140802_092252.sql.gz'
 '@self:/tmp/drupal_20140802_092252.sql.gz'   --remove-source-files
 2>&1 [15.54 sec, 11.86 MB]
 Bootstrap to phase 0. [15.57 sec, 4.35 MB]                                 [bootstrap]
 Drush bootstrap phase : _drush_bootstrap_drush() [15.57 sec, 4.36 MB][bootstrap]
 Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
 [15.57 sec, 4.45 MB]
 Cache HIT cid:                                                                         [debug]
 7.0-dev-commandfiles-0-d59e04c348899678368fc648b2c8da2b [15.58 sec,
 4.47 MB]
 Bootstrap to phase 0. [15.69 sec, 11.36 MB]                                [bootstrap]
 Bootstrap to phase 0. [15.72 sec, 11.36 MB]                                [bootstrap]
 Found command: core-rsync (commandfile=core) [15.72 sec, 11.36 MB]   [bootstrap]
 Including                                                                           [bootstrap]
 /home/user/.composer/vendor/drush/drush/commands/core/rsync.core.inc
 [15.81 sec, 11.38 MB]
 Calling hook drush_core_rsync [15.82 sec, 11.48 MB]                           [debug]
 Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
 [15.82 sec, 11.5 MB]
 Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
 [15.82 sec, 11.5 MB]
  Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
  [15.82 sec, 11.5 MB]
 Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
 [15.91 sec, 11.51 MB]
 Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
 [15.92 sec, 11.51 MB]
 You will destroy data from /tmp/drupal_20140802_092252.sql.gz and replace with data from /home/user/drush-backups/drupal/20140802092251/drupal_20140802_092252.sql.gz
 Do you really want to continue? (y/n): y
  Calling system(rsync -e 'ssh ' -akzv --exclude=".git" --exclude=".gitignore" --exclude=".hg" --exclude=".hgignore" --exclude=".hgrags" --exclude=".bzr"
  --exclude=".bzrignore" --exclude=".bzrtags" --exclude=".svn" --stats --progress --remove-source-files
 /home/user/drush-backups/drupal/20140802092251/drupal_20140802_092252.sql.gz /tmp/drupal_20140802_092252.sql.gz);
 sending incremental file list
 drupal_20140802_092252.sql.gz
   925847 100%  106.46MB/s     0:00:00 (xfer#1, to-check=0/1)

 Number of files: 1
 Number of files transferred: 1
 Total file size: 925847 bytes
 Total transferred file size: 925847 bytes
 Literal data: 925847 bytes
 Matched data: 0 bytes
 File list size: 58
 File list generation time: 0.001 seconds
 File list transfer time: 0.000 seconds
 Total bytes sent: 926266
 Total bytes received: 31

 sent 926266 bytes  received 31 bytes  617531.33 bytes/sec
 total size is 925847  speedup is 1.00
 Returned from hook drush_core_rsync [16.08 sec, 11.66 MB]                    [debug]
 Command dispatch complete [16.08 sec, 11.61 MB]                               [notice]
 Peak memory usage was 14.92 MB [16.08 sec, 11.6 MB]                          [memory]
 Cache MISS cid: 7.0-dev-alias-path--8bf32223596c4e7624f626b4fa56d306      [debug]
 [16.08 sec, 11.6 MB]
 Copying dump file from Source to Destination. [16.12 sec, 11.86 MB]  [ok]
 Starting to import dump file onto Destination database. [16.12 sec,  [ok]
 11.86 MB]
 Backend invoke: ssh -o PasswordAuthentication=yes root@eso-meetu.de     [command]
 'drush  --backend=2 --verbose --debug --strict=0
 --uri=www.eso-meetu.de --root=/var/www/virtual/eso-meetu.de/htdocs
 sql-query   --file=/tmp/drupal_20140802_092252.sql.gz --file-delete
 2>&1' 2>&1 [16.3 sec, 11.88 MB]
 ssh -o PasswordAuthentication=yes root@eso-meetu.de 'drush                 [notice]
 --backend=2 --verbose --debug --strict=0 --uri=www.eso-meetu.de
 --root=/var/www/virtual/eso-meetu.de/htdocs  sql-query
 --file=/tmp/drupal_20140802_092252.sql.gz --file-delete 2>&1' 2>&1
 [16.3 sec, 11.89 MB]
 root@eso-meetu.de's password:
 Starting Drush preflight. [17.63 sec, 1.99 MB]                            [preflight]
 Cache MISS cid: 7.0-dev-alias-path--55ad758669c686ea540e62d1ca109d5b      [debug]
 [17.63 sec, 2.04 MB]
 Cache HIT cid:                                                                         [debug]
 7.0-dev-commandfiles-0-087331b5bed7344fe80ba1b1fea51261 [17.64 sec,
 2.06 MB]
 Bootstrap to phase 0. [17.7 sec, 5.65 MB]                                   [bootstrap]
 Bootstrap to phase 0. [17.74 sec, 5.66 MB]                                 [bootstrap]
 Found command: sql-query (commandfile=sql) [17.74 sec, 5.66 MB]       [bootstrap]
 Calling hook drush_sql_query [17.81 sec, 5.7 MB]                               [debug]
 Drush bootstrap phase : _drush_bootstrap_drupal_root() [17.81 sec,   [bootstrap]
 5.7 MB]
 Initialized Drupal 7.30 root directory at                                      [notice]
 /var/www/virtual/eso-meetu.de/htdocs [17.83 sec, 6.64 MB]
 Cache HIT cid:                                                                         [debug]
 7.0-dev-commandfiles-1-1b1f76beae8b3fa873220937ec1d95e2 [17.83 sec,
 6.64 MB]
 Drush bootstrap phase : _drush_bootstrap_drupal_site() [17.83 sec,   [bootstrap]
 6.64 MB]
 Initialized Drupal site www.eso-meetu.de at sites/default [17.83 sec,   [notice]
 6.65 MB]
 Cache HIT cid:                                                                         [debug]
 7.0-dev-install_profile-66ecfeb9791a023150773849f1550c5d [17.83 sec,
 6.65 MB]
 Cache HIT cid:                                                                         [debug]
 7.0-dev-commandfiles-2-f1f919de142adb82dd89194b63606c3b [17.83 sec,
 6.66 MB]
 Drush bootstrap phase : _drush_bootstrap_drupal_configuration()       [bootstrap]
 [17.84 sec, 7.4 MB]

finfo::file(/tmp/drupal_20140802_092252.sql.gz): failed to open           [warning]
 stream: No such file or directory drush.inc:842 [17.84 sec, 7.52 MB]
 Examining /tmp/drupal_20140802_092252.sql.gz headers. [17.84 sec,         [debug]
 7.52 MB]
 fopen(/tmp/drupal_20140802_092252.sql.gz): failed to open stream: No      [warning]
 such file or directory drush.inc:854 [17.84 sec, 7.52 MB]
 Unable to open /tmp/drupal_20140802_092252.sql.gz. [17.84 sec, 7.52       [warning]
 MB]
 Examining /tmp/drupal_20140802_092252.sql.gz extension. [17.84 sec,       [debug]
 7.52 MB]
 Unable to determine mime type for drupal_20140802_092252.sql.gz.          [error]
 [19.05 sec, 11.96 MB]
 Executing: mysql --defaults-extra-file=/tmp/drush_Ba0Nob --database=meetu_original --host=localhost --silent  < /tmp/drupal_20140802_092252.sql.gz
 sh: 1: Query failed. [19.08 sec, 11.97 MB]                                   [error]
 Returned from hook drush_sql_query [17.85 sec, 7.52 MB]                      [debug]
 Command dispatch complete [17.85 sec, 7.5 MB]                                [notice]
 Peak memory usage was 7.78 MB [17.85 sec, 7.61 MB]                           [memory]
 Cache MISS cid: 7.0-dev-alias-path--55ad758669c686ea540e62d1ca109d5b         [debug]
 [17.85 sec, 7.62 MB]
 cannot open /tmp/drupal_20140802_092252.sql.gz: No such file
  Timer  Cum (sec)  Count  Avg (msec)
  page   0.006       1       5.99
 Returned from hook drush_sql_sync [19.09 sec, 11.89 MB]                      [debug]
 Command dispatch complete [19.09 sec, 11.84 MB]                               [notice]
 Peak memory usage was 15.4 MB [19.09 sec, 11.83 MB]                          [memory]
 user@drupal:~/html$

```

# Answer
> 1 votes
From your error log its almost clear that the SQL dump file which was created in local server didn't moved to the remote production server. So this error `finfo::file(/tmp/drupal_20140801_224144.sql.gz): failed to open` happened. Have a good look at your alias file and see if you want to add some SSH validations in the server. Generally remote servers do need this setup. For further information look at this link 'drush rsync' not excluding paths specified in 'exclude-paths' in "aliases.drushrc.php". Also try to debug with verbose mode with `drush -v -d sql-sync @oldsite @newsite`.

Let me know if you have any further issues in this.

---
Tags: drush
---


# Question
Title: How to determine taxonomy vocabularies related to a specific content type in Drupal 8?
could anyone help me please, how to get the vocabularies to a given content type? For example in older Drupal cores there was a taxonomy\_get\_vocabuleries($type) function(https://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy.module/function/taxonomy\_get\_vocabularies/6), but I didn't find anythink similar solution in D8.

Thanks a lot!

# Answer
> 0 votes
In Drupal 6, this was configured per vocabulary, which had settings for which node type they should be displayed.

Since Drupal 7 already, this is handled through fields, a term reference field from a node type to a given vocabulary. The UI doesn't allow it, but a term reference field can also allow terms of multiple vocabularies.

So, if you want to know, you need to load term reference fields of that node type and then filter them by their allowed values setting. That said, the concept of "vocabulary of a given node type" simply doesn't really exist anymore, as there are other ways too, you can for example use an generic entity reference field too for term relationships. (In fact, there was an attempt to replace the term reference field completely in 8.x, but that was not successful so far).

Untested, but you need something like this:

```
$vids = array();
foreach (\Drupal::entityManager()->getFieldDefinitions('node', $node_type) as $field_definition) {
  if ($field_definition->getType() == 'taxonomy_term_reference') {
    foreach ($field_definition->getSetting('allowed_values') as $allowed_values) {
      $vids[] = $allowed_values['vocabulary'];
    }
  }
}

```

You can figure out most of this if you look at TaxonomyTermReferenceItem and how it is defining and using it's own settings, for example in `getSettableOptions()`.

---
Tags: taxonomy-terms, 8
---


title: $node object not populating with data

text:
# Question
Title: $node object not populating with data
I'm using the Rules module to execute custom PHP script whenever a new node is saved after importing via Feeds module.

```
<?php

$lid = db_insert('location')->fields(array(
    'additional' => $node->field-address, //saves as '0'
    'city' => $node->field-locality, // saves '0'
    'province' => $prov, // //saves correctly
    'country' => 'xx', //saves 'xx' correctly
    'latitude' => $node->field-latitude-temp, //saves as 0.00000
    'longitude' => $node->field-longitude-temp, //same
    'source' => 1,
    'is_primary' => 0
))->execute();

```

This is the location table (from the Location module) and I'm importing data from a csv file.

All the other constant values are saved properly except for when it is coming from the $node object. Lat and Lon goes 0.00000 while all the other string values such as city and address also goes 0.

Been dealing with this for hours.

EDIT: I'm using Feeds module. But I need to import also location data. While a row is getting committed to db, the values are all 0!

node:field-latitude-temp shows the actual imported value correctly when viewing the node. But it is not getting absorbed in within the PHP Execute custom code page in Rules.

# Answer
> 1 votes
I am not sure this can help you, but I don't think `$node->field-address` or `$node->field-longitude-temp` are valid syntax by `$node` object, you should use `$node->field_address['und'][0]['value']` or with `entity_metadata_wrapper` function, eg:

```
$nodeWrapper = entity_metadata_wrapper('node', $node);
$nodeWrapper->field_address->value()

```

---
Tags: 7, rules, feeds, location
---


# Question
Title: Views keeps crashing when I change setting
I have created a Latest News view which I'm displaying in my sidebar as a block. When I then go back to change anything such as the Title of the View or the number of items that can be displayed, it crashes. can anyone help? I have attached a screen print which shows the error.

# Answer
It is jquery version issue. Views is not crashing, It is returning `json` response which Drupal is not handling properly due to jquery version issue. If you are using jquery\_update module. Change the jquery version to 1.5 or older. If not; use this module. Latest jquery\_update module allow you to set different jquery version for administrator pages and actual site nodes. Set the jquery version 1.5 or older for administrator pages and higher for actual site nodes if needed.
> 4 votes

---
Tags: views
---


title: Pop Up login Forms for LoginToBoggan

text:
# Question
Title: Pop Up login Forms for LoginToBoggan
I am using **LoginToBoggan Module** to unable anonymous user to register using self created password.

Now in some other page I want a **popup login form**. I have tried using other module like modal forms, but these seems not to work.

Please show me the right way to do this.

Thank you

# Answer
Try Popup forms or Colorbox modules. These provide this functionality.
> 1 votes

---
Tags: forms, users, javascript, authentication-authorization
---


# Question
Title: How to set the front page with Mobile Switch
I am using Mobile Switch to switch to my mobile theme when viewed on a mobile device. However, I don't see any way of setting redirect to a custom front page. How can I do this?

# Answer
Have you tried Context Mobile Switch in comination with Context? And if you want to implement a small custom module then you can add the global $conf variable and inspect it for which property to switch on.
> 1 votes

---
Tags: theming
---


# Question
Title: How to show album title for 'album with no photos' in view
I am using node gallery module to create albums and upload photos. I have created a view to create albums and upload photos.It is working fine.But when i create album with no photos, album title is not getting displayed.I want to show 'default image and title of the album' for 'albums with no photos'.I have specified 'title and default image' in 'content:photo' no result behaviour in my view and Only the node author can see this but other users are not able to view this album. How to do this?

# Answer
> 0 votes
You also seem to have a permission issue. Maybe some of your nodes aren't published. Check that first. If you are unsure set your views'Query settings' to 'Disable SQL rewriting' and see if it works. If it does then it is definitely a permission issue which you need to track down. It is not advisable unless you are doing it by design to leave Disable SQL rewriting on. And if you are using the file entity then also check the permission there.

# Answer
> 0 votes
One of two ways:

1) Create a Header. Under Header (middle of page) create a Global Text. This will create a title for the View regardless of it's contents

2) Under Advanced, create a NO RESULTS BEHAVIOUR. This functions on the view as a whole, so that if there is not content to display at all, this will be displayed

---
Tags: views, media
---


# Question
Title: tableselect showing empty message instead of options
I'm trying to populate a tableselect on a form of a custom module. The tableselect is actually visible, but it's displaying the `#empty` message. I've simplified it to this code:

```
$form['my_module_overview'] = array(
    '#type' => 'tableselect',
    '#header' => array('parent' => t('Parent'), 'child' => t('Child')),
    '#options' => array(
        1 => array('parent' => 'test1', 'child' => 'test2'),
        2 => array('parent' => 'test3', 'child' => 'test4')),
    '#empty' => t('There are no relationships defined yet.'),
    '#multiple' => TRUE,
);

```

So I'm seeing the table with the correct headers, but with the message "There are no ...".

I think I'm donig it correct, as the options array contains key-value-pairs with the values being arrays again. And those arrays have the header keys as keys ('parent' and 'child').

So how can I get the data to become visible in my tableselect?

# Answer
> 0 votes
Apparently, something is/was cached because clearing the cache solved it. So there weren't any problems with the code.

---
Tags: forms
---


title: Bootstrap's css is not loading

text:
# Question
Title: Bootstrap's css is not loading
I am have a website on drupal and have enabled Bootstrap theme . The problem is *http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css* is not loading . It says "This webpage is not available" when i try to load

*http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css*

in **ubuntu** ,

But when works fine in **windows**.

I have no idea why is this happening . Plz help.

# Answer
Add this to your template.php

`function MYTHEME_framework_page_build(&$vars) {
 // Add bootstrap cdn.
 drupal_add_css('http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css ', array('type' => 'external'));
}`

where MYTHEME should be replaced with the name of your theme in your MYTHEME.info.

Save the file on your server

clear all chaes and reload the page.

now this should be fixred
> 1 votes

---
Tags: theming
---


# Question
Title: How to print add/remove link for user relationships module?
I want to print Add/Remove friend link fro user relationship module on user profile page. I am trying this using below code but its causing white screen.

```
//add link
global $user;
$account = user_load(arg(1));
$actions = _user_relationships_ui_actions_between($user, $account);
if (count($actions)) {
  print theme('item_list', $actions);
}

```

Please help me.

# Answer
> 0 votes
Install Devel module and add dpm statements in a progressive fashion. For instance: After you load the account, add : dmp (arg(1)) (and no other statements following). Inspect the dpm output for correctness and go onto the next statement, ie. dpm($account(arg(1)) and so forth.

---
Tags: users
---


# Question
Title: Combine two or more filter criteria in views
I want to combine two or more filter criteria to a dropdown in views filter criteria. so that i can select a filter criteria in the dropdown box and can search with a string in a text box. so that the result will be similar to the string from the filter criteria which is selected from the dropdown listbox(combination of filter criterias).

Is there any way to combine the filter criteria as dropdown...?

# Answer
> 1 votes
I Found this problem interesting and spend little time over this. Here is the solution i come with.

1. Create a view with title and Body field.
2. Add two filters `Content:Title` and `Content:Body` with `Contains` operator, expose these two filters.
3. Create a custom module with the following hooks.

```
//custom.module
function custom_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {

if ($form_id == 'views_exposed_form' && $form_state['view']->name == 'VIEW_NAME') {

    // Unset the title and body filter info so that it doesn't print any label.
    unset($form['#info']['filter-title']);
    unset($form['#info']['filter-body_value']);
    // Unset the title and body filter
    unset($form['title']);
    unset($form['body_value']);

    $form_element = array();
    $options = array(
    // '' => '-Select-',
      'title' => 'Title',
      'body' => 'Body',
    );
    $form_element['search_within'] = array(
      '#type' => 'select',
      '#title' => t('Search within'),
      '#options' => $options,
      '#default_value' => !empty($form_state['search_within']) ? $form_state['search_within'] : '',
      '#description' => t('Set the <em>Title</em> or <em>Body</em> within which you want to search.'),
      '#prefix' => '<div class="views-exposed-widget">',
      '#suffix' => '</div>',
    );
    $form_element['search_box'] = array(
      '#type' => 'textfield',
      '#title' => t('Search term'),
      '#default_value' => !empty($form_state['search_box']) ? $form_state['search_box'] : '',
      '#description' => t('Enter the term which you want to search.'),
      '#prefix' => '<div class="views-exposed-widget">',
      '#suffix' => '</div>',
    );
    $form = $form_element + $form;
}
}

function custom_views_query_alter(&$view, &$query) {
if ($view->name == 'VIEWS_NAME') {
    if (!empty($view->exposed_input['search_box']) && $view->exposed_input['search_within'] == 'title') {
    // Add title filter condition if title is selected
        $query->where[1]['conditions'][] = array(
          'field' => 'node.title',
          'value' => '%' . $view->exposed_input['search_box'] . '%',
          'operator' => 'LIKE',
          );
    }
    if (!empty($view->exposed_input['search_box']) && $view->exposed_input['search_within'] == 'body') {
    // Create join with fiedl_data_body table.
    // source:
    // https://api.drupal.org/api/views/includes!handlers.inc/function/views_join%3a%3aconstruct/
    // https://www.drupal.org/node/2049051#comment-7784967
        $join = new views_join;
        $extra = array();
        $extra[] = array(
          'table' => 'field_data_body',
          'field' => 'entity_type',
          'value' => 'node',
          'operator' => '=',
          );
        $extra[] = array(
          'table' => 'field_data_body',
          'field' => 'deleted',
          'value' => '0',
          'operator' => '=',
          );
        $join->construct('field_data_body', 'node', 'nid', 'entity_id', $extra);
    // Add join to query; 'node' is the left table name
        $view->query->add_relationship('field_data_body',$join,'node');
    // Add fields from table (or where clause, or whatever)
        $view->query->add_field('field_data_body','entity_id');
    // Add body filter condition if body is selected
        $query->where[1]['conditions'][] = array(
          'field' => 'field_data_body.body_value',
          'value' => '%' . $view->exposed_input['search_box'] . '%',
          'operator' => 'LIKE',
          );
    }
}
}

```

**Note:** This solution will only work with `Contains` operator and very case specific. It would be great if somebody will create a generic views filter handler to combine exposed filter as select list and allow search within selected filter.

# Answer
> 0 votes
You may need the Better Exposed Filters module for this.

Make sure the fields that you want to filter through are in your fields area, even if they are not visible. Add a new filter criteria. You are looking for the one named Global: Combine fields filter. From here you can choose two of the fields that you have added to the Fields area. Set your operator to contains and make sure it is exposed.

---
Tags: nodes, views
---


title: Autopost using checkbox

text:
# Question
Title: Autopost using checkbox
I have used facebook autopost module using rules but what I would like is a little checkbox saying: publish to facebook on the node edit page. Does anyone know a module that could help me achieve this? Thanks !

# Answer
> 0 votes
Here is how I made this work.

Added a simple Boolean to the node type called field\_post\_to\_facebook. In the rule, added a condition of Data Value is Empty. The Data Selector will be node:field-post-to-facebook. Choose negate to make sure that it reacts when the checkbox is selected.

I hope this helps.

---
Tags: nodes, social-network
---


# Question
Title: Drupal Commerce: Create advanced add to cart form block in views
With Drupal Commerce product variations, certain values will update without a page refresh based on an attribute selection. For example, changing a color attribute may update the product image.

I want to the display the add to cart form in a views block using the method described in the following video https://drupalcommerce.org/questions/10801/display-add-cart-separate-block . At the same time I would also like to include other product fields in the block, such as price.

I am finding that the block is static and does not update based on an attribute selection. And I have tried enabling Ajax for the block without success.

Is is possible to create a dynamically updating views block to replicate some of the functionality of a commerce product display?

# Answer
> 1 votes
Ajax on the block only works for the views pager and the table sorting. You have to simulate that behaviour by triggering the ajax call when an attribute is selected.

Alternatively try with Ajax Block, Block Refresh, or Authcache Blocks, and see how they trigger the Ajax load on page load, and do the same on attribute selection.

---
Tags: commerce
---


# Question
Title: How to prevent users from being registered when their username contains a space?
I'm trying to prevent a user from being saved with Rules when he/she tries to use a username that contains a whitespace. I've already read How can I disallow spaces in usernames? and used the User restrictions module to achieve this, but I'd like to use Rules to do some other stuff (e.g. checking that the username doesn't have more than 20 characters).

So, what I'd like to do is showing an error message on the page and keep all the filled in information in the form without saving it. Is it possible to do this?

This is the Rule I'm currently using:

* **Event:** Before saving a user account.
* **Conditions:** NOT Execute custom PHP code. `<?php preg_match('/\s/',$account->name) == 1; ?>`
* **Actions:** Show a message on the site.

# Answer
> 5 votes
@Jeroen, Then I would suggest to do just one custom form alter to the user registration form and add a validation function that will validate each case for you.

```
/**
 * Implements hook_form_FORM_ID_alter().
 */
// Alter the registration form
function CUSTOM_MODULE_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  // Add your own function to the array of validation callbacks
  $form['#validate'][] = 'CUSTOM_MODULE_user_validation';
}

/**
 * Custom function to validate the user creations.
 */
function CUSTOM_MODULE_user_validation(&$form, &$form_state) {
  $name = $form_state['values']['name'];
  if (preg_match('/\s/',$name)) {
     form_set_error('name', t('Name should not contain white spaces.'));
  }
}

```

Its easier to use and doesn't invoke rules API every time. I also think this is much effective for performance.

# Answer
> 0 votes
I don't think using Rules for form validation is the right way to go. It is too messy and complicated.

I will rather do a form alter on the registration form and add my own custom validation handler.

Or try using Field Validation module. I have never used it on user fields before, but I don't see why it won't work.

---
Tags: 7, rules, users
---


# Question
Title: one view show nodes and their referenced nodes - both only published
I have 2 content types. Question and Answer. Answers hava a entity reference field and contain reference to certain questions. Now, I want to build a view with listing of questions and number of answers to each question.

So, my view has one field title. Another field title with set up relationship (to show related answers). Filter is set up to show only published nodes and node types of Question and Answer. Query setings - distinct.

Result: I get all questions with all answers. Like this:
Q1 (published)
-someanswer1 (published)
-someanswer2 (unpublished)
Q2 (published)
-someanswer3 (unpublished)
-someanswer4 (unpublished)

Problem: Only Questions get filtered by using filter - published nodes. The referenced nodes - answers are not filtered and are shown all published as well as unpublished.
What would be the best approach to show ONLY published both answers and questions? Thank you

# Answer
> 0 votes
While there might be other approaches, I'd go with Views Field View.

It allows you to use a view as a field in another view. Then just build a view for the answers, taking a nid argument as an entity reference contextual filter. And use that view as field in your question listing view.

# Answer
> 0 votes
When you create a node view by default it adds the 'Content: Published (Yes)' Filter Criteria. You must now add a second 'Content: Published (Yes)' filter criteria and set the relationship on it to Answers. And be careful with how you add the relationship initially to bring in the Answer table. If you set it as required then Questions with no published Answers will not be shown.

# Answer
> 0 votes
After some hours struggling I decided to use entity reference count module. I did not use it from start, because I was not aware that it has option to count only published nodes - which is exactly what I want. Besides it is better performance-wise.

---
Tags: 7, views
---


title: IMCE with Amazon S3

text:
# Question
Title: IMCE with Amazon S3
I'm having an issue configuring IMCE to rely on the Amazon S3 bucket pointed to by the AmazonS3 module: https://www.drupal.org/project/amazons3. I have successfully configured image fields to use the S3 bucket location, but the IMCE file browsing window appears blank after being clicked on from within the ckeditor window and when file browsing is enabled for image fields.

Has anyone successfully hooked this up, and if so, could you either direct me to or write detailed, step-by-step instructions for accomplishing this?

Thanks in advance!

# Answer
Use AmazonS3 7.x-1.x-dev version. It contains a fix for IMCE compatibility. https://www.drupal.org/node/2204401
> 2 votes

---
Tags: files, wysiwyg
---


# Question
Title: Use AJAX on a form with multiple buttons
I have a form that has two text areas and three buttons, "Copy", "Reverse" and "Clear". I would like the buttons to, respectively, copy the text from one text area to the other, take the text from the first area and place the reverse of it in the other, and clear both text areas using AJAX.

I know how to do these functions in PHP but I can't seem to get the AJAX to work at all. Here is my existing code, any help would be appreciated:

```
<?php

    function produce_form() {
    $form['input'] = array(
        '#type' => 'textarea',
        '#title' => t('Input text'),
        '#prefix' => '<div id="in-text">',
        '#value' => '',
        '#attributes' => array(
            'placeholder' => t('Enter some text here... '),
        ),
        '#suffix' => '</div>',
    );

    $form['buttons'] = array(
        '#type' => 'fieldset',
        '#title_display' => 'invisible',
        '#attributes' => array(
            'style' => 'border: 0px; text-align: right',
            'class' => array('container-inline'),
        ),
    );

    $form['buttons']['copy'] = array(
        '#type' => 'button',
        '#value' => 'Copy text',
        '#ajax' => array(
            'callback' => 'copy_text',
            'wrapper' => 'out-text',
//          'method' => 'replace',
//          'effect' => 'fade',
        ),
    );

    $form['buttons']['reverse'] = array(
        '#type' => 'button',
        '#value' => t('Reverse text'),
    );

    $form['buttons']['clear'] = array(
        '#type' => 'button',
        '#value' => t('Clear text'),
    );

    $form['output'] = array(
        '#type' => 'textarea',
        '#title' => t('Output text:'),
        '#prefix' => '<div id="out-text">',
        '#value' => '',
        '#attributes' => array(
            'placeholder' => t('Your text will appear here...'),
        ),
        '#suffix' => '</div>',
    );

    return $form;
    }
    print render(produce_form());

    function copy_text($form, &$form_state){
        $form['output']['#value'] = $form_state['values']['input'];
        return $return['output'];
    }
?>

```

# Answer
> 0 votes
Just two problem with your form:

1. Remove #value element from 'input' element
2. replace return $return\['output'\]; with return $form\['output'\];

The problem with #value is that the element gets re-initialised on form render.

Here is the working version(copy button) of your code:

```
<?php

function playground_menu() {
  $items['playground/form'] = array(
    'title' => 'Form',
    'description' => '',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('playground_demo_form'),
    'access arguments' => array('access content'),
  );
  return $items;
}

function playground_demo_form($form, $form_state) {

  $form['input'] = array(
    '#type' => 'textarea',
    '#title' => t('Input text'),
    '#prefix' => '<div id="in-text">',
    '#attributes' => array(
      'placeholder' => t('Enter some text here... '),
    ),
    '#suffix' => '</div>',
  );

  $form['buttons'] = array(
    '#type' => 'fieldset',
    '#title_display' => 'invisible',
    '#attributes' => array(
      'style' => 'border: 0px; text-align: right',
      'class' => array('container-inline'),
    ),
  );

  $form['buttons']['copy'] = array(
    '#type' => 'button',
    '#value' => 'Copy text',
    '#ajax' => array(
      'callback' => 'copy_text',
      'wrapper' => 'out-text',
//          'method' => 'replace',
//          'effect' => 'fade',
    ),
  );

  $form['buttons']['reverse'] = array(
    '#type' => 'button',
    '#value' => t('Reverse text'),
  );

  $form['buttons']['clear'] = array(
    '#type' => 'button',
    '#value' => t('Clear text'),
  );

  $form['output'] = array(
    '#type' => 'textarea',
    '#title' => t('Output text:'),
    '#prefix' => '<div id="out-text">',
    '#value' => '',
    '#attributes' => array(
      'placeholder' => t('Your text will appear here...'),
    ),
    '#suffix' => '</div>',
  );

  return $form;
}

function copy_text($form, $form_state){
  $form['output']['#value'] = $form_state['values']['input'];
  return $form['output'];
}

```

---
Tags: 7, forms, ajax
---


# Question
Title: Multiple filed handlers in Views for a field
How do I set multiple field handlers in Views on a single field.

I've applied the patch Relationship & sort for {history} to Views which brings in the user relationship on the history table. I then replaced the Views field handler for \['history'\]\['timestamp'\] in node.views.inc with this:

```
  $data['history']['timestamp'] = array(
    'title' => t('Node last access timestamp'),
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
      'help' => t('Show the timestamp a node was last accessed by user.'),
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
      'help' => t('Sort by the node last access time.'),
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_date',
      'help' => t('Filter by the node last access time.'),
    ),
  );

```

because I need the timestamp as a date field. Normally it is this:

```
$data['history']['timestamp'] = array(
    'title' => t('Has new content'),
    'field' => array(
      'handler' => 'views_handler_field_history_user_timestamp',
      'help' => t('Show a marker if the content is new or updated.'),
    ),
    'filter' => array(
      'help' => t('Show only content that is new or updated.'),
      'handler' => 'views_handler_filter_history_user_timestamp',
    ),
  );

```

But ideally I would like to have both field handlers available because I do not want to remove the default handler in Views. How do I do this?

# Answer
> 0 votes
You don't. That's not possible.

But you still have options:

1. Define your own field handler and add support for multiple display formats using configuration options, have a look at this snippet for an example: https://gist.github.com/juampy72/5816530. The key methods to implement this are `option_definition`, `options_form`, `options_submit` and `render`.
2. This is more of a work-around. Copy the definition of the first field handler under different database column key, e.g. `$data['history']['timestamp_as_date'] = array( ...`. Then implement your own filter class as before, but also override the query method in order to ensure that the timestamp column is present. Then display that as you like.

There are a lot of code examples out there.

---
Tags: views, entities
---


# Question
Title: Is there a way i can import users having profile2 with feeds
I have done user migration using feeds. but i am not able to migrate the profile2 fields with it. Is there a way? am I missing something. I am trying to use migrate module but its tricky. Any help is welcomed.

# Answer
There's a module called Feeds Profile2 which extends the built-in User processor so that Profile2 profiles can be created and updated as part of a user importer.
> 1 votes

---
Tags: feeds, users, migrations
---


# Question
Title: Sending notifications to users from other users dependent on certain conditions
Is there a way to alert users of the content in a node field? I'm trying to get users to be able to mass message other users based on certain taxonomy terms they're selecting as part of their login process.

So essentially the process (as I'm envisioning it, but I'm open to other methods) would work like this:

User1 selects a county as part of their profile creation.

User2 wants to send an alert to all users that are signed up to that county.

They create a node with the content type, "Alert", which consists of the title, the actual alert information (a text field), and a county.

This is then sent to all users (i.e. user1) with that county.

My guess would be to use the notification and messages modules, and have a user subscribe to a given taxonomy term(s). I'm only seeing how to send messages on content update/creation though, not the actual content of the node.

Are there any solutions for this problem (one to many communication between users dependent on certain criteria)

# Answer
> 0 votes
I put a hierarchical taxonomy term in a user profile, and then had rules send to any user with that county selected.

---
Tags: nodes, users, notifications
---


title: Extra handler breaks Datepicker field

text:
# Question
Title: Extra handler breaks Datepicker field
**Problem**

I have a form which a user can create data with and some of the fields are date fields which use jQuery datepicker.

The form is long and in order to help the user out, I have a series of help messages which appear when the relevant form input is focused.

When a form element is given focus, the form's ID is grabbed and attached as a class to the help div, which reveals the correct help message.

Example: jsfiddle \- caveat in a moment

This works in the jsfiddle, however in Drupal it breaks. On click the calender opens but rather than selecting a link it hits the local hyperlink "#" below it and changes the url to `http://mywebsite.com/form/#`

The problem appears to be related to how the Drupal date jQuery module deals with Datepicker. I've narrowed it down to something to do with `$(this).attr('id')`, it doesn't like the that selector but I'm unsure as to why.

**Full Script**

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

      var jobHelp = $('#jobhelp').children();

      $('input, select').focus(function() {
        $(jobHelp).attr('id', $(this).attr('id'));
      });
    }
  };

```

I've tried with document ready instead of Drupal behaviours and it still breaks. I've also tried getting focus to call a function (with the same code), however neither works.

# Answer
Looks like the problem is with the CSS rather than the id part. The typical id would be something like this: edit-field-date-und-0-value-datepicker-popup-0 and this id is dynamically generated and not grandee that it would stay same (i.e. you may get edit-field-date-und-0-value-datepicker-popup-1 if you have the same field twice in the same form).

You can use name instead of id. Here is the working fork of your jsfiddle with name: http://jsfiddle.net/vijaycs85/C4sh9/
> 0 votes

---
Tags: 7, javascript, datetime
---


# Question
Title: Why i get the error "Call to undefined function node_object_prepare()" while i try to add a node programmatically in Drupal 7?
i'm trying to add a node content programmatically from a custom module file. I have created the .module file and used this code as suggested:

```
$node = new stdClass(); // We create a new node object
$node->type = "page"; // Or any other content type you want
$node->title = "Your title goes jere";
$node->language = LANGUAGE_NONE; // Or any language code if Locale module is enabled.
$node->path = array('alias' => 'your node path'); // Setting a node path
node_object_prepare($node); // Set some default values.
$node->uid = 1; // Or any id you wish

// Let's add standard body field
$node->body[$node->language][0]['value'] = 'This is a body text';
$node->body[$node->language][0]['summary'] = 'Here goes a summary';
$node->body[$node->language][0]['format'] = 'filtered_html'; // If field has a format,  you need to define it. Here we define a default filtered_html format for a body field

$node = node_submit($node); // Prepare node for a submit
node_save($node); // After this call we'll get a nid

```

but when i enable the module what i get is an error saying "Call to undefined function node\_object\_prepare()"

Thanks.

# Answer
I think you will have to include `node.pages.inc` to be able to use this function from within your module:

```
module_load_include('inc', 'node', 'node.pages');

```

I just tried the using `node_object_prepare()` from a sample module without using the above code and it seems to work just fine. As @Clive mentioned is his comment you should add your code for creating a node programatically inside a module hook and not directly in your module file.

```
// create a node using 'hook_menu' in your module, this might not be the
// best hook for doing this but it should work
function <MODULE>_menu() {
  $node = new stdClass();
  $node->type = "page";
  $node->title = "Your title goes jere";
  $node->language = LANGUAGE_NONE;
  $node->path = array('alias' => 'your node path');
  node_object_prepare($node);
  // ...
}

```

Reference: Module hooks
> 1 votes

---
Tags: nodes
---


# Question
Title: Simple category with drupal commerce not showing to anonymous users
I followed this guide https://drupalcommerce.org/user-guide/setting-product-catalog and now I have a nice simple category page, but not visible to anonymous users. I tried changing the roles to marking all three options but no luck.. Any suggestions?

# Answer
> 1 votes
Here are some tips:

* Set all checkboxes in People -\> Premissions : Product-\> View any product of any type
* or If you are using any contextual filter in views configuration be sure that arguement exists in category page;

---
Tags: commerce, users
---


title: Install other modules from hook_install

text:
# Question
Title: Install other modules from hook_install
Is it possible to run command of the same functionality as drush pm-download from hook\_install or hook\_update\_n? If not, what other alternative solutions do I have to automatically download and install modules and dependencies from a custom site deployer module?

# Answer
> Is it possible to run command of the same functionality as drush pm-download from hook\_install or hook\_update\_n?

If the web server user has permissions to write to the modules folder (which is in itself a security risk), then yes, you can do that. Writing it wouldn't be trivial, of course, but you can get a lot of the necessary code from Drush.

If the web server user doesn't have permissions to write to the modules folder, then no, it's not possible.

> If not, what other alternative solutions do I have to automatically download and install modules and dependencies from a custom site deployer module?

If your web-server is properly secured, then your only option is to invoke the script (whatever form that may take) as a user with sufficient privileges.
> 0 votes

---
Tags: updating, installation
---


# Question
Title: Workbench moderation state tab not displayed
My "Authenticated User" can *not* see the tab "Publishing options" on the node/add/\[content type\] page. What I need in my workflow is the user to select the moderation state (Draft/Moderation) the node should be in, but he can't see the tab.

I have 3 moderation states: `Draft`, `In Moderation`, `Published`.

The user has the following permissions:

```
Node:
    View published content
    View own unpublished content
    View content revisions
    create [content type] content
    edit own [content type] content
    edit any [content type] content
Workbench Moderation:
    View the moderation messages on a node
    Use "My Drafts" workbench tab
    View all unpublished content
    View moderation history

```

I configured the permissions looking at https://www.drupal.org/node/1175592 and https://www.youtube.com/watch?v=8nqWLrxH\_4M \+ https://www.youtube.com/watch?v=qHYWOohhKZE

I don't know if there are other permissions that I forgot. I have already rebuilt the permissions on /admin/reports/status/rebuild, no difference.

Funny thing is that, if I assign *all permissions*

```
Moderate all content from Draft to in Moderation
Moderate all content from in Moderation to Draft
Moderate all content from in Moderation to Published

```

to the anonymous user, he still *can't* see this tab.

Any help welcome.

# Answer
> 0 votes
Ah. Again, Fooled myself - it was a simple shoot into my own foot. I had written custom PHP code in my costom theme in the function THEME\_form\_alter() to **suppress** the whole revisoning tab:

```
$form['revision_information']['#access'] = FALSE;

```

When I then installed and configured the workbench module I didn't realize that it needs exactly THIS tab.

Works as expected now. Sorry for using your time... But maybe someone else learns from my errors... Thanks for your thoughts.

---
Tags: users, workbench
---


title: How can I place blocks side by side?

text:
# Question
Title: How can I place blocks side by side?
I found a solution to my question but the problem is I don't know where to insert this code. Is there a way to input this code through the site or do I need to go into the css files to do this?

http://www.drupalgardens.com/content/place-blocks-side-side

Basically the solution is to input code in the following manner:

```
#jayblock1  {
  float: left;
  width: 280px;
}
#jayblock2  {
  width: 280px;
}
#jayblock3  {
  width: 280px;
}

```

If there is an easier way to do this that doesn't require code I'd love to know!

# Answer
> -1 votes
right, that is css code. It needs dots infront of the variables though: .jayblock1

Here is an html with that css as an example...

```
<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<style type="text/css">
  .jayblock1 {
    float: left;
    width: 280px;
    background: red;
  }
  .jayblock2 {
    float: left;
    width: 280px;
    background: blue;
  }
  .jayblock3 {
    width: 280px;
    float: left;
    background: green;
  }
  div {
    height:10em;
    padding: 0.3em;
  }
</style>
<body>
  <div class="jayblock1">
    .jayblock1
  </div>
  <div class="jayblock2">
    .jayblock2
  </div>
  <div class="jayblock3">
    .jayblock3
  </div>
</body>
</html>

```

check this for more on css floating: http://www.w3schools.com/css/css\_float.asp

# Answer
> -1 votes
Yes, you should paste this code in one of your theme's CSS files. If you have installed Firefox as browser, you should use Firebug to find the correct ID's or classes for your blocks. Also, I don't think your code will work. I think something like

```
#block-system-jayblock1,
#block-system-jayblock2,
#block-system-jayblock3 {
  float: left;
  width: 280px;
}

```

is what you're looking for.

---
Tags: blocks, theming
---


title: hiding taxonomy terms on term page

text:
# Question
Title: hiding taxonomy terms on term page
I'm struggling theming the taxonomy-term page and since i'm not really getting anywhere, i now embedded two blocks (created with views) in my taxonomy-term.tpl.php. Now, that views is showing everything the way I want it, I don't want the term page itself output its data. That's why I'm trying codes like

```
<?php hide($content); ?>

```

But that won't do the trick. How can I just show the Blocks from Views instead of the content taxonomy provides itself?

Thanks!

# Answer
> 0 votes
Use Display Suite to manage your display and show/hide fields for Taxonomy terms. You can actually display nothing. Then add the blocks in there.

Second option is alter taxonomy term page.tpl.php - a function that you need to add in template.php within your theme directory.

This is a function for templating pages for content types or terms. Second part defines page--taxonomy--term.tpl.php suggestion. It worked for me.

```
<?php
/**
* Add / modify variables before the page renders.
*/
function YOURTHEMENAME_preprocess_page(&$vars) {
// custom content type page template
  // Renders a new page template to the list of templates used if it exists
  if (isset($vars['node']->type)) {
// This code looks for any page--custom_content_type.tpl.php page
    $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
  }
    if(arg(0) == 'taxonomy' && arg(1) == 'term') {
        $tid = (int)arg(2);
        $term = taxonomy_term_load($tid);
        if(is_object($term)) {
           $vars['theme_hook_suggestions'][] = 'page__taxonomy__'.$term->vocabulary_machine_name;
        }
  }
}
?>

```

I hope it helps. A while ago, I've been looking for this solution for days!

---
Tags: theming, taxonomy-terms
---


# Question
Title: How to create a node based on views results
I'm looking for a way to accomplish the following:

Use views to select users that match a certain criteria. Create a "campaign" targeted at only those users. The campaign should ideally have all users' names/ids attached to it.

Many thanks.

# Answer
> 0 votes
I think you need 2 relationships in Views. One that targets your field that points from user to the campaing. Second, with the author, based on the first relationship. After, add as fields user names. Not really sure about your structure so that was just a supposition.

---
Tags: views
---


# Question
Title: Is it possible and reasonable to convert a complicated, heavily styled html page into an editable Drupal site page?
I already read this:

How to convert an HTML website to Drupal 7 nodes?

and this:

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

and some more.

Hello,

I have been tasked with creating an editable version of an html page that is heavily based on this template's design:

http://themeforest.net/item/zayra-bootstrap-3-retina-app-landing-page-/full\_screen\_preview/8135956

http://themeforest.net/item/zayra-bootstrap-3-retina-app-landing-page-/8135956

(not trying to advertise, just to give an idea)

I have read and learned about Drupal in the past week and have reached the point where I feel comfortable:

1. Tweaking themes.
2. Adding articles, polls and such plain content.
3. Messing around with the admin panel.

I don't understand how one would add content that is less "straight forward" to a Drupal site. Is it reasonable to do? Can it be done more easily with other CMSs (like Wordpress)? Should I tell my boss that the CMS should be used for news and articles in other areas of the site but *NOT* this specific promotional page?

From what I read I realize that I could create a rather complex view and a gazillion nodes and use that to generate an editable promotional page that looks like this template. My concern is that it may turn out unfriendly to the content professional.

I really would like to hear some expertly advice on how reasonably doable the task of creating an editable version of the promotional html page is in Drupal (that looks like the original).

# Answer
You can use drupal to develop and complexity of site including that of a complex css design. I personally work for a digital agency and every single project I have been on has been built in drupal and has been heavily design oriented. I have also built JS apps in drupal as well.

If you are looking for a theme out of the box then you probably wont find it as they are generally free and not a whole lot of design into them. If you are comfortable or willing to learn to create your own theme and template files then you most certainly can do this inside drupal.

It all depends on your level of knowledge and effort.

Here are a few heavy sites designed in drupal:

http://www.elmwoodreclaimedtimber.com/virtual-showroom (js app, but the site is also built on drupal)

http://www.servicesource.com

http://www.jedunn.com

http://www.tnvacation.com/made-in-tennessee

With drupal you have CSS, PHP, and MYSQL which means you can do anything those technologies can.

EDIT\***

Also to answer your question more specific it really depends on how much of the content will be editable. Drupal provides a more flexible GUI type layout called panels and panelyzer that provides more of what you may need. Research into Panopoly distribution as its geared more towards landing pages
> 1 votes

# Answer
When we talk about custom themes, there is nothing out of the box. As far as I understand, you need to figure out which CMS is better for your design. I am a big Drupal fan, BUT for small personal projects I'd rather use WP. For my clients' projects that don't involve a huge complexity I also use WP. On the other hand, for small projects that don't require tons of CSS, I use Drupal. It is safer and gives me better perspectives. Your one page theme could be done easily with Drupal, but it does require a bit of javascript - for that you may need to write your own modules.

Regardless design, there is a saying: **the shortest road is the road you know better**.

It isn't a matter of design, it is a matter of purpose & know-how. Choose carefully!

BUT, it really depends on your project's purpose as well. Could be a theme that you want to sell, or a presentation website for a client. That I do not know.

If someone would implement the javascript part, I'd probably code the CSS for that particular design, in Drupal or Wordpress, in one day. I'm not promoting myself, I just give you an example.

Bottom line here: if that was a presentation one-page theme for a customer, I'd use WP. If there are major structural requirement and a multi-page theme with a few projected content types, I'd use Drupal.
> 0 votes

---
Tags: nodes, theming, migrations
---


# Question
Title: Remote Entity Create with Node Reference
I am writing an Android app which is creating Drupal nodes remotely. I am creating these nodes via a straight php form. But now I need to create Nodes which are node\_references of the main node. Usually in order to do this you will need the entity ID of the main node before you can create a node reference.

Creating the second node as a reference should be easy as it is just an extra field with a reference value in it. The problem is, once the App creates the main node, I need the entity ID to be returned to the App so that the value can be used to create the other referenced node.

How do I get the entity ID back as a return value after node creation?

or... am I thinking about this all wrong :)

# Answer
> 0 votes
If you are using the entity api to create and save your entity its fairly easy:

```
// Create the node and wrap it in entity metadata wrapper
$node_create = entity_create('node', array('type' => 'my_content_type'):
$node_wrapper = entity_metadata_wrapper('node', $node_create);

$node_wrapper->title->value("My Title"); // Set the title
$node_wrapper->save(); // Node is now saved
$node_nid = $node_wrapper->getIdentifier(); // We now have the nid

// Doing the same thing here except adding the reference
$node_create2 = entity_create('node', array('type' => 'my_other_content_type'):
$node_wrapper2 = entity_metadata_wrapper('node', $node_create2);

$node_wrapper2->title->value("My referenced title");
$node_wrapper2->field_node_reference->value($node_nid);

$node_wrapper2->save();

```

---
Tags: entities
---


# Question
Title: Checked as default --> The user must confirm the account cancellation via e-mail.
How can I checked as default the value **Require e-mail confirmation to cancel account.** It is unchecked as default :(

I tried to edit user.module editing this line **'#default\_value' =\> TRUE,** but it doesn't work

```
  // Allow to send the account cancellation confirmation mail.
  $form['user_cancel_confirm'] = array(
    '#type' => 'checkbox',
    '#title' => t('Require e-mail confirmation to cancel account.'),
    '#default_value' => TRUE,
    '#description' => t('When enabled, the user must confirm the account cancellation via e-mail.'),

```

# Answer
> 1 votes
Consider never modifying core or contrib modules.

Instead, the right practice here is to use hook\_form\_alter() or `hook_form_FORM_ID_alter()` in a custom module.

So, configure a little module and put the following code in it:

```
function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
  //get your form id
  drupal_set_message("Form ID is : " . $form_id);
  switch($form_id) {
    case 'MY FORM ID':
      $form['user_cancel_confirm']['#default_value'] = 1;
      break;
    case 'OTHER FORM ID':
      //do sthing
      break;
    //...
  }
}

```

---
Tags: users
---


title: Update a menu link programmatically

text:
# Question
Title: Update a menu link programmatically
For a migration project, we had some links on the main menu stubbed out to an external site. Now I want to update the links with their actual final path. However, I can't do this beforehand, because I don't know what the node ids of the newly-created imported nodes would be.

I want to update the menu links with node ids in my import script, but I haven't found how to do that programmatically. We would like to avoid updating them manually during the final migration.

How can I do this?

# Answer
> 11 votes
I assume you know the path of the link you need to change and that's all? If so this should work for you. Note that I have put comments in place of any error/success reporting, which you can add if you want it.

It also assumes you know how to integrate this into the migration. This shows the menu link saving only. I can expand to show migrate integration although that is really a separate question.

**Note:** The paths used for menu items are drupal internal paths, not path aliases. To convert a path alias to an internal path you can use drupal\_get\_normal\_path().

```
// Variables used below. Set these to the values you need.
// The current path of the link.
$path = '';
// The menu the link is in. If you don't want to be menu specific remove the menu_name part of the SQL below.
$menu = '';
// The new path for the link.
$new_path = '';

// Get the menu link ID for the given path in the given menu.
// If you donb't know the menu it is in you can omit that part of the query.
// This also handles the case where there are multiple menu links for the same
// path.
$mlids = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu", array(':path' => $path, ':menu' => $menu))->fetchCol();
if ($mlids) {
  // Loop through the matching menu items and update them.
  foreach ($mlids as $mlid) {
    if ($menu_link = menu_link_load($mlid)) {
      // Set the new menu link data.
      $menu_link['link_path'] = $new_path;
      // Save the menu link.
      if (!menu_link_save($menu_link)) {
        // There was an error saving the link.
      }
      else {
        // The link has been saved successfully.
      }
    }
    else {
      // Menu link $mlid not found.
    }
  }
}
else {
  // No menu links were found for this $path.
}

```

---
Tags: routes
---


# Question
Title: restrict visiting user/1 path for all users except admin
I would like to add a condition that users are not able to visit admin profile using user/1 in url. (not even if url contains alias). What would be the easiest way of doing that? I do not want to install additional module just for this task. Thank you.

# Answer
In template.php of you theme:

```
function NAMEOFYOURTHEME_preprocess_page($vars) {
  if ($_GET['q'] == "user/1")
  {
    drupal_goto("ANY PAGE"); //Example <front> for the homepage
  }
}

```

Clear cache and enjoy :)

Greetings.
> 0 votes

# Answer
You can do this in page.tpl.php

```
global $user;
global $base_url;
$uid=$user->uid;
if(agr(0)=='user' && arg(1)==1)
{
if($uid!=1)
{
drupal_goto($base_url);
}
}

```

OR

```
function YOURTHEMENAME_preprocess_page($vars) {
  if ($_GET['q'] == "user/1")
  {
    $usr = user_load(arg(1));
    if(!in_array('administrator',$usr->roles) ){
         drupal_goto("ANY PAGE"); //Example <front> for the homepage
    }
  }
 }

```

Hope this will work
> 0 votes

---
Tags: 7, users
---


# Question
Title: How can I create a new field with a line break in it?
I created a few fields which always stick together with no free space at all. Then I created a new field between them which I named linebrake, chose the "long text and summary" (which is the only type where I can add html-code) and wrote `<br>` (`<p></p>` doesn't work) and now I have like 3 line breaks at once.

Is there any way to get only 1 line break?

Thanks in advance

# Answer
> 0 votes
Maybe the "p" tag doesn't work, because has been escaped and the Text format chosen is "Filtered HTML", see the "Allowed HTML tags" below to be sure that the "p" tag is allow.

Choose "Full HTML" for not escape.

Greetings.

# Answer
> 0 votes
Basically it depend on the `Text format` you choose.

`Filtered html` strips most of your tags, so it can be the issue.

You can test it by choosing `phpcode` or `Full html` in your text format dropdown. You can insert one line spacing by pressing shift+ENTER(if editor enabled) or using
.

If you still face the issue check Text Format setting in your `Configuration settings`.

Hope it will help you!

---
Tags: entities
---


# Question
Title: Fatal error: Class 'RulesI18nStringController' not found in entity.i18n.inc on line 31
My client drupal site stopped working suddenly and gave me this error `Fatal error: Class 'RulesI18nStringController' not found in entity.i18n.inc on line 31` i checked the rules module and entity module and nothing seems to be messing. I searched for a solution on the internet with no luck. I have rules 7.x-2.2 and entity 7.x-1.0-rc3 but i can't login to the site so i can't access update.php to update the rules and entity modules to the latest versions "as it may fix this problem".

So can anybody help me find solve this problem?

PS: If you need any additional information about the problem just ask about it in the comments.

Thanks in advance for you all.

# Answer
You have `$update_free_access` variable in your settings.php file. Set it to:

```
$update_free_access = TRUE;

```

You will be able to run update.php without login. Don't forget to turn it back to `FALSE` when done - if left `TRUE`, it can open your site to DoS attacks.
> 2 votes

---
Tags: 7, rules, entities
---


# Question
Title: How to change the language of inserted or updated paths to LANGUAGE_NONE using a module?
All path aliases are entered by hand. I need them to be language independent. Currently they are created/updated in the language that the user is currently using which does not make sense in case of my site.

I tried using hook\_path\_insert and hook\_path\_update but they only receive the $path by value and not by reference and changing the function to hook\_path\_update(&$path) results in an error.

How to change the language of inserted or updated paths to LANGUAGE\_NONE using a module? Alternatively, how can I force all aliases to be language independent automatically when user enters them? I don't think it is not possible; it is possible to allow them to choose the "All" language, but not force it.

# Answer
> 1 votes
If someone needs to have a multi language site, but have all URL aliases language independent (i.e. the same for all nodes and languages), the solution is to create a function:

```
mymodule_node_validate($node, $form, &$form_state) {
   $form_state['values']['language'] = LANGUAGE_NONE;
}

```

As a side effect, it also makes all nodes language independent. One possible scenario where this would be useful is:

* all nodes are created in a custom language which is also the site default language
* the administration interface is in English (this so far requires multi-language)
* the administrator users are able to use the same URL aliases as the rest of site visitors, despite the fact that they have English set while the content is in a different language (this requires the trick)

In a real multi-language scenario, URL aliases may need to be different for different languages.

# Answer
> 0 votes
This comment on drupal.org provides exactly what you were looking for.

Create a new module called `neutral_paths` and make this the content of `neutral_paths.module`:

```
<?php
/**
 * Implements hook_pathauto_alias_alter().
 *
 * Resets the language before saving the alias
*/
function neutral_paths_pathauto_alias_alter(&$alias, array &$context) {
  // Force all aliases to be saved as language neutral.
  $context['language'] = LANGUAGE_NONE;
}
?>

```

This hook is more specific than the one posted in the other answer so it will be called only when needed.

---
Tags: 7, hooks, path-aliases
---


# Question
Title: Drush was not able to start (bootstrap) the Drupal database - MySQL Access denied error
I've installed Drush 7 using Composer and working with Drupal 8 and 7 on Ubuntu 12.04 with PHP 5.4.31, mysql 5.5.38

Drush will `dl` modules and themes just fine but when I want to `en` a module then it gives me the `Drush was not able to start (bootstrap) the Drupal database.`

So upon further investigation I did this:

```
$ drush -v -d sql-cli
Starting Drush preflight. [0.02 sec, 1.15 MB]                        [preflight]
Cache HIT cid:                                                           [debug]
7.0-dev-commandfiles-0-87f720da39665f2c425de5e651f2ac4d [0.05 sec,
1.19 MB]
Bootstrap to phase 0. [0.2 sec, 3.19 MB]                             [bootstrap]
Bootstrap to phase 0. [0.28 sec, 3.19 MB]                            [bootstrap]
Found command: sql-cli (commandfile=sql) [0.28 sec, 3.19 MB]         [bootstrap]
Calling hook drush_sql_cli [0.56 sec, 3.21 MB]                           [debug]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.56 sec,    [bootstrap]
3.22 MB]
Initialized Drupal 8.0-dev root directory at                            [notice]
/home/wavesailor/My_sites/bootstrap-business [0.62 sec, 3.52 MB]
Cache HIT cid:                                                           [debug]
7.0-dev-commandfiles-1-67528d048330f8c38ed66ea20e647906 [0.62 sec,
3.52 MB]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.63 sec,    [bootstrap]
3.57 MB]
Initialized Drupal site default at sites/default [0.63 sec, 3.57 MB]    [notice]
Cache MISS cid:                                                          [debug]
7.0-dev-install_profile-66ecfeb9791a023150773849f1550c5d [0.64 sec,
3.57 MB]
Cache HIT cid:                                                           [debug]
7.0-dev-commandfiles-2-027a7d06ad1248d56c7499a21fb8d2df [0.65 sec,
3.57 MB]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [0.65[bootstrap]
sec, 3.57 MB]
Calling proc_open(mysql --defaults-extra-file=/tmp/drush_ST3u9r --database=bootstrap_business --host=127.0.0.1 --port=3306);
ERROR 1045 (28000): Access denied for user 'my_username'@'localhost' (using password: YES)
Returned from hook drush_sql_cli [0.87 sec, 3.72 MB]                     [debug]
Command dispatch complete [0.87 sec, 3.71 MB]                           [notice]
Peak memory usage was 5.21 MB [0.87 sec, 3.7 MB]                        [memory]
$

```

It seems it cannot connect to the database so I did the following:

```
$ drush sql-connect
mysql --user=my_username --password=my_password --database=bootstrap_business --host=127.0.0.1 --port=3306
$ mysql --user=my_username --password=my_password --database=bootstrap_business --host=127.0.0.1 --port=3306
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 286
Server version: 5.5.38-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

```

I can connect manually to the database with the connection string given by drush.

So then I deleted the `.drush` folder in my home directory but that did not help. I did try this for both Drupal 7 and 8 sites.

So then I downgraded to drush 6 (`composer global require drush/drush:6.*`) and drush then worked flawlessly with Drupal 7 sites. I then upgraded to drush 7 (`composer global require drush/drush:dev-master`) and it stops working again

Any ideas on how to solve this??

# Answer
The answer to the problem was that I had a file `.my.cnf` in my home directory which I used a while back. It contained the `user=username` and the `password=old_password`. This was the cause of problem as it contained the correct username but an old password.

Previous drush versions (\< 7.x) did not use the mysql option `--defaults-extra-file=/tmp/mysql_credentials` to connect to database and that's why the problem didn't exist when I used an older version of drush.

I would have thought that the '`--defaults-extra-file=/tmp/mysql_credentials` would supercede the `.my.cnf` in my home directory but it doesn't seem to.

One thing which would be useful to help debug this issue it to make drush not delete the `/tmp/...` files when you select the `-d` option.
> 13 votes

# Answer
Do a `drush st database | grep -i connected`.

If you don't get any results, that could mean (in your case) the db credentials on your settings.php is wrong.

The above command tells drush to give a status (st) of your installation, filter results to include only strings containing the word *database* and finally passing this result to grep to do a case-insensitive search for the word *connected*. To understand more about `drush st` execute a `drush help st`.
> 1 votes

---
Tags: drush
---


# Question
Title: How To Wrap Drupal Form API in html div structure [in my Drupal theme files (.tpl file)]
I have a webpage which is being rendered from my page.tpl.php , it has a login page at top - right of page. I am kind of struggling to wrap my `LOGIN HTML FORM` in `Drupal Form API`

Below Links did not help me that much even though it gave me general idea

1. should-i-put-input-tag-inside-label-tag

2. drupal-7-forms-how-do-you-wrap-an-input-in-a-label

3. how-to-put-two-form-elements-in-a-row-using-drupal-form-api Below image shows my Login form

theme\_form\_element , drupal-form-api-prefix-suffix, using-prefix-and-suffix-form-api-layout and drupal-form-wrap-div-tag-custom-html-prefix-suffix gave me some idea but I am still puzzled about this things.

{ found some more helpful links for this :

1. how-to-create-multiple-forms-in-drupal-7.html
2. page-user-login.tpl.php
3. page-template-for-custom-form
4. Printing a form on a page with drupal\_get\_form }

Can some one guide me for this.

I am not sure if I should go with `Drupal form` or just use the normal `HTML Login` in `PHP` way.

For Better Understanding of the scenario I am adding screen shots and details of my task below, it is purely just for example, all I am looking for is some guidance for the task I am doing, answer does not have to be exactly FORM API of my HTML but I need to know how to achieve this in page.tpl.php.

\[Do I have to create new custom module or I can manage this in my page.tpl.php- sorry if it is very simple question, I am little new here in drupal \]

> **Here is the HTML**

```
<div class="accessBlock">
            <button class="primary_btn">Download Guidelines</button>
            <button id="loginPopup" class="primary_btn">Login</button>
</div>

<div class="loginBox" style="overflow: hidden; display: block;">
            <div class="loginHolder">
                <div class="nameHolder"><p class="sub-title-1">Email address</p></div>
                <div class="inputHolder"><input type="text" placeholder="Enter your email address"></div>
                <div class="nameHolder"><p class="sub-title-1">Password</p></div>
                <div class="inputHolder"><input type="password" placeholder="Enter your password"></div>
                <div class="nameHolder"><p class="sub-title-1">Not registered?</p></div>
                <div class="inputHolder"><input type="checkbox" vlaue="ss"><span class="registerNote">Tick this box and click 'Register'</span></div>
                <div class="buttonHolder">
                    <button class="primary_btn">Login</button>
                    <button class="primary_btn">Register</button>
                    <button class="primary_btn">Cancel</button>
                </div>
            </div>
        </div>

```

I need to create a Login and Registration Module. I have this whole form in basic html not in form, I am struggling to convert this to `Drupal From`

Also I am not sure if I should go for `Drupal Form` or not. Since my requirement is to show the error message in the same place `<div>` . see below

Thanks :)

# Answer
> 2 votes
It will be hard to implement this html as it is. You have to create a custom form using form api of drupal and use its arguments to make the html nearly same like your design. But still there will be css changes respectively. Let me edit Email field for you

```
    function mycustomform($form, &$form_state){
    $form['email'] = array(
      '#type' => 'textfield',
      '#title' => t('Email address'),
      '#size' => 60,
      '#maxlength' => 128,
      '#required' => TRUE,
      '#prefix'=>'<div class="inputHolder"><p class="sub-title-1">',
      '#suffix'=>'</p></div>',
      '#attributes'=>array('placeholder'=>'Enter your email address')
    );

    $form['password'] = array(
      '#type' => 'password',
      '#title' => t('Password'),
      '#size' => 60,
      '#maxlength' => 128,
      '#required' => TRUE,
      '#prefix'=>'<div class="inputHolder"><p class="sub-title-1">',
      '#suffix'=>'</p></div>',
      '#attributes'=>array('placeholder'=>'Enter your password') // No use because it will show dots or *
    );
    $form['login'] = array(
      '#type' => 'submit',
      '#value' => t('Login'),

      '#prefix'=>'<div class="buttonHolder">',
      '#suffix'=>'',
      '#submit'=>'custom_user_login',
      '#attributes'=>array('class'=>array('primary_btn')) // No use because it will show dots or *
    );
    $form['register'] = array(
      '#type' => 'submit',
      '#value' => t('Register'),
      '#submit'=>'custom_user_register',
      '#prefix'=>'',
      '#suffix'=>'</div>',
      '#attributes'=>array('class'=>array('primary_btn')) // No use because it will show dots or *
    );
return $form;
}

function mycustomform_validate($form, &$form_state){
    //Add checks for already registered user
}

function custom_user_login($form, &$form_state){

      if($uid = user_authenticate($username=$form_state['values']['email'], $password=$form_state['values']['password']))
    {
      user_login_submit(array(), array('uid' => $uid));
      return true;
    }
    else
    {
        return false;
    }
}

function custom_user_register($form, &$form_state){
    $new_user = array(
  'name' => $form_state['values']['email'],
  'pass' => $form_state['values']['password'], // note: do not md5 the password
  'mail' => $form_state['values']['email'],
  'status' => 1,
  'init' => $form_state['values']['email'],

);

// The first parameter is sent blank so a new user is created.
$user = user_save('', $new_user);
if($user->uid){
drupal_set_message('User saved successfully');
}else{
    drupal_set_message('Error in saving user','error');
}
}

```

Hope it will help you.

---
Tags: users
---


# Question
Title: Can I display all token values available for my Drupal installation?
Is there a way that I can display all possible values for tokens available on my Drupal installation? For example, I'd like to see all of the possible values for the \[termalias-raw\] placeholder that I use with the Pathauto module.

# Answer
To see all the value a token would get, you should call the function that replaces a token with its value, passing a different value for its `$object` parameter.
Using pseudo-code, this is the code you should run:

```
foreach (get_all_nodes() as $node) {
  print token_replace("[termalias-raw]", 'node', $node);
}

```

"\[termalias-raw\]" is a token implemented by the Pathauto module that is associated with node objects.
This is the code contained in pathauto\_token\_list(), which is the function that lists all the token implemented by a module:

```
if ($type == 'node' || $type == 'all') {
  $tokens['node']['termpath'] = t('As [term], but including its supercategories separated by /.');
  $tokens['node']['termpath-raw'] = t('As [term-raw], but including its supercategories separated by /.');
  $tokens['node']['termalias'] = t('The URL alias of the taxonomy term.');
  $tokens['node']['termalias-raw'] = t('The URL alias of the taxonomy term.');
}

```

If you meant the list of all the tokens available, then that list is already given by the Pathauto module in the form that allows you to set the path alias for each entity supported by the module. To see it all you need to check each of the path alias types (e.g. *user*, *node*, *taxonomy terms*).
> 4 votes

# Answer
In Drupal 7, the list is available at /admin/help/token Cheers.
> 4 votes

# Answer
This is very vague. Token values depend on providing data - so you'd be requesting to see what the token value is for every single node on your site?

I guess if you wanted to do this (assuming Drupal 6 and using the latest release of Token module):

```
$result = db_query("SELECT nid FROM {node} ORDER BY nid");
while ($nid = db_result($result)) {
  $node = node_load($nid, NULL, TRUE);
  echo "Node: $nid\t";
  echo "[termalias-raw]: " . token_replace('[termalias-raw]', 'node', $node, '[', ']', array(), TRUE);
  echo "\n";
}

```

Also, if you have the Devel module enabled, you should have a 'Devel' tab on all your nodes with a 'Tokens' sub-tab so that you can inspect all the tokens for a specific node.
> 2 votes

---
Tags: taxonomy-terms, tokens, path-aliases
---


# Question
Title: How and where do I programmatically add a menu to the Navigation menu?
I want to add menu items to the Navigation menu dynamically, depending on certain states (example: user is logged in, etc). I assume I do this in theme\_preprocess, but I can't seem to find the var to tweak.

Am I looking in the wrong place? Where is the best place to do this, and what is the best method?

# Answer
I'd suggest checking out hook\_menu(). For example, the following implementation of `hook_menu()` placed in either a module or template.php should insert a menu item into the navigation menu for anonymous users. Take a look at the User module for some good examples of how to implement `hook_menu()` for different user roles.

```
function MODULE_menu() {
   $items = array();
   $items['the/menu/path'] = array(
   'access callback' => 'user_is_anonymous',  //or 'user_is_logged_in' to check if logged in
   'type' => MENU_NORMAL_ITEM,
   'menu_name' => 'navigation',
   'title' => t('Title of Menu Item'),
  );
  return $items;
}

```
> 7 votes

# Answer
I think you can create it by using `menu_link_save()`.

```
$item = array(
  'link_path' => 'my_path',
  'link_title' => 'title',
  'menu_name' => 'header-top-menu', // Menu machine name, for example: main-menu
  'weight' => 0,
  'language' => $node->language,
  'plid' => 0, // Parent menu item, 0 if menu item is on top level
  'module' => 'menu',
);
menu_link_save($item);

```

You could use the code I am showing in a `hook_update_N()` implementation.

See also Drupal 7 Menu Link update through update.php.
> 6 votes

---
Tags: 7, theming, routes
---


# Question
Title: Configuration Settings of Authcache + File Cache
I have already file cache module installed and working perfectly except that I've read that it also work with authcache.

So I installed authcache but wondering what is the proper configuration in the settings.php.

In authcache readme file, it gives an example as follows:

```
$conf['cache_backends'][] = 'sites/all/modules/filecache/filecache.inc';
$conf['cache_backends'][] = 'sites/all/modules/authcache/authcache.cache.inc';
$conf['cache_backends'][] = 'sites/all/modules/authcache/modules/authcache_builtin/authcache_builtin.cache.inc';
$conf['cache_class_cache_page'] = 'DrupalFileCache';

```

And my current configuration for file cache module is:

```
$conf['cache_backends'] = array('sites/all/modules/filecache/filecache.inc');
$conf['cache_default_class'] = 'DrupalFileCache';
$conf['filecache_directory'] = '/tmp/scfilecache-' . substr(conf_path(), 6);

```

I tried to combine the two configuration as follows without luck:

```
$conf['cache_backends'][] = 'sites/all/modules/filecache/filecache.inc';
$conf['cache_backends'][] = 'sites/all/modules/authcache/authcache.cache.inc';
$conf['cache_backends'][] = 'sites/all/modules/authcache/modules/authcache_builtin/authcache_builtin.cache.inc';
$conf['cache_class_cache_page'] = 'DrupalFileCache';
$conf['filecache_directory'] = '/tmp/scfilecache-' . substr(conf_path(), 6);

```

My site returns an error with the config above.

Anyone know what is the correct configuration for authcache + file cache?

# Answer
After testing for several settings, I came up with the following configuration:

```
$conf['cache_backends'][] = 'sites/all/modules/filecache/filecache.inc';
$conf['cache_default_class'] = 'DrupalFileCache';
$conf['filecache_directory'] = '/var/www/clients/client1/web8/tmp';
$conf['cache_class_cache_authcache_key'] = 'DrupalFileCache';

$conf['authcache_builtin_cache_without_database'] = TRUE;

$conf['page_compression'] = 1;

$conf['page_cache_maximum_age'] = 600;

$conf['cache_backends'][] = 'sites/all/modules/authcache/authcache.cache.inc';
$conf['cache_backends'][] = 'sites/all/modules/authcache/modules/authcache_builtin/authcache_builtin.cache.inc';

```

I am using nginx and just change the `$conf['cache_class_cache_page']` to `$conf['cache_default_class']`. I don't know if I am using the correct config, but this works for me.

And the speed of my server increase significantly when I ab test it.
> 1 votes

---
Tags: 7, caching
---