Skip to content

Instantly share code, notes, and snippets.

View jec006's full-sized avatar

Josh Caldwell jec006

View GitHub Profile
@jec006
jec006 / PreviewConditionInterface.php
Created June 28, 2012 20:52
Proposed Condition Interface
<?php
namespace Drupal\sps\Condition;
interface ConditionInterface {
/**
* Provide the config to allow this Condition to construct itself.
*
* @param $config
* An associative array of configuration, generally provided by the
@jec006
jec006 / conditiontest.php
Created July 3, 2012 21:48
How do I test this
<?php
//Basic condition should construct the correct widget and properly get its form
$test_widget = new \Drupal\sps\Test\Widget(array(), $manager);
$state = array();
$widget = $test_widget->getPreviewForm(array(), $state);
$state = array();
$element = $condition->getElement(array(), $state);
$this->assertEqual($subelement, $widget,
@jec006
jec006 / getForm.php
Created July 5, 2012 15:11
Get the drupal form
<?php
/**
* Passthrough from Drupal form to the correct condition for building the preview form
*
* @param $form
* The form array used in hook_form
* @param $form_state
* The form_state array as used in hook_form
*
* @return
@jec006
jec006 / Manager.php
Created July 5, 2012 19:10
The manager getForm function
<?php
/**
* Passthrough from Drupal form to the correct condition for building the preview form
*
* @param $form
* The form array used in hook_form
* @param $form_state
* The form_state array as used in hook_form
*
* @return
@jec006
jec006 / Manager.php
Created July 11, 2012 18:21
RootCondit
/**
* Helper method for getting and causing the root Condition
*
* The Root condition is the use as the basis for the constructing the preview form
* It can be expect that it will be much more complicated then the other conditions
*
* This method select the condition and its config using the config controller.
*
* @return \Drupal\sps\Plugins\ConditionInterface
* the current root condition object
<?php
/**
* Implements ConditionInterface::getElement().
*
* Gets the form for the condition.
*
* @see sps_condition_form_validate_callback
* @see sps_condition_form_submit_callback
*/
public function getElement($element, &$form_state) {
@jec006
jec006 / Manager.php
Created July 12, 2012 19:55
GetForm
<?php
/**
* Passthrough from Drupal form to the correct condition for building the preview form
*
* @param $form
* The form array used in hook_form
* @param $form_state
* The form_state array as used in hook_form
*
* @return
@jec006
jec006 / IIBBaseUnitTest.php
Created July 19, 2012 19:04
'Enable' a module during unit tests
<?php
/**
* Fake enables a module for the purpose of a unit test
*
* @param $name
* The module's machine name (i.e. ctools not Chaos Tools)
*/
protected function enableModule($name) {
$modules = module_list();
<?php
/**
* Implements WidgetInterface::getPreviewForm().
*
* Return a form to collect the date information from the user.
*/
public function getPreviewForm($element, &$form_state) {
$element['#type'] = 'fieldset';
$element['#title'] = empty($this->settings['title']) ? t('Date/Time:') : $this->settings['title'];
$element['#description']= t('Preview nodes published on or after this date.');
<?php
$render = array();
//Good
$render['top'] = array(
'#type' => 'items_list',
'#items' => array(
array('#data' => 'lololol'),
),