Skip to content

Instantly share code, notes, and snippets.

View dsnopek's full-sized avatar

David Snopek dsnopek

View GitHub Profile
@dsnopek
dsnopek / SA-CORE-2018-001.patch
Last active February 23, 2018 14:31
Patch to update full Drupal 6.38 release to Drupal 6.41
diff -Nur drupal-6.38/includes/common.inc drupal-6.41/includes/common.inc
--- drupal-6.38/includes/common.inc 2016-02-24 13:20:15.000000000 -0600
+++ drupal-6.41/includes/common.inc 2018-02-22 10:29:07.000000000 -0600
@@ -1499,7 +1499,7 @@
);
if (!isset($options['external'])) {
- $options['external'] = menu_path_is_external($path);
+ $options['external'] = $_GET['q'] === $path ? FALSE : menu_path_is_external($path);
}
<?php
class MyObjectUnitTest extends UnitTestBase {
/**
* Mock object for one of the objects dependencies.
*
* @var \Project\Dependency|\Prophecy\Prophecy\ObjectProphecy
*/
protected $dependency;
@dsnopek
dsnopek / block-annotation-with-context.php
Last active September 20, 2018 15:54
Drupal 8 block annotation with context example
/**
* @Block(
* id = "my_block",
* context = {
* "node" = @ContextDefinition("entity:node")
* }
* )
*/
@dsnopek
dsnopek / convert_landing_pages.php
Created May 30, 2015 00:33
Panopoly: Convert Page Manager pages into Landing Page nodes
function _panopoly_convert_landing_pages() {
ctools_include('export');
// Collect a list of all the page manager pages that are eligable for
// conversion. There are lots of features of page manager pages that don't
// work with Panelizer nodes!
$pages = array();
foreach (ctools_export_load_object("page_manager_pages") as $page) {
// Skip pages that are in code at all (even if they are overridden in the
// database).
@dsnopek
dsnopek / convert_img_to_media.php
Last active August 29, 2015 14:10
hook_update_N() function to convert <img> tags to Media tokens (Drupal)
/**
* A helper function to convert <img> tags to Media tokens where possible.
*
*/
function hook_update_N() {
// A cache to help us when we encounter the same <img> tag multiple times.
$src_info_cache = array();
// We'll work directly in the database for performance reasons.
$tables = array(
@dsnopek
dsnopek / existing_node_to_content_item.php
Created November 19, 2014 16:19
hook_update_N() to replace "Existing node" panes with Panopoly's "Content item" pane (Drupal)
/**
* Convert 'Existing node' panes to 'Content item' panes.
*/
function hook_update_N() {
// We're going to load the panes directly from the 'panels_pane' table and
// replace them with the new pane, reusing the same IDs and everything.
// Don't try this at home, kids!
$result = db_query("SELECT * FROM {panels_pane} WHERE type = 'node' AND subtype = 'node'");
$serialized_fields = array('access', 'configuration', 'cache', 'style', 'css', 'extras', 'locks');
foreach ($result as $pane) {
@dsnopek
dsnopek / change_text_format.php
Created November 17, 2014 21:48
Function to change text format on all content (Drupal)
/**
* Change content from one input format to another, deleting the old at the end.
*
* @param string $old_format
* Name of the old input format.
* @param string $new_type
* Name of the new input format.
*/
function _myprofile_install_change_input_format($old_format, $new_format) {
// Change the format on all fields.
@dsnopek
dsnopek / gist:c25791aff617cdf7535d
Created July 15, 2014 13:11
openberkeley_base permissions
access administration pages
access content
access content overview
access site reports
access user profiles
add media from remote sources
administer blocks
administer files
administer menu
administer nodes
<?php
$a = array('a' => 'a1', 'b' => 'b1');
$b = array('a' => 'a2', 'b' => 'b2');
print_r(array_map(NULL, $a, $b));
/* RESULT:
Array
(
/**
* Implements hook_module_implemnts_alter().
*/
function MODULE_module_implements_alter(&$implementations, $hook) {
if ($hook == 'user_login' && isset($implementations['oa_core'])) {
// The oa_core_user_login() function does some INSANE things with redirecting
// the user to their home dashboard and it messes up our registration workflow.
unset($implementations['oa_core']);
}
}