Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions eck_shared_entities.module
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
/**
* @file
* ECK shared entities
*
* ECK shared entities allows entities to be marked a shareable across multiple
* host entities.
*/

/**
* Implements hook_ctools_plugin_directory().
Expand Down Expand Up @@ -28,8 +35,13 @@ function eck_shared_entities_permission() {
foreach (Bundle::loadByEntityType($entity_type) as $bundle) {
$permissions += array(
'edit share flag for ' . $entity_type->name . ' ' . $bundle->name . ' entities' => array(
'title' => t('Can edit share flag for ' . $bundle->label . ' entities'),
'description' => t('Allow the user to mark ' . $bundle->label . ' (' . $entity_type->label . ') entities as shared.'),
'title' => t('Can edit share flag for @bundle_label entities', array(
'@bundle_label' => $bundle->label,
)),
'description' => t('Allow the user to mark @bundle_label (@entity_type_label) entities as shared.', array(
'@bundle_label' => $bundle->label,
'@entity_type_label' => $entity_type->label,
)),
),
);
}
Expand Down Expand Up @@ -84,4 +96,4 @@ function eck_shared_entities_query_shared_entities_alter(QueryAlterableInterface
}

$query->condition($filter_condition);
}
}
25 changes: 22 additions & 3 deletions plugins/eck/property_behavior/shared_entity.inc
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
<?php
/**
* @file
* ECK shared entities shared flag property behavior plugin.
*
* Provides a checkbox widget to toggle whether the eck entity can be shared
* across host entities.
*/

$plugin = array(
'label' => 'Shared Entity Flag',
'default_widget' => 'eck_shared_entities_shared_entity_property_widget'
'default_widget' => 'eck_shared_entities_shared_entity_property_widget',
);

/**
* Returns array defining share entity flag widget.
*
* @param string $property
* Name of the property
* @param array $vars
* Additional variables passed to property widget.
*
* @return array
* Return array of defining share entity flag widget.
*/
function eck_shared_entities_shared_entity_property_widget($property, $vars) {
$entity = $vars['entity'];
list($id) = entity_extract_ids($entity->entityType(), $entity);
Expand All @@ -15,8 +34,8 @@ function eck_shared_entities_shared_entity_property_widget($property, $vars) {
'#description' => t('Share this @label entity to make it available for reuse.', array('@label' => $entity->type)),
'#attributes' => array('data-shared-entity-flag-' . $entity->entityType() => $id),
'#weight' => 90,
'#disabled' => !(user_access('edit share flag for all entities') || user_access('edit share flag for ' . $entity->entityType() . ' ' . $entity->type . ' entities'))
'#disabled' => !(user_access('edit share flag for all entities') || user_access('edit share flag for ' . $entity->entityType() . ' ' . $entity->type . ' entities')),
);

return $shared_entity_widget;
}
}
27 changes: 23 additions & 4 deletions plugins/eck/property_behavior/shared_entity_title.inc
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
<?php
/**
* @file
* ECK shared entities shared title property behavior plugin.
*
* Provides a text field storing the title for the shared entity so that it can
* be easily referenced/searched for.
*/

$plugin = array(
'label' => 'Shared Entity Title (required for the shared flag)',
'default_widget' => 'eck_shared_entities_shared_entity_title_property_widget'
'default_widget' => 'eck_shared_entities_shared_entity_title_property_widget',
);

/**
* Returns array defining shared entity title widget.
*
* @param string $property
* Name of the property
* @param array $vars
* Additional variables passed to property widget.
*
* @return array
* Return array of defining share entity title widget.
*/
function eck_shared_entities_shared_entity_title_property_widget($property, $vars) {
$entity = $vars['entity'];
list($id) = entity_extract_ids($entity->entityType(), $entity);
Expand All @@ -19,9 +38,9 @@ function eck_shared_entities_shared_entity_title_property_widget($property, $var
'#states' => array(
'visible' => array(
'[data-shared-entity-flag-' . $entity->entityType() . '="' . $id . '"]:input' => array('checked' => TRUE),
)
)
),
),
);

return $shared_entity_title_widget;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<?php
/**
* @file
* ECK shared entities selection handler class.
*
* Provides a selection handler class allowing for eck entities marked as
* shareable to be referenced.
*/

/**
* ECK shared entities selection handler.
*/
class SharedEntities_SelectionHandler extends EntityReference_SelectionHandler_Generic {
class SharedEntitiesSelectionHandler extends EntityReference_SelectionHandler_Generic {
/**
* Implements EntityReferenceHandler::getInstance().
*/
Expand Down Expand Up @@ -54,10 +62,11 @@ public function getReferencableEntities($match = NULL, $match_operator = 'CONTAI
foreach ($entities as $entity_id => $entity) {
list(,, $bundle) = entity_extract_ids($entity_type, $entity);

// Use shared entity title when available
// Use shared entity title when available.
if (isset($entity->shared_title) && trim($entity->shared_title) !== '') {
$label = trim($entity->shared_title);
} else {
}
else {
$label = $this->getLabel($entity);
}
$options[$bundle][$entity_id] = check_plain($label);
Expand All @@ -66,4 +75,4 @@ public function getReferencableEntities($match = NULL, $match_operator = 'CONTAI

return $options;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php
/**
* @file
* ECK shared entities selection handler for entity reference.
*
* Provides a selection handler for ECK shared entities.
*/

$plugin = array(
'title' => t('Only shared entities'),
'class' => 'SharedEntities_SelectionHandler'
);
'class' => 'SharedEntitiesSelectionHandler',
);