Skip to content

Instantly share code, notes, and snippets.

@guoxiangke
guoxiangke / Entity metadata wrappers.php
Created October 9, 2012 09:51
Entity metadata wrappers
<?php
// Create wrapper around the node.
$wrapper = entity_metadata_wrapper('node', $node);
// We can do it also using only $nid.
$wrapper = entity_metadata_wrapper('node', $nid);
// Get the value of field_name of the nodes author's profile.
$wrapper->author->profile->field_name->value();
$wrapper->author->profile->field_name->set('New name');
@guoxiangke
guoxiangke / add a Cancel button to Drupal forms
Created January 18, 2013 03:42
关键点: '#type' => 'submit', '#limit_validation_errors' => array(), '#submit' => array('yourmodule_cancel_buttons_callback')
/**
* @file
* Defines a Cancel button on node forms
*/
function yourmodule_cancel_form_node_form_alter(&$form, &$form_state) {
$form['actions']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#weight' => 20,
'#executes_submit_callback' => TRUE,
@guoxiangke
guoxiangke / dale_js_form_behaviors
Last active August 26, 2017 05:33
1.drupal 7,表单如果有必填项没有填写,提交的话,自动focus到未填项。
//form behaviors
$('form .form-submit').click(function(e){
$('input.required').each(function(){
if($(this).val()==''){
$(this).focus();
e.preventDefault()
return false;
}
});
});
//Ckedit 定制!隐藏finder链接和图像,并设定默认值 for drupal
if(typeof(CKEDITOR) === 'object')
CKEDITOR.on( 'dialogDefinition', function( ev )
{
// Take the dialog name and its definition from the event
// data.
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
// Check if the definition is from the dialog we're
@guoxiangke
guoxiangke / gist:8996525
Created February 14, 2014 06:10
iFrame: How to show specific part of a webpage using iframe
<div style="overflow: hidden; margin: 15px auto; max-width: 671px;">
<iframe scrolling="no" src="http://www.tudou.com/programs/view/CsD3k0zPQuU" style="border: 0px none; margin-left: 0px; height: 2354px; margin-top: -853px; width: 926px;">
</iframe>
</div>
<?php
//drupal7 迁移评论 某个节点的
//dpm(comment_load(381));
$comments = array();
for($i=0;$i<500;$i++) {
$comment = comment_load($i);
if($comment && $comment->nid == '3') {
$comment->nid = '486';
$comment->node_type = 'comment_node_page';
unset($comment->rdf_data);
@guoxiangke
guoxiangke / syfmony1
Created March 7, 2014 06:53
syfmony安装记录1
//syfmony安装记录1
composer create-project symfony/framework-standard-edition . 2.4.2
Installing symfony/framework-standard-edition (v2.4.2)
- Installing symfony/framework-standard-edition (v2.4.2)
Downloading: 100%
Created project in .
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing jdorn/sql-formatter (v1.2.17)
@guoxiangke
guoxiangke / drupal node created
Created April 16, 2014 23:34
按顺序创建365个节点
$time = strtotime('2014-01-01 00:00:00+00:00');
dpm(date('Y-m-d 00:00:00+00:00',$time));
$i=date('z');
dpm($i);
$nodes = array();
for($i;$i<=365;$i++) {
$created =$time + $i* 86400;
$node = new stdClass();
$node->uid = '1';
$node->type = 'grace365';
@guoxiangke
guoxiangke / page--user.tpl.php
Created April 22, 2014 11:04
page--user.tpl.php
<div class="bbb-page-user clearfix">
<div class="header">
<div class="bbb-goback"> <a href="list">« 首页</a> </div>
<div class="username">@bluesky_still</div>
</div>
<div class="bbb-user">
<div class="picture">
<a href="#" class="">
@guoxiangke
guoxiangke / druedu_notifications.js
Created April 26, 2014 00:11
druedu_notifications.js
jQuery(function($){
function drueduNotificationsAjaxSubmit() {
$( ".notifications-ajax li a" ).each(function(){
if($(this).hasClass('btn-small')) {
$(this).removeClass('btn-small');
}
$(this).addClass('btn btn-mini');
});