Skip to content

Instantly share code, notes, and snippets.

View chadmandoo's full-sized avatar

Chad Peppers chadmandoo

  • Missouri
View GitHub Profile
@chadmandoo
chadmandoo / render_block.php
Last active December 19, 2015 05:29
Drupal programmatically render a block
<?php
//module_invoke('module_name', 'block_view', 'block_identifier')
//Printing using Drupal block system
$block = module_invoke('block', 'block_view', '1');
print render($block['content']);
//Printing using a contrib module block, this example uses the weather module
$block = module_invoke('weather', 'block_view', 'user');
print render($block['content']);
@chadmandoo
chadmandoo / entity_create.php
Last active December 20, 2015 02:09
Programmatically create an instance of a node using the Entity API/Entity Metadata Wrapper
<?php
//Load instance of entity
$node = entity_create('node', array('type' => 'content_type'));
$entity = entity_metadata_wrapper('node',$node);
//Set properties
$entity->author = $user->uid; // Author
$entity->title->set("String"); //Title
$entity->field_name->set("String"); //Textfield
$entity->body->set(array('value' => "String or HTML")); //Body
@chadmandoo
chadmandoo / gist:8031117
Created December 18, 2013 22:40
Drupal Bing news
<?php
/**
* @file
* Code for the Bing News feature.
*/
include_once 'bing_news.features.inc';
define ('BING_NEWS_URL', 'https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%27news%27&Query=%27@bing_news_query%27&NewsSortBy=%27Date%27&@bing_skip&$format=json');
@chadmandoo
chadmandoo / arrays_objects.php
Created June 30, 2014 21:29
Arrays and Object
<?php
//Object with an array inside
$object->array['value']['value'];
//Array with an object
$array['object']->value;
//Accessing a property of an object
$object->value;
<?php
$make = array( "Chevrolet", "Ford", "Dodge", "Cadillac" );
$model = array( "Malibu", "Focus", "Ram", "Escalade" );
$year = array( 2010, 2011, 2012, 2013 );
array_multisort( $authors, $titles, $pubYears );
// Displays "Array ( [0] => Cadillac [1] => Chevrolet [2] => Dodge [3] => Ford )"
print_r ( $make );
echo "<br/>";
// Displays "Array ( [0] => Escalade [1] => Malibu [2] => Ram [3] => Focus )"
print_r ( $model );
<?php
$make = array( "Chevrolet", "Ford", "Dodge", "Cadillac", "Chevrolet" );
$model = array( "Malibu", "Focus", "Ram", "Escalade", "Corvette" );
$year = array( 2010, 2011, 2012, 2013, 2014 );
array_multisort( $authors, $titles, $pubYears );
// Displays "Array ( [0] => Cadillac [1] => Chevrolet [2] => Chevrolet [3] => Dodge [4] => Ford )"
print_r ( $make );
echo "<br/>";
// Displays "Array ( [0] => Escalade [1] => Corvette [2] => Malibu [3] => Ram [4] => Focus )"
print_r ( $model );
<?php
$myBooks = array(
array(
"title" => "The Grapes of Wrath",
"author" => "John Steinbeck",
"pubYear" => 1939
),
array(
"title" => "Travels With Charley",
"author" => "John Steinbeck",
<?php
function myfun($num1, $num2, $ctr = 1)
{
for ($i = $num1; $i <= $num2; $i += $ctr)
{
yield $i;
}
}
echo 'Odd numbers: ';
foreach (myfun(1, 7, 2) as $num)
<?php
function fun1(Callable $func)
{
$func();
return "This function is ";
}
class Sample
{
public function __invoke()
{
<?php
/**
* Class EntityDecorator.
*/
class EntityDecorator {
protected $entity;
protected $wrapper;