Skip to content

Instantly share code, notes, and snippets.

View somatonic's full-sized avatar

Philipp Urlich somatonic

View GitHub Profile
@somatonic
somatonic / PageAddableHook.module
Last active August 29, 2015 13:57
Example module to modify/remove page "addable" permission for pages with level greater than one and basic-page template
<?php
/**
* ProcessWire example demonstration module
*
* Page::addable hook module, once installed will set permission "addable" to false
* for pages using basic-page template and with level greater than 1
*/
class PageAddableHook extends WireData implements Module, ConfigurableModule {
@somatonic
somatonic / HelperFieldsLanguageLabel.module
Created March 13, 2014 18:50
Adds a method to get lanugage label from a field with $fields->getLangLabel("body")
<?php
/**
* ProcessWire module
*
* Example Fields Language Label Helper
* Gets the language value of a field label for the current user's language
*
* Once Installed it will add a new method to fields
*
@somatonic
somatonic / TextareaStripNbsp.module
Created April 9, 2014 23:45
Fix TinyMCE &nbsp chars, leaving those without a space in front intact
<?php
/**
* TinyMCE replace nbsp with regular whitespace
*
* Only nbsp preceeded with a whitespace will get replaced, this leaves
* single non breaking space only bewtween words
*
* ProcessWire 2.x
* Copyright (C) 2012 by Ryan Cramer
@somatonic
somatonic / MyPageTableHooks.module
Last active August 29, 2015 14:05
Example InptfieldPageTable hook module to remove "Add New" button on a condition
<?php
/**
* Example Hooks to hack InputfieldPageTable to not render add buttons on a condition
* This will remove "add new" buttons if there's more than 2 entries
*
* - First addHookBefore InputfieldPageTable::render to count the value (table rows)
* - If value is greater than 1, we hadd another hook to InputfieldButton::render (used by page table for the buttons)
* and overwrite it with an empty string.
* - Add another hook after page table render to remove the button hooks, to not remove any other buttons rendered
@somatonic
somatonic / AddImagesFromUrl.module
Last active August 29, 2015 14:09
AddImagesFromUrl.module
<?php
/**
* AddImagesFromUrl
*
* On a page with fields
* "add_images_url" text field
* "images" images field
*
* This basic example module will add the image from the url to the images field on page save.
@somatonic
somatonic / login.php
Created June 8, 2015 08:11
processwire login
/**
* Custom login
* ==============================================================================
*/
wire()->addHookBefore("ProcessLogin::execute", function($event){
if(wire("user")->isLoggedin() && wire("input")->get("login")) {
wire("session")->redirect("/");
}
});
$words = '';
$q = $sanitizer->selectorValue($input->post->q);
$words = explode(' ', $q);
foreach($words as $word) {
$word = $sanitizer->selectorValue($word);
if($word) $selectorEmergencyContacts .= "title|label_$lang*=$word, ";
}
...
@somatonic
somatonic / breadcrumbs.php
Created March 28, 2012 15:04
PW breadcrumb
foreach($page->parents as $p) echo "<a href='$p->url'>$p->title</a>";
$parent = '/processwire/access/users/' . $user->name;
foreach($pages->get("/tools/categories/")->children("sort=title") as $tag) {
echo "<h2>$tag->title</h2>";
foreach($pages->find("parent={$parent}, course_categories=$tag") as $p){
echo "<a href='{$p->course_documents->url}'>{$p->course_documents->name}</a>";
}
}
<?php
class UserNameLabel extends WireData implements Module{
public static function getModuleInfo() {
return array(
'title' => __('UserNameLabel', __FILE__), // Module Title
'version' => 100,
'summary' => __('Overwrite User Name Label', __FILE__), // Module Summary
'autoload' => true