drupal 7 case 1
create theme
- I created a menu, but in node edit page, I can’t find it in ‘parent item’ list. Is it settings of content type?
Yes, there is an option ‘menu setting’ in content type edit page. - When I create a vocabulary, there is no content type setting option to assign the vocabulary.
It’s the field of content type. detail in http://drupal.org/node/1146844 - can’t find header and footer template codes in theme, only modify them in fuctions?
custom modules/system/html.tpl.php - node content is made as a block ‘Main page content’
- I remove block class module files from modules folder to sites/all/modules after it’s actived, there is no problem
- there is clearfix in system.base.css
- the search form block is not visible to anonymous visitor, to change the permissions
- title in node is h1.with-tabs, title in block is h2.title
- the default search block no default value
- http://drupal.org/node/154137
- http://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7
- http://api.drupal.org/api/drupal/includes%21theme.inc/function/theme/7
- how to make default text format to be full html?
Go to admin/config/content/formats, and move ‘full html’ to first line - node–type.tpl.php,clear all caches to enable new template files
- store http://drupal.org/project/location
- there is no multigroup
- use field collection http://drupal.org/project/field_collection
- field collection require entity http://drupal.org/project/entity
- go to content type page, create a new field with field colletion, with unlimited value
- go to admin/structure/field-collections, create fields for field collection
- field group is no useful for multigroup, http://drupal.org/project/field_group
- get image field in code
- http://stackoverflow.com/questions/8124089/get-value-of-custom-user-field-in-drupal-7-template
- http://benbuckman.net/tech/11/04/how-render-image-fields-drupal-7
- get image from theme folder in code
<img src="<?php print $GLOBALS['base_url']."/".path_to_theme(); ?>/images/icon01.gif" alt="" width="22" height="22" />
- get field collection value in code
- http://drupal.org/node/1166238
- http://drupal.org/node/1294536#comment-5362592
- custom taxonomy term page
- http://stackoverflow.com/questions/2654636/how-can-i-theme-the-taxonomy-term-x-page
- http://api.drupal.org/api/drupal/modules%21taxonomy%21taxonomy-term.tpl.php/7
- there is no location search module
https://drupal.org/node/359463
- search by city, location 7.3x dev already support city search, city names are in {zipcodes} table with latitude,longitude info. city name is put in zip column. so city name is made as zip code. http://drupal.org/node/489904
- Fatal error: Call to undefined function drupal_urlencode() in F:\wamp\www\drupal\sites\all\modules\gmap\gmap.module on line 1147
- drupal_urlencode has been replaced in D7 with drupal_encode_path
- http://drupal.org/node/1109708
- not map link, need map
- http://drupal.org/node/191926
- http://drupal.org/node/181340
- http://drupal.org/node/1089344
- https://drupal.org/node/489904
- custom block template, howto get module name, delta of block
- look at ‘block’ table in database, or get template file name with below codes in block.tpl.php
-
<?php $templatefile='block--'.$block->module.'--'.$block->delta.'.tpl.php'; echo $templatefile.'<br >'; ?>
- template_process_block(), look at all variables
- http://api.drupal.org/api/drupal/modules%21block%21block.module/function/template_preprocess_block/7
- NB:html_block_id is not equal as template file name,there are much difference.
- set html_block_id to be template file name in template.php
-
function mytheme_preprocess_block(&$vars) { $vars['title_attributes_array']['class'][] = 'title'; //$vars['classes_array'][] = 'clearfix'; $vars['block_html_id'] = 'block--'.$vars['block']->module.'--'.$vars['block']->delta; } - after create custom block template file, need to clear all cache
- after change custom block template file’s name, need to clear all cache
- http://drup-all.com/blog/exposed-filters-form-your-custom-block-drupal-7
https://drupal.org/node/290691
http://stackoverflow.com/questions/451745/drupal-views2-exposed-form-how-to-change
- get node teaser
- http://stackoverflow.com/questions/7259402/drupal-7-get-teaser-with-field-view-value
- get 1st of product images only in views
- config field with option ‘SHOWMULTIPLE FIELD SETTINGS’
- get block content in php
- http://www.werockyourweb.com/drupal-block-in-node
-
<?php $block_store = module_invoke('modulename', 'block_view', 'delta'); print render($block_store); ?> - convert path to alias with pathauto
<span style="line-height: 18px;"> <?php url('node/1');?></span> - create rss
- admin/config/services/rss-publishing, select ‘teaser plus title’, click ‘save’
- http://coredogs.com/article/creating-basic-rss-feed-drupal
- custom search results page,hide author and date info of node in results
- modules/search/search-result.tpl.php, find template_preprocess_search_result()
- http://api.drupal.org, search template_preprocess_search_result(),find it in modules/search/search.pages.inc, line 106
- open modules/search/search.pages.inc, find template_preprocess_search_result(), read comments and codes
- opentemplate.php, create mytheme_preprocess_search_result(&$variables)
-
function mytheme_preprocess_search_result(&$variables){ } - what’s the detail of $variables['result']
- show field of node in results
- get node id
- get node object
- get field value of node
-
function mytheme_preprocess_search_result(&$variables){ $node = node_load($variables['result']['node']->nid); $variables['product_type']=$node->field_product_type['und'][0]['value']; } - copy modules/search/search-result.tpl.php to template folder, output product type
-
<?php if ($product_type): ?> <div><?php print $product_type; ?></div> <?php endif; ?>
- Notice: Undefined property: stdClass::$field_product_type in mytheme_preprocess_search_result() (line 182 of F:\wamp\www\drupal\sites\all\themes\mytheme\template.php).
- change code to, and clear all caches
-
function mytheme_preprocess_search_result(&$variables){ $variables['info']=''; $variables['product_type']=''; $node = node_load($variables['result']['node']->nid); if(isset($node->field_product_type)){ $variables['product_type']=$node->field_product_type['und'][0]['value']; } } - http://drupal.org/node/175013
- http://drupal.org/node/1177980
- http://drupal.org/node/953096
- http://drupal.org/node/955894
- add target=”_blank” to menu item link
- http://drupal.org/project/menu_attributes
- http://drupal.org/node/102685
- http://api.drupal.org/api/drupal/includes%21menu.inc/function/theme_menu_link/7
- Embed view in your code in Drupal 7
- http://www.tipstank.com/2011/10/13/embed-view-in-your-code-in-drupal-7/
-
<?php $viewname='store_locator'; $view = views_get_view($viewname); print $view->preview('block_1'); ?> - make the gmap center on the zipcode that is entered
- In Admin > Site Configuration > Gmap in the Map Behavior flags set autozoom to on.
- Notice: Trying to get property of non-object in gmap_plugin_style_gmap->render() (line 105 of /home/xxxxxxxx/public_html/sites/all/modules/gmap/gmap_plugin_style_gmap.inc)
- http://drupal.org/node/1124724#comment-5632860
- Gmap Number or Letter marker doesn’t work
- http://drupal.org/node/514998
- http://highrockmedia.com/blog/using-drupal-views-arguments-show-results-only-when-filter-used
- http://drupalsh.cn/node/153
move drupal from local to server
- can’t upload files to sites/default/files in drupal 7 with ftp
- update the permission
- http://drupal.org/node/784972
- http://drupal.stackexchange.com/questions/20364/weird-permissions-problems-for-sites-default-files
- http://drupal.org/node/231865
- update file system configure
- update path.php from zip folder in local to server
- run path.php, get ‘/home/xxx/path.php’
- create tmp folder in server, set it with chmod 777
- set temp directory to ‘/home/xxx/tmp’
- The CTools CSS cache directory, ctools/css could not be created due to a misconfigured files directory. Please ensure that the files directory is correctly configured and that the webserver has permission to create directories.
- create css folder in sites/default/files/ctools/, and set chmod 777 for it.
- http://drupal.org/node/447064
- after update image in product page,the image shows blank, find the original image file in default/files, but can’t find related images in product_large,thubmnail,product_thumb folder
- ensure all subdirectorys of ‘default/files’ with chmod 777
- images in the page uploaded by ckeditor are not show with wrong url
- upate the database with running sql or edit the url in ckeditor
- http://psdtucss.com/drupal/move-drupal-site-from-local-to-server/
move drupal to another server
- Backup and Migrate Database http://drupal.org/project/backup_migrate, is not very useful
- Backup and Migrate Files http://drupal.org/project/backup_migrate_files, it only backup site/default/files folder, not very useful
- use phpmyadmin to export mysql without extended inserts
- Export Method
- Custom – display all possible options
- Format-specific options:Data dump options:Syntax to use when inserting data:
- include column names in every
INSERTstatement - Example: INSERT INTO tbl_name (col_A,col_B,col_C) VALUES (1,2,3)
- use custom code to create zip file of whole site
- import mysql file with bigdump
- troubeshoot
Stopped at the line 12127. At this place the current query includes more than 300 dump lines. That can happen if your dump file was created by some tool which doesn't place a semicolon followed by a linebreak at the end of each query, or if your dump contains extended inserts. Please read the BigDump FAQs for more infos.
- extended inserts cause this error, make sure use phpmyadmin to export mysql without extended inserts
- upload and unzip zip file
- update database connect info
- only home page is access, inner pages show error:Internal Server Error
- clean url is not working
- go to mysql, table ‘variable’, find ‘clean_url’ in name column, but the value type is ‘blob’, can’t to disable it directly
- go to http://example.com/?q=admin/config/search/clean-urls, disable clean url
- clean url failure, .htaccess file is missing
- http://drupal.org/node/15365
- change sites/default/files/* permission to writeable, make sites/default/settings.php not writeable
- Update Drupal Core
- http://drupal.org/node/1494290
- Domain access failed to load during phase: bootstrap include. Please check your settings.php file and site configuration.
- add code to settings.php
- include ‘./sites/all/modules/domain/settings.inc’;
detect input changes event
This jQuery code catches immediate changes to any element, and should work across all browsers:
$('.myElements').each(function() {
// Save current value of element
$(this).data('oldVal', $(this).val());
// Look for changes in the value
$(this).bind("propertychange keyup input paste", function(event){
// If value has changed...
if ($(this).data('oldVal') != $(this).val()) {
// Updated stored value
$(this).data('oldVal', $(this).val());
// Do action
....
}
});
});
wordpress visual editor(tinymce) usage
- wordpess visual wysiwyg editor is tinymce
- when you add new post, click in the editor, the path shows ‘p’
- bullets usage
- click ‘ordered list’
, it creates first bullets item - press ‘Enter’ key, it creates another bullets item
- press ‘Enter’ key first and then click ‘outdent’
or ‘ordered list ‘ to finish bullets or jump out bullets - click ‘indent’
to create next level(children) bullets - click ‘unordered list’ , change ‘ordered list’ to ‘unordered list’
- first level bulltes is odered by ’1.’, ’2.’ …
- second level bulltes is ordered by ‘A.’,'B.’ …
- when you are in children bullets, press ‘Enter’ key first and click ‘outdent’ or ‘ordered list’ to jump to first level bullets
- ‘h3′ usage
- type or paste your text, it shows in ‘p’ auto
- click ‘format’ and select ‘headline 3′
- the same for other formats
- Remove formatting
- when the path is ’p » font » span’, click the ‘remove formatting’, the path is changed to ‘p’
- it’s no effection to remove format directly ‘p’,'li’ etc
- if you want remove ordered list format ( ‘li’ ) , just click ‘outdent’ or ‘ordered list’
- if you want to remove ‘p’ format, just click ‘format’ and select other format
- click ‘insert custom character’
to insert special character such as ‘»’ - to add line breaks ‘br’, press ‘shfit +enter’ keys
create drupal 7 theme
Initial theme
- copy theme ‘garland’ to sites/all/themes and rename it
- delete ‘color’ folder
- clean ’images’ folder
- clean style.css file
- clean theme-settings.php
- clean template.php
- rename and edit garland.info file
- replace screenshot.png(294×219) file
- create regions
- edit page.tpl.php
- go to admin/appearance, set site theme with new theme
- add javascript
- http://drupal.org/node/171205
Theme reference
- Default baseline variables
- Drupal 7 Theme Hook Suggestions
- variables in html.tpl.php
- variables in page.tpl.php
- The path ‘taxonomy/term/1+2′ is either invalid or you do not have access to it.
- taxonomy/term/1+2 is not supported in drupal7, just to create views with ‘filter criteria’
- http://drupal.org/node/1108742
Initial drupal 7
- create menus name
- create menus name
- create taxonomy
- create content type
- publishing options
- display settings
- comment settings
- menu settings
- add term field
- create nodes
- leave content blank
- menu settings
- create other menu items
- install ckeditor, imce modules
- create detail nodes
- install views , ctool modules
- install block class module
- create blocks
lightbox
- Shadowbox
- Free from Frameworks
- Shadowbox supports all of the web’s most popular media publishing formats including images, QuickTime, Windows Media Player, Flash, Flash video, HTML, and even external web pages. This makes it easy to display your content, no matter what it is
- FancyBox
- jQuery Plugin
- Simple and fancy lightbox alternative
The type of database your Drupal data will be stored in. Your PHP configuration only supports a single database type, so it has been automatically selected
I try to install drupal 7 on local. it select sqlite to store database “The type of database your Drupal data will be stored in. Your PHP configuration only supports a single database type, so it has been automatically selected.” If I continue to install, it installed sqlite, not mysql. my local server has mysql 5.0.45 and php 5.2.5 , and drupal 7 requires
- MySQL 5.0.15 or higher with PDO
- PHP 5.2.5
So it seems my local server meets the requirements. After I enabled php_pdo_mysql, Drupal 7 can be installed with mysql.
ckeditor is not working well in multigroup of drupal 6
Errors:
- when we click on add more value button, the ckedior disappears from text areas
- Text in textarea dissappears when clicking cck’s “Add another item”
- “Add another item” button breaks all WYSIWYG editors on edit form
- Data loss when clicking “Add another item” from CCK text field
update steps:
- disable, uninstall and delete ckeditor module
- install wysiwyg-6.x-2.0
- copy tinymce files to sites/all/libraries/tinymce
- install IMCE Wysiwyg bridge (http://drupal.org/project/imce_wysiwyg)
- configure admin/settings/wysiwyg, set tinymce as editor for both filter html and full html; edit the profile, set Buttons and plugins, enable the buttons such as bold,..advance image,…imce
- configure textarea field in mulitgroup, in Global settings, Text processing: select Filtered text (user selects input format)
- install JS Alter(http://drupal.org/project/jsalter)
- install jQuery Form Update(http://drupal.org/project/jquery_form_update)
- install jQuery AOP (http://drupal.org/project/jquery_aop)
- install Wysiwyg API CCK Integration (http://drupal.org/project/wysiwygcck)
notes:
- wysiwyg-6.x-2.0 support fckeditor, not support ckeditor
- ckeditor is the new version of fckeditor
Error: Form elements must not be named “submit”
When submitting an upload form in drupal 6, an alert shows up: Error: Form elements must not be named “submit”. jquery version is 1.2.6 in drupal 6.22, I updated it to 1.3.2.
I just saw the problem. It’s in line 54 of the jquery.form.js file which says
$(':input[@name=submit]', form).length
From API/1.3/Selectors, it says that
Note: In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the '@' symbol from your selectors in order to make them work again.
I probably got the problem when I replaced my jQuery version from 1.2 to 1.3. When I recovered the jQuery 1.2.6. the problem is fixed.
Drupal error: An error accured at http://example.com/admin/build/views/ajax/config-item/Latest/block_1/sort/created Error Description:0
You may get error: An error accured at… Error Description:0, when you edit views in drupal. This is an example and try to analysis the reason and solution.
Requirement:
1. Drupal 6.22
2. Views 2.11
When I try to save a view named “lastest” after edition.the Chrome alerts an error:
An error accured at http://example.com/admin/build/views/ajax/config-item/Latest/block_1/sort/created Error Description:0
there are more info in console of Chrome
Failed to load resource: the server responded with a status of 403 (Forbidden): http://example.com/admin/build/views/ajax/config-item/Latest/block_1/sort/created XMLHttpRequest cannot load http://example.com/admin/build/views/ajax/config-item/Latest/block_1/sort/created. Origin http://www.example.com is not allowed by Access-Control-Allow-Origin.
There is the same error in firefox
An error accured at http://example.com/admin/build/views/ajax/config-item/Latest/block_1/sort/created Error Description:0
I find the page url is http://www.example.com/admin/build/views/edit/Latest. and the resource url is http://example.com/admin/build/views/ajax/ config-item/Latest/block_1/sort/created. it has no “wwww.”. Try to change the page url from http://www.example.com/admin/build/views/edit/Latest to http://example.com/admin/build/ views/edit/Latest. There is no errors.
When you open http://www.example.com/admin and login at first time. the page url will turn to http://example.com/admin autoly.Then the page url and resource url is the same. both of the url have no “wwww.”. But when you open http://www.example.com/admin after you already login. the page url is still http://www.example.com/admin. then there is difference between the page url and the resource url. And www.example.com and example.com are supposed as different “origin”.It causes security problem.
We can change the page url by hand. Default resource url is http://example.com, how to change the resource url if you want. Just to edit settings.php:
1. open sites/default/settings.php
2. uncomment the Base URL statement and fill in the absolute URL to your Drupal installation. Such as
$base_url = 'http://www.example.com/drupal';
But after you change the Base URL in settings.php,when you try to login, the page url will redirect to Base URL, and the resource url also uses the Base URL.
Obviously, change Base URL can’t solve this problem. The solution is we should change the page url by hand. But change Base URL is useful at sometimes. For example, if the site is not available without “www.”, then you should change it to have “www.”.
Change language after installation in drupal 6
1. go to admin/build/modules, active locale module under core-optional section.
2. go to admin/settings/language/add, add Spanish language
3. go to admin/settings/language, enable Spanish language and make it as default language
4. download language files from http://localize.drupal.org/translate/languages/es
5. go to admin/build/translate/import,import the language file es.po
http://drupal.org/node/229416
http://drupal.org/project/admin_language
http://groups.drupal.org/node/149984