Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
287 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name = ECK Sample Property Behavior | ||
description = A module exposing a simple property behavior, that allows us to set a property through an entities input form | ||
package = ECK | ||
core = 7.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
function eck_spb_ctools_plugin_directory($owner, $plugin_type) { | ||
if ($owner == 'eck' && $plugin_type == 'property_behavior') { | ||
//This is a folder relative to our module. So we are stroing our property behavior plugins in | ||
//a folder called property_behavior which is the plugin type's name. In ECK we stared the plugins in a | ||
//directory under the plugins directory, you can look at eck.module to see the differences in the | ||
//hook_ctools_plugin_directory implementation. | ||
return $plugin_type; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/* | ||
* In a property behavior plugin we want to hijack drupal when it is relavant. In this case we | ||
* want to do it when an entity with a property using our behavior is being manipulated: created, updated, saved, | ||
* shown, etc. | ||
* | ||
* So the plugin implementation in ECK gives an opportunity to do this in multiple places. Currelty this are the | ||
* places where we can do it | ||
* | ||
* entity_save: save gets called everytime the entity is being saved. | ||
* | ||
* entity_insert: insert is a subset of save, in which it only gets called on a new entity | ||
* entity_update: insert is a subset of save, in which it only gets called on an entity that was loaded (edit mode) | ||
* | ||
* We are also allowed to give a default_widget for this behavior, and a default_formatter | ||
* | ||
* As new use cases arise, I am sure that this would be expanded to many other cases. | ||
* | ||
* THE PLUGIN | ||
* | ||
* The plugin is a very simple array with a label, and with the different callbacks that we want to implement. | ||
* | ||
* In this example we are using the default_widget, default_formatter, and the save options. | ||
* After the plugin array we give the functions that we want call at these different stages. | ||
*/ | ||
|
||
$plugin = array( | ||
'label' => "ECK SPB", | ||
'entity_save' => 'eck_spb_entity_save', | ||
'default_widget' => 'eck_spb_widget', | ||
'default_formatter' => 'eck_spb_formatter' | ||
); | ||
|
||
function eck_spb_entity_save($entity, $property, $value = NULL){ | ||
$entity->{$property} = $value; | ||
} | ||
|
||
/** | ||
* Define a rendarble array to input a value for the property using this behavior | ||
* | ||
* @param $entity: and entity object that contains the property for which this behavior is relevant | ||
* @param $property: the name of the property (string) that is using this behavior | ||
* | ||
* @return a rendarable array use when the input form for this entity is displayed | ||
*/ | ||
function eck_spb_widget($entity, $property){ | ||
$title = _eck_spb_extract_title($entity, $property); | ||
return array( | ||
'#type' => 'textfield', | ||
'#title' => ucfirst($property), | ||
'#default_value' => $title | ||
); | ||
} | ||
|
||
function eck_spb_formatter($entity, $property){ | ||
$title = _eck_spb_extract_title($entity, $property); | ||
return array('#markup' => "<h1>{$title}</h1>"); | ||
} | ||
|
||
function _eck_spb_extract_title($entity, $property){ | ||
$title = ""; | ||
if(isset($entity->{$property})){ | ||
$title = $entity->{$property}; | ||
} | ||
|
||
return $title; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.