Date: Sat, 19 Oct 2013 23:04:16 -0500
Subject: [PATCH 341/629] Converted admin/structure/flags to a list entity
controller.
---
flag.module | 18 +++-
flag.routing.yml | 14 +--
.../flag/Controller/FlagAdminController.php | 59 ------------
.../flag/Controller/FlagListController.php | 44 +++++++++
lib/Drupal/flag/Entity/Flag.php | 22 +++--
lib/Drupal/flag/FlagInterface.php | 4 +
lib/Drupal/flag/Form/FlagAddForm.php | 94 ++++++++++---------
7 files changed, 134 insertions(+), 121 deletions(-)
delete mode 100644 lib/Drupal/flag/Controller/FlagAdminController.php
diff --git a/flag.module b/flag.module
index 42e2e09..4e083bc 100644
--- a/flag.module
+++ b/flag.module
@@ -183,12 +183,13 @@ function flag_menu() {
$items[FLAG_ADMIN_PATH] = array(
'title' => 'Flags',
- 'route_name' => 'flag_settings',
+ // 'route_name' => 'flag_settings',
'description' => 'Configure flags for marking content with arbitrary information (such as offensive or bookmarked).',
- );
- $items[FLAG_ADMIN_PATH . '/list'] = array(
- 'title' => 'List',
- 'type' => MENU_DEFAULT_LOCAL_TASK,
+// );
+// $items[FLAG_ADMIN_PATH . '/list'] = array(
+// 'title' => 'List',
+// 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'route_name' => 'flag.flag_list',
'weight' => -10,
);
$items[FLAG_ADMIN_PATH . '/add'] = array(
@@ -1793,6 +1794,10 @@ function flag_get_flag($name = NULL, $fid = NULL) {
return FALSE;
}
+function flag_load_by_id($id) {
+ return entity_load('flag_flag', $id);
+}
+
/**
* List all flags available.
*
@@ -1811,6 +1816,8 @@ function flag_get_flag($name = NULL, $fid = NULL) {
* An array of the structure [fid] = flag_object.
*/
function flag_get_flags($entity_type = NULL, $content_subtype = NULL, $account = NULL) {
+ return entity_load_multiple('flag_flag');
+/**
$flags = &drupal_static(__FUNCTION__);
// Retrieve a list of all flags, regardless of the parameters.
@@ -1889,6 +1896,7 @@ function flag_get_flags($entity_type = NULL, $content_subtype = NULL, $account =
}
return $filtered_flags;
+ */
}
/**
diff --git a/flag.routing.yml b/flag.routing.yml
index a6f8acf..e27d89f 100644
--- a/flag.routing.yml
+++ b/flag.routing.yml
@@ -1,9 +1,9 @@
-flag_settings:
- path: '/admin/structure/flags'
- defaults:
- _content: '\Drupal\flag\Controller\FlagAdminController::content'
- requirements:
- _permission: 'administer flags'
+#flag_settings:
+# path: '/admin/structure/flags'
+# defaults:
+# _content: '\Drupal\flag\Controller\FlagAdminController::content'
+# requirements:
+# _permission: 'administer flags'
flag_add_page:
path: '/admin/structure/flags/add'
@@ -13,7 +13,7 @@ flag_add_page:
_permission: 'administer flags'
flag.flag_list:
- path: '/admin/structure/flagz/add'
+ path: '/admin/structure/flags'
defaults:
_entity_list: 'flag_flag'
requirements:
diff --git a/lib/Drupal/flag/Controller/FlagAdminController.php b/lib/Drupal/flag/Controller/FlagAdminController.php
deleted file mode 100644
index 7251a0f..0000000
--- a/lib/Drupal/flag/Controller/FlagAdminController.php
+++ /dev/null
@@ -1,59 +0,0 @@
- $flags, 'default_flags' => $default_flags));
-
- if (!module_exists('views')) {
- $output .= '' . t('The Views module is not installed, or not enabled. It is recommended that you install the Views module to be able to easily produce lists of flagged content.', array('@views-url' => url('http://drupal.org/project/views'))) . '
';
- }
- else {
- $output .= '';
- $output .= t('Lists of flagged content can be displayed using views. You can configure these in the Views administration section.', array('@views-url' => url('admin/structure/views')));
- if (flag_get_flag('bookmarks')) {
- $output .= ' ' . t('Flag module automatically provides a few default views for the bookmarks flag. You can use these as templates by cloning these views and then customizing as desired.', array('@views-url' => url('admin/structure/views', array('query' => array('tag' => 'flag')))));
- }
- $output .= ' ' . t('The Flag module handbook contains extensive documentation on creating customized views using flags.', array('@flag-handbook-url' => 'http://drupal.org/handbook/modules/flag', '@customize-url' => 'http://drupal.org/node/296954'));
- $output .= '
';
- }
-
- if (!module_exists('flag_actions')) {
- $output .= '' . t('Flagging an item may trigger actions. However, you don\'t have the Flag actions module enabled, so you won\'t be able to enjoy this feature.', array('@actions-url' => url(FLAG_ADMIN_PATH . '/actions'), '@modules-url' => url('admin/modules'))) . '
';
- }
- else {
- $output .= '' . t('Flagging an item may trigger actions.', array('@actions-url' => url(FLAG_ADMIN_PATH . '/actions'))) . '
';
- }
-
- if (!module_exists('rules')) {
- $output .= '' . t('Flagging an item may trigger rules. However, you don\'t have the Rules module enabled, so you won\'t be able to enjoy this feature. The Rules module is a more extensive solution than Flag actions.', array('@rules-url' => url('http://drupal.org/node/407070'))) . '
';
- }
- else {
- $output .= '' . t('Flagging an item may trigger rules.', array('@rules-url' => url('admin/config/workflow/rules'))) . '
';
- }
-
- $output .= '' . t('To learn about the various ways to use flags, please check out the Flag module handbook.', array('@handbook-url' => 'http://drupal.org/handbook/modules/flag')) . '
';
-
- return array(
- '#type' => 'markup',
- '#markup' => $output,
- );
- }
-
-}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Controller/FlagListController.php b/lib/Drupal/flag/Controller/FlagListController.php
index 3f78170..d77173e 100644
--- a/lib/Drupal/flag/Controller/FlagListController.php
+++ b/lib/Drupal/flag/Controller/FlagListController.php
@@ -23,6 +23,50 @@ public function buildHeader() {
return $header + parent::buildHeader();
}
+ public function render() {
+ $build['table'] = parent::render();
+
+ $output = "";
+
+ //@todo Move this too hook_help()?
+ if (!module_exists('views')) {
+ $output .= '' . t('The Views module is not installed, or not enabled. It is recommended that you install the Views module to be able to easily produce lists of flagged content.', array('@views-url' => url('http://drupal.org/project/views'))) . '
';
+ }
+ else {
+ $output .= '';
+ $output .= t('Lists of flagged content can be displayed using views. You can configure these in the Views administration section.', array('@views-url' => url('admin/structure/views')));
+ if (flag_get_flag('bookmarks')) {
+ $output .= ' ' . t('Flag module automatically provides a few default views for the bookmarks flag. You can use these as templates by cloning these views and then customizing as desired.', array('@views-url' => url('admin/structure/views', array('query' => array('tag' => 'flag')))));
+ }
+ $output .= ' ' . t('The Flag module handbook contains extensive documentation on creating customized views using flags.', array('@flag-handbook-url' => 'http://drupal.org/handbook/modules/flag', '@customize-url' => 'http://drupal.org/node/296954'));
+ $output .= '
';
+ }
+
+ if (!module_exists('flag_actions')) {
+ $output .= '' . t('Flagging an item may trigger actions. However, you don\'t have the Flag actions module enabled, so you won\'t be able to enjoy this feature.', array('@actions-url' => url(FLAG_ADMIN_PATH . '/actions'), '@modules-url' => url('admin/modules'))) . '
';
+ }
+ else {
+ $output .= '' . t('Flagging an item may trigger actions.', array('@actions-url' => url(FLAG_ADMIN_PATH . '/actions'))) . '
';
+ }
+
+ if (!module_exists('rules')) {
+ $output .= '' . t('Flagging an item may trigger rules. However, you don\'t have the Rules module enabled, so you won\'t be able to enjoy this feature. The Rules module is a more extensive solution than Flag actions.', array('@rules-url' => url('http://drupal.org/node/407070'))) . '
';
+ }
+ else {
+ $output .= '' . t('Flagging an item may trigger rules.', array('@rules-url' => url('admin/config/workflow/rules'))) . '
';
+ }
+
+ $output .= '' . t('To learn about the various ways to use flags, please check out the Flag module handbook.', array('@handbook-url' => 'http://drupal.org/handbook/modules/flag')) . '
';
+
+
+ $build['markup'] = array(
+ '#type' => 'markup',
+ '#markup' => $output,
+ );
+
+ return $build;
+ }
+
/**
* Overrides Drupal\Core\Entity\EntityListController::buildRow().
*/
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index af22934..141ebbe 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -66,13 +66,6 @@ class Flag extends ConfigEntityBase implements FlagInterface {
*/
public $entity_type = NULL;
- /**
- * The flag's "machine readable" name.
- *
- * @var string
- */
- public $name = '';
-
/**
* The flag label.
*
@@ -87,6 +80,13 @@ class Flag extends ConfigEntityBase implements FlagInterface {
*/
public $is_global = FALSE;
+ /**
+ * Whether this flag is enabled.
+ *
+ * @var bool
+ */
+ public $enabled = TRUE;
+
/**
* The sub-types, AKA bundles, this flag applies to.
*
@@ -159,4 +159,12 @@ class Flag extends ConfigEntityBase implements FlagInterface {
*/
public $weight = 0;
+ public function enable() {
+ $this->enabled = TRUE;
+ }
+
+ public function disable() {
+ $this->enabled = FALSE;
+ }
+
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/FlagInterface.php b/lib/Drupal/flag/FlagInterface.php
index ffa4d8c..0113880 100644
--- a/lib/Drupal/flag/FlagInterface.php
+++ b/lib/Drupal/flag/FlagInterface.php
@@ -14,4 +14,8 @@ interface FlagInterface extends ConfigEntityInterface {
// todo: Add getters and setters as necessary.
+ public function enable();
+
+ public function disable();
+
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Form/FlagAddForm.php b/lib/Drupal/flag/Form/FlagAddForm.php
index d23d043..67b14ef 100644
--- a/lib/Drupal/flag/Form/FlagAddForm.php
+++ b/lib/Drupal/flag/Form/FlagAddForm.php
@@ -13,8 +13,8 @@
class FlagAddForm extends EntityFormController {
- public function form(array $form, array &$form_state, $entity_type = NULL) {
- $form = parent::form($form, $form_state);
+ public function buildForm(array $form, array &$form_state, $entity_type = NULL) {
+ $form = parent::buildForm($form, $form_state);
$flag = $this->entity; //\Drupal\flag\Handlers\AbstractFlag::factory_by_entity_type($entity_type);
@@ -25,29 +25,28 @@ public function form(array $form, array &$form_state, $entity_type = NULL) {
$form['#flag'] = $flag;
- $form['#flag_name'] = $flag->name;
+ $form['#flag_name'] = $flag->id;
- $form['title'] = array(
+ $form['label'] = array(
'#type' => 'textfield',
- '#title' => t('Title'),
- '#default_value' => $flag->title,
+ '#title' => t('Label'),
+ '#default_value' => $flag->label(),
'#description' => t('A short, descriptive title for this flag. It will be used in administrative interfaces to refer to this flag, and in page titles and menu items of some views this module provides (theses are customizable, though). Some examples could be Bookmarks, Favorites, or Offensive.', array('@insite-views-url' => url('admin/structure/views'))),
'#maxlength' => 255,
'#required' => TRUE,
'#weight' => -3,
);
- $form['name'] = array(
+ $form['id'] = array(
'#type' => 'machine_name',
'#title' => t('Machine name'),
- '#default_value' => $flag->name,
+ '#default_value' => $flag->id(),
'#description' => t('The machine-name for this flag. It may be up to 32 characters long and may only contain lowercase letters, underscores, and numbers. It will be used in URLs and in all API calls.'),
- '#maxlength' => 32,
'#weight' => -2,
'#machine_name' => array(
- 'exists' => 'flag_get_flag',
- 'source' => array('title'),
+ 'exists' => 'flag_load_by_id',
),
+ '#disabled' => !$flag->isNew(),
);
$form['global'] = array(
@@ -61,11 +60,11 @@ public function form(array $form, array &$form_state, $entity_type = NULL) {
// there are too many unpleasant consequences in either direction.
// @todo: Allow this, but with a confirmation form, assuming anyone actually
// needs this feature.
- if (!empty($flag->id) && flag_get_flag_counts($flag->name)) {
+/* if (!empty($flag->id) && flag_get_flag_counts($flag->id)) {
$form['global']['#disabled'] = TRUE;
$form['global']['#description'] .= '
' . t('This setting cannot be changed when flaggings exist for this flag.');
}
-
+*/
$form['messages'] = array(
'#type' => 'fieldset',
'#title' => t('Messages'),
@@ -141,11 +140,17 @@ public function form(array $form, array &$form_state, $entity_type = NULL) {
'#weight' => 10,
);
+ $bundles = entity_get_bundles($entity_type);
+ $entity_bundles = array();
+ foreach ($bundles as $bundle_id => $bundle_row) {
+ $entity_bundles[$bundle_id] = $bundle_row['label'];
+ }
+
// Flag classes will want to override this form element.
$form['access']['types'] = array(
'#type' => 'checkboxes',
'#title' => t('Flaggable types'),
- '#options' => array(),
+ '#options' => $entity_bundles,
'#default_value' => $flag->types,
'#description' => t('Check any sub-types that this flag may be used on.'),
'#required' => TRUE,
@@ -221,7 +226,7 @@ public function form(array $form, array &$form_state, $entity_type = NULL) {
'#tree' => FALSE,
'#weight' => 20,
// @todo: Move flag_link_type_options_states() into controller?
- '#after_build' => array('flag_link_type_options_states'),
+// '#after_build' => array('flag_link_type_options_states'),
);
$form['display']['link_type'] = array(
@@ -229,7 +234,7 @@ public function form(array $form, array &$form_state, $entity_type = NULL) {
'#title' => t('Link type'),
'#options' => _flag_link_type_options(),
// @todo: Move flag_check_link_types into controller?
- '#after_build' => array('flag_check_link_types'),
+// '#after_build' => array('flag_check_link_types'),
'#default_value' => $flag->link_type,
// Give this a high weight so additions by the flag classes for entity-
// specific options go above.
@@ -265,7 +270,7 @@ public function form(array $form, array &$form_state, $entity_type = NULL) {
'#id' => 'link-options-confirm',
'#weight' => 21,
);
-/*
+
$form['display']['link_options_confirm']['flag_confirmation'] = array(
'#type' => 'textfield',
'#title' => t('Flag confirmation message'),
@@ -279,18 +284,6 @@ public function form(array $form, array &$form_state, $entity_type = NULL) {
'#default_value' => isset($flag->unflag_confirmation) ? $flag->unflag_confirmation : '',
'#description' => t('Message displayed if the user has clicked the "unflag this" link and confirmation is required. Usually presented in the form of a question such as, "Are you sure you want to unflag this content?"'),
);
-*/
- $form['actions'] = array(
- '#type' => 'actions',
- );
-
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save flag'),
- // We put this button on the form before calling $flag->options_form()
- // to give the flag handler a chance to remove it (e.g. flag_broken).
- '#weight' => 999,
- );
// Add our process handler to disable access to locked properties.
//@todo: Fix reference to flag_form_locked_process, or replace entirely.
@@ -303,13 +296,19 @@ public function form(array $form, array &$form_state, $entity_type = NULL) {
return $form;
}
+ protected function actions(array $form, array &$form_state) {
+ $actions = parent::actions($form, $form_state);
+ $actions['submit']['#value'] = t('Save Flag');
+ return $actions;
+ }
+
/**
* Overrides Drupal\Core\Entity\EntityFormController::validate().
*/
public function validate(array $form, array &$form_state) {
parent::validate($form, $form_state);
- $form_state['values']['title'] = trim($form_state['values']['title']);
+ $form_state['values']['label'] = trim($form_state['values']['label']);
$form_values = $form_state['values'];
if ($form_values['link_type'] == 'confirm') {
@@ -320,26 +319,32 @@ public function validate(array $form, array &$form_state) {
form_set_error('unflag_confirmation', t('An unflag confirmation message is required when using the confirmation link type.'));
}
}
-
-
- $flag = $form['#flag'];
-// @todo: Move this into the flag controller here.
-// $errors = $flag->validate();
- foreach ($errors as $field => $field_errors) {
- foreach ($field_errors as $error) {
- form_set_error($field, $error['message']);
- }
+/*
+ if (!preg_match('/^[a-z_][a-z0-9_]*$/', $form_values['id'])) {
+ form_set_error('label', t('The flag name may only contain lowercase letters, underscores, and numbers.'));
}
+*/
}
+ /**
+ * Overrides Drupal\Core\Entity\EntityFormController::save().
+ */
public function save(array $form, array &$form_state) {
$flag = $this->entity;
$form_state['values']['title'] = trim($form_state['values']['title']);
+ $flag->enable();
$status = $flag->save();
-// $flag->enable();
- drupal_set_message(t('Flag @title has been saved.', array('@title' => $flag->get_title())));
+ $uri = $flag->uri();
+ if ($status == SAVED_UPDATED) {
+ drupal_set_message(t('Flag %label has been updated.', array('%label' => $flag->label())));
+ watchdog('flag', 'Flag %label has been updated.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'] . '/edit'));
+ }
+ else {
+ drupal_set_message(t('Flag %label has been added.', array('%label' => $flag->label())));
+ watchdog('flag', 'Flag %label has been added.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'] . '/edit'));
+ }
// We clear caches more vigorously if the flag was new.
// _flag_clear_cache($flag->entity_type, !empty($flag->is_new));
@@ -351,7 +356,7 @@ public function save(array $form, array &$form_state) {
// for different flag types: http://drupal.org/node/879988
// If the flag machine name as changed, clean up all the obsolete permissions.
- if ($flag->name != $form['#flag_name']) {
+ if ($flag->id != $form['#flag_name']) {
$old_name = $form['#flag_name'];
$permissions = array("flag $old_name", "unflag $old_name");
foreach (array_keys(user_roles()) as $rid) {
@@ -371,9 +376,12 @@ public function save(array $form, array &$form_state) {
// @todo: when we add database caching for flags we'll have to clear the
// cache again here.
- $form_state['redirect'] = FLAG_ADMIN_PATH;
+ $form_state['redirect'] = 'admin/structure/flags';
}
+ /**
+ * Overrides Drupal\Core\Entity\EntityFormController::delete().
+ */
public function delete(array $form, array &$form_state) {
$form_state['redirect'] = 'admin/structure/flag';
}
From e391d948f5b7508a6d029fcd3d723298a90947a0 Mon Sep 17 00:00:00 2001
From: Tess
Date: Sun, 20 Oct 2013 23:00:45 -0500
Subject: [PATCH 342/629] Added Flagging content entity.
---
flag.module | 2 +-
flag.routing.yml | 14 +-
includes/flag.admin.inc | 477 ------------------
lib/Drupal/flag/Annotation/Flag.php | 2 +-
.../flag/Controller/FlagListController.php | 28 +-
lib/Drupal/flag/Entity/Flag.php | 5 +-
lib/Drupal/flag/Entity/Flagging.php | 84 +++
lib/Drupal/flag/FlaggingInterface.php | 16 +
8 files changed, 130 insertions(+), 498 deletions(-)
create mode 100644 lib/Drupal/flag/Entity/Flagging.php
create mode 100644 lib/Drupal/flag/FlaggingInterface.php
diff --git a/flag.module b/flag.module
index 4e083bc..cdc25b9 100644
--- a/flag.module
+++ b/flag.module
@@ -372,7 +372,7 @@ function flag_load($flag_name, $include_disabled = FALSE) {
*/
function _flag_menu_title($flag) {
// The following conditional it to handle a D7 bug (@todo: link).
- return $flag ? $flag->get_title() : '';
+ return $flag ? $flag->label : '';
}
/**
diff --git a/flag.routing.yml b/flag.routing.yml
index e27d89f..efda13c 100644
--- a/flag.routing.yml
+++ b/flag.routing.yml
@@ -1,10 +1,3 @@
-#flag_settings:
-# path: '/admin/structure/flags'
-# defaults:
-# _content: '\Drupal\flag\Controller\FlagAdminController::content'
-# requirements:
-# _permission: 'administer flags'
-
flag_add_page:
path: '/admin/structure/flags/add'
defaults:
@@ -26,6 +19,13 @@ flag_add:
requirements:
_permission: 'administer flags'
+flag_edit:
+ path: '/admin/structure/flags/manage/{entity_type}'
+ defaults:
+ _entity_form: flag_flag.edit
+ requirements:
+ _permission: 'administer flags'
+
flag_import:
path: '/admin/structure/flags/import'
defaults:
diff --git a/includes/flag.admin.inc b/includes/flag.admin.inc
index 64fb23b..555e5d4 100644
--- a/includes/flag.admin.inc
+++ b/includes/flag.admin.inc
@@ -8,22 +8,6 @@
use Drupal\flag\Handlers\AbstractFlag;
use Drupal\flag\Handlers\BrokenFlag;
-/**
- * Flag administration page. Display a list of existing flags.
- */
-/*
-function flag_admin_page() {
- $flags = flag_get_flags();
- $default_flags = flag_get_default_flags(TRUE);
- $flag_admin_listing = drupal_get_form('flag_admin_listing', $flags);
- return theme('flag_admin_page', array(
- 'flags' => $flags,
- 'default_flags' => $default_flags,
- 'flag_admin_listing' => $flag_admin_listing,
- ));
-}
-*/
-
/**
* A form for ordering the weights of all the active flags in the system.
*/
@@ -175,396 +159,6 @@ function theme_flag_admin_listing_disabled($variables) {
return $output;
}
-/**
- * Theme the output for the main flag administration page.
- */
-function theme_flag_admin_page($variables) {
- $flags = $variables['flags'];
- $default_flags = $variables['default_flags'];
-
- $output = '';
-
- $output .= drupal_render($variables['flag_admin_listing']);
- $output .= theme('flag_admin_listing_disabled', array('flags' => $flags, 'default_flags' => $default_flags));
-
- if (!module_exists('views')) {
- $output .= '' . t('The Views module is not installed, or not enabled. It is recommended that you install the Views module to be able to easily produce lists of flagged content.', array('@views-url' => url('http://drupal.org/project/views'))) . '
';
- }
- else {
- $output .= '';
- $output .= t('Lists of flagged content can be displayed using views. You can configure these in the Views administration section.', array('@views-url' => url('admin/structure/views')));
- if (flag_get_flag('bookmarks')) {
- $output .= ' ' . t('Flag module automatically provides a few default views for the bookmarks flag. You can use these as templates by cloning these views and then customizing as desired.', array('@views-url' => url('admin/structure/views', array('query' => array('tag' => 'flag')))));
- }
- $output .= ' ' . t('The Flag module handbook contains extensive documentation on creating customized views using flags.', array('@flag-handbook-url' => 'http://drupal.org/handbook/modules/flag', '@customize-url' => 'http://drupal.org/node/296954'));
- $output .= '
';
- }
-
- if (!module_exists('flag_actions')) {
- $output .= '' . t('Flagging an item may trigger actions. However, you don\'t have the Flag actions module enabled, so you won\'t be able to enjoy this feature.', array('@actions-url' => url(FLAG_ADMIN_PATH . '/actions'), '@modules-url' => url('admin/modules'))) . '
';
- }
- else {
- $output .= '' . t('Flagging an item may trigger actions.', array('@actions-url' => url(FLAG_ADMIN_PATH . '/actions'))) . '
';
- }
-
- if (!module_exists('rules')) {
- $output .= '' . t('Flagging an item may trigger rules. However, you don\'t have the Rules module enabled, so you won\'t be able to enjoy this feature. The Rules module is a more extensive solution than Flag actions.', array('@rules-url' => url('http://drupal.org/node/407070'))) . '
';
- }
- else {
- $output .= '' . t('Flagging an item may trigger rules.', array('@rules-url' => url('admin/config/workflow/rules'))) . '
';
- }
-
- $output .= '' . t('To learn about the various ways to use flags, please check out the Flag module handbook.', array('@handbook-url' => 'http://drupal.org/handbook/modules/flag')) . '
';
-
- return $output;
-}
-
-/**
- * Menu callback for adding a new flag.
- *
- * @param $entity_type
- * The entity type for the new flag, taken from the path argument. If not
- * present (i.e., '/add'), a form showing all possible flag types is shown.
- * Otherwise, this shows a form for adding af flag the given type.
- *
- * @see flag_add_form()
- * @see flag_form()
- *//*
-function flag_add_page($entity_type = NULL) {
- if (isset($entity_type)) {
- $flag = \Drupal\flag\Handlers\AbstractFlag::factory_by_entity_type($entity_type);
- // Mark the flag as new.
- $flag->is_new = TRUE;
- $type_info = flag_fetch_definition($entity_type);
- drupal_set_title(t('Add new @type flag', array('@type' => $type_info['title'])));
- return drupal_get_form('flag_form', $flag);
- }
-
- drupal_set_title(t('Select flag type'));
- return drupal_get_form('flag_add_form');
-}
-*/
-/**
- * Present a form for creating a new flag, setting the type of flag.
- *//*
-function flag_add_form($form, &$form_state) {
- $types = array();
- foreach (flag_fetch_definition() as $type => $info) {
- $types[$type] = $info['title'] . '' . $info['description'] . '
';
- }
-
- $form['type'] = array(
- '#type' => 'radios',
- '#title' => t('Flag type'),
- '#default_value' => 'node',
- '#description' => t('The type of object this flag will affect. This cannot be changed once the flag is created.'),
- '#required' => TRUE,
- '#options' => $types,
- );
-
- $form['actions'] = array(
- '#type' => 'actions',
- );
-
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Continue'),
- );
-
- return $form;
-}
-
-function flag_add_form_validate($form, &$form_state) {
- $flag = AbstractFlag::factory_by_entity_type($form_state['values']['type']);
- if (get_class($flag) == 'BrokenFlag') {
- form_set_error('type', t("This flag type, %type, isn't valid.", array('%type' => $form_state['values']['type'])));
- }
-}
-
-function flag_add_form_submit($form, &$form_state) {
- $form_state['redirect'] = FLAG_ADMIN_PATH . '/add/' . $form_state['values']['type'];
-}
-*/
-/**
- * Add/Edit flag page.
- *//*
-function flag_form($form, &$form_state, $flag) {
- $form['#flag'] = $flag;
- $form['#flag_name'] = $flag->name;
-
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => t('Title'),
- '#default_value' => $flag->title,
- '#description' => t('A short, descriptive title for this flag. It will be used in administrative interfaces to refer to this flag, and in page titles and menu items of some views this module provides (theses are customizable, though). Some examples could be Bookmarks, Favorites, or Offensive.', array('@insite-views-url' => url('admin/structure/views'))),
- '#maxlength' => 255,
- '#required' => TRUE,
- '#weight' => -3,
- );
-
- $form['name'] = array(
- '#type' => 'machine_name',
- '#title' => t('Machine name'),
- '#default_value' => $flag->name,
- '#description' => t('The machine-name for this flag. It may be up to 32 characters long and may only contain lowercase letters, underscores, and numbers. It will be used in URLs and in all API calls.'),
- '#maxlength' => 32,
- '#weight' => -2,
- '#machine_name' => array(
- 'exists' => 'flag_get_flag',
- 'source' => array('title'),
- ),
- );
-
- $form['global'] = array(
- '#type' => 'checkbox',
- '#title' => t('Global flag'),
- '#default_value' => $flag->global,
- '#description' => t('If checked, flag is considered "global" and each entity is either flagged or not. If unchecked, each user has individual flags on entities.'),
- '#weight' => -1,
- );
- // Don't allow the 'global' checkbox to be changed when flaggings exist:
- // there are too many unpleasant consequences in either direction.
- // @todo: Allow this, but with a confirmation form, assuming anyone actually
- // needs this feature.
- if (!empty($flag->fid) && flag_get_flag_counts($flag->name)) {
- $form['global']['#disabled'] = TRUE;
- $form['global']['#description'] .= '
' . t('This setting cannot be changed when flaggings exist for this flag.');
- }
-
- $form['messages'] = array(
- '#type' => 'fieldset',
- '#title' => t('Messages'),
- );
-
- $form['messages']['flag_short'] = array(
- '#type' => 'textfield',
- '#title' => t('Flag link text'),
- '#default_value' => !empty($flag->flag_short) ? $flag->flag_short : t('Flag this item'),
- '#description' => t('The text for the "flag this" link for this flag.'),
- '#required' => TRUE,
- );
-
- $form['messages']['flag_long'] = array(
- '#type' => 'textfield',
- '#title' => t('Flag link description'),
- '#default_value' => $flag->flag_long,
- '#description' => t('The description of the "flag this" link. Usually displayed on mouseover.'),
- );
-
- $form['messages']['flag_message'] = array(
- '#type' => 'textfield',
- '#title' => t('Flagged message'),
- '#default_value' => $flag->flag_message,
- '#description' => t('Message displayed after flagging content. If JavaScript is enabled, it will be displayed below the link. If not, it will be displayed in the message area.'),
- );
-
- $form['messages']['unflag_short'] = array(
- '#type' => 'textfield',
- '#title' => t('Unflag link text'),
- '#default_value' => !empty($flag->unflag_short) ? $flag->unflag_short : t('Unflag this item'),
- '#description' => t('The text for the "unflag this" link for this flag.'),
- '#required' => TRUE,
- );
-
- $form['messages']['unflag_long'] = array(
- '#type' => 'textfield',
- '#title' => t('Unflag link description'),
- '#default_value' => $flag->unflag_long,
- '#description' => t('The description of the "unflag this" link. Usually displayed on mouseover.'),
- );
-
- $form['messages']['unflag_message'] = array(
- '#type' => 'textfield',
- '#title' => t('Unflagged message'),
- '#default_value' => $flag->unflag_message,
- '#description' => t('Message displayed after content has been unflagged. If JavaScript is enabled, it will be displayed below the link. If not, it will be displayed in the message area.'),
- );
-
- $form['messages']['tokens_help'] = array(
- '#title' => t('Token replacement'),
- '#type' => 'fieldset',
- '#description' =>
- '' . t('The above six texts may contain any of the tokens listed below. For example, "Flag link text" could be entered as:') . '
' .
- theme('item_list', array(
- 'items' => array(
- t('Add <em>[node:title]</em> to your favorites'),
- t('Add this [node:type] to your favorites'),
- t('Vote for this proposal ([node:flag-vote-count] people have already done so)'),
- ),
- 'attributes' => array('class' => 'token-examples'),
- )) .
- '' . t('These tokens will be replaced with the appropriate fields from the node (or user, or comment).') . '
' .
- theme('flag_tokens_browser', array('types' => $flag->get_labels_token_types())),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
-
- $form['access'] = array(
- '#type' => 'fieldset',
- '#title' => t('Flag access'),
- '#tree' => FALSE,
- '#weight' => 10,
- );
-
- // Flag classes will want to override this form element.
- $form['access']['types'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Flaggable types'),
- '#options' => array(),
- '#default_value' => $flag->types,
- '#description' => t('Check any sub-types that this flag may be used on.'),
- '#required' => TRUE,
- '#weight' => 10,
- );
-
- // Disabled access breaks checkboxes unless #value is hard coded.
- if (!empty($flag->locked['types'])) {
- $form['access']['types']['#value'] = $flag->types;
- }
-
- // Load the user permissions into the flag.
- if (isset($flag->fid)) {
- $flag->fetch_roles();
- }
- elseif (isset($flag->import_roles)) {
- // Convert the roles data from old API 2 flags that have been run through
- // the update system.
- // @see FlagUpdate_2::update()
- $flag->roles = $flag->import_roles;
- }
- else {
- // For new flags, provide a reasonable default value.
- $flag->roles = array(
- 'flag' => array(DRUPAL_AUTHENTICATED_RID),
- 'unflag' => array(DRUPAL_AUTHENTICATED_RID),
- );
- }
-
- $form['access']['roles'] = array(
- '#title' => t('Roles that may use this flag'),
- '#description' => t('Users may only unflag content if they have access to flag the content initially. Checking authenticated user will allow access for all logged-in users.'),
- '#theme' => 'flag_form_roles',
- '#theme_wrappers' => array('form_element'),
- '#weight' => -2,
- '#attached' => array(
- 'js' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.js'),
- 'css' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.css'),
- ),
- );
- if (module_exists('session_api')) {
- $form['access']['roles']['#description'] .= ' ' . t('Support for anonymous users is being provided by Session API.');
- }
- else {
- $form['access']['roles']['#description'] .= ' ' . t('Anonymous users may flag content if the Session API module is installed.');
- }
-
- $form['access']['roles']['flag'] = array(
- '#type' => 'checkboxes',
- '#options' => user_roles(!module_exists('session_api')),
- '#default_value' => $flag->roles['flag'],
- '#parents' => array('roles', 'flag'),
- );
- $form['access']['roles']['unflag'] = array(
- '#type' => 'checkboxes',
- '#options' => user_roles(!module_exists('session_api')),
- '#default_value' => $flag->roles['unflag'],
- '#parents' => array('roles', 'unflag'),
- );
-
- $form['access']['unflag_denied_text'] = array(
- '#type' => 'textfield',
- '#title' => t('Unflag not allowed text'),
- '#default_value' => $flag->unflag_denied_text,
- '#description' => t('If a user is allowed to flag but not unflag, this text will be displayed after flagging. Often this is the past-tense of the link text, such as "flagged".'),
- '#weight' => -1,
- );
-
- $form['display'] = array(
- '#type' => 'fieldset',
- '#title' => t('Display options'),
- '#description' => t('Flags are usually controlled through links that allow users to toggle their behavior. You can choose how users interact with flags by changing options here. It is legitimate to have none of the following checkboxes ticked, if, for some reason, you wish to place the the links on the page yourself.', array('@placement-url' => 'http://drupal.org/node/295383')),
- '#tree' => FALSE,
- '#weight' => 20,
- '#after_build' => array('flag_link_type_options_states'),
- );
-
- $form['display']['link_type'] = array(
- '#type' => 'radios',
- '#title' => t('Link type'),
- '#options' => _flag_link_type_options(),
- '#after_build' => array('flag_check_link_types'),
- '#default_value' => $flag->link_type,
- // Give this a high weight so additions by the flag classes for entity-
- // specific options go above.
- '#weight' => 18,
- '#attached' => array(
- 'js' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.js'),
- ),
- '#attributes' => array(
- 'class' => array('flag-link-options'),
- ),
- );
- // Add the descriptions to each ratio button element. These attach to the
- // elements when FormAPI expands them.
- foreach (_flag_link_type_descriptions() as $key => $description) {
- $form['display']['link_type'][$key]['#description'] = $description;
- }
-
- $form['display']['link_options_intro'] = array(
- // This is a hack to allow a markup element to use FormAPI states.
- // @see http://www.bywombats.com/blog/06-25-2011/using-containers-states-enabled-markup-form-elements
- '#type' => 'container',
- '#children' => '' . t('The selected link type may require these additional settings:') . '
',
- '#weight' => 20,
- );
-
- $form['display']['link_options_confirm'] = array(
- '#type' => 'fieldset',
- '#title' => t('Options for the "Confirmation form" link type'),
- // Any "link type" provider module must put its settings fields inside
- // a fieldset whose HTML ID is link-options-LINKTYPE, where LINKTYPE is
- // the machine-name of the link type. This is necessary for the
- // radiobutton's JavaScript dependency feature to work.
- '#id' => 'link-options-confirm',
- '#weight' => 21,
- );
-
- $form['display']['link_options_confirm']['flag_confirmation'] = array(
- '#type' => 'textfield',
- '#title' => t('Flag confirmation message'),
- '#default_value' => isset($flag->flag_confirmation) ? $flag->flag_confirmation : '',
- '#description' => t('Message displayed if the user has clicked the "flag this" link and confirmation is required. Usually presented in the form of a question such as, "Are you sure you want to flag this content?"'),
- );
-
- $form['display']['link_options_confirm']['unflag_confirmation'] = array(
- '#type' => 'textfield',
- '#title' => t('Unflag confirmation message'),
- '#default_value' => isset($flag->unflag_confirmation) ? $flag->unflag_confirmation : '',
- '#description' => t('Message displayed if the user has clicked the "unflag this" link and confirmation is required. Usually presented in the form of a question such as, "Are you sure you want to unflag this content?"'),
- );
-
- $form['actions'] = array(
- '#type' => 'actions',
- );
-
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save flag'),
- // We put this button on the form before calling $flag->options_form()
- // to give the flag handler a chance to remove it (e.g. flag_broken).
- '#weight' => 999,
- );
-
- // Add our process handler to disable access to locked properties.
- $form['#process'][] = 'flag_form_locked_process';
-
- // Allow the flag handler to make additions and changes to the form.
- // Note that the flag_broken handler will completely empty the form array!
- $flag->options_form($form);
-
- return $form;
-}
-*/
/**
* FormAPI after_build function set states on link type options fieldsets.
*
@@ -633,77 +227,6 @@ function flag_form_locked_process($element, &$form_state, $form) {
return $element;
}
-/**
- * Add/Edit flag form validate.
- *//*
-function flag_form_validate($form, &$form_state) {
- $form_state['values']['title'] = trim($form_state['values']['title']);
- $form_values = $form_state['values'];
-
- if ($form_values['link_type'] == 'confirm') {
- if (empty($form_values['flag_confirmation'])) {
- form_set_error('flag_confirmation', t('A flag confirmation message is required when using the confirmation link type.'));
- }
- if (empty($form_values['unflag_confirmation'])) {
- form_set_error('unflag_confirmation', t('An unflag confirmation message is required when using the confirmation link type.'));
- }
- }
-
-
- $flag = $form['#flag'];
- $flag->form_input($form_values);
- $errors = $flag->validate();
- foreach ($errors as $field => $field_errors) {
- foreach ($field_errors as $error) {
- form_set_error($field, $error['message']);
- }
- }
-}
-*/
-/**
- * Add/Edit flag form submit.
- *//*
-function flag_form_submit($form, &$form_state) {
- $flag = $form['#flag'];
-
- $form_state['values']['title'] = trim($form_state['values']['title']);
- $flag->form_input($form_state['values']);
-
- $flag->save();
- $flag->enable();
- drupal_set_message(t('Flag @title has been saved.', array('@title' => $flag->get_title())));
- // We clear caches more vigorously if the flag was new.
- _flag_clear_cache($flag->entity_type, !empty($flag->is_new));
-
- // Save permissions.
- // This needs to be done after the flag cache has been cleared, so that
- // the new permissions are picked up by hook_permission().
- // This may need to move to the flag class when we implement extra permissions
- // for different flag types: http://drupal.org/node/879988
-
- // If the flag machine name as changed, clean up all the obsolete permissions.
- if ($flag->name != $form['#flag_name']) {
- $old_name = $form['#flag_name'];
- $permissions = array("flag $old_name", "unflag $old_name");
- foreach (array_keys(user_roles()) as $rid) {
- user_role_revoke_permissions($rid, $permissions);
- }
- }
-
- foreach (array_keys(user_roles(!module_exists('session_api'))) as $rid) {
- // Create an array of permissions, based on the checkboxes element name.
- $permissions = array(
- "flag $flag->name" => $flag->roles['flag'][$rid],
- "unflag $flag->name" => $flag->roles['unflag'][$rid],
- );
- user_role_change_permissions($rid, $permissions);
- }
- // @todo: when we add database caching for flags we'll have to clear the
- // cache again here.
-
- $form_state['redirect'] = FLAG_ADMIN_PATH;
-}
-*/
/**
* Output the access options for roles in a table.
*/
diff --git a/lib/Drupal/flag/Annotation/Flag.php b/lib/Drupal/flag/Annotation/Flag.php
index d739ee3..604b4bd 100644
--- a/lib/Drupal/flag/Annotation/Flag.php
+++ b/lib/Drupal/flag/Annotation/Flag.php
@@ -12,7 +12,7 @@
/**
- * Defines a Tip annotation object.
+ * Defines a Flag annotation object.
*
* @Annotation
*/
diff --git a/lib/Drupal/flag/Controller/FlagListController.php b/lib/Drupal/flag/Controller/FlagListController.php
index d77173e..a71b70d 100644
--- a/lib/Drupal/flag/Controller/FlagListController.php
+++ b/lib/Drupal/flag/Controller/FlagListController.php
@@ -17,12 +17,27 @@ class FlagListController extends ConfigEntityListController {
* Overrides Drupal\Core\Entity\EntityListController::buildHeader().
*/
public function buildHeader() {
- $header['id'] = t('ID');
- $header['label'] = t('Label');
+// $header['id'] = t('Flag');
+ $header['label'] = t('Flag');
+ $header['roles'] = t('Roles');
+ $header['is_global'] = t('Global?');
return $header + parent::buildHeader();
}
+ /**
+ * Overrides Drupal\Core\Entity\EntityListController::buildRow().
+ */
+ public function buildRow(EntityInterface $entity) {
+ $row['label'] = $this->getLabel($entity);
+
+ $row['roles'] = ' ';
+
+ $row['is_global'] = $entity->is_global ? t('Yes') : t('No');
+
+ return $row + parent::buildRow($entity);
+ }
+
public function render() {
$build['table'] = parent::render();
@@ -67,13 +82,4 @@ public function render() {
return $build;
}
- /**
- * Overrides Drupal\Core\Entity\EntityListController::buildRow().
- */
- public function buildRow(EntityInterface $entity) {
- $row['label'] = $this->getLabel($entity);
-
- return $row + parent::buildRow($entity);
- }
-
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 141ebbe..6c31ebc 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -30,13 +30,16 @@
* "edit" = "Drupal\flag\Form\FlagAddForm",
* "delete" = "Drupal\flag\Form\FlagAddForm"
* }
-
* },
+ * bundle_of = "flagging",
* config_prefix = "flag.flag",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
+ * },
+ * links = {
+ * "edit-form" = "admin/structure/flags/manage/{flag_flag}"
* }
* )
*
diff --git a/lib/Drupal/flag/Entity/Flagging.php b/lib/Drupal/flag/Entity/Flagging.php
new file mode 100644
index 0000000..1dd9507
--- /dev/null
+++ b/lib/Drupal/flag/Entity/Flagging.php
@@ -0,0 +1,84 @@
+bundle;
+ }
+
+ public static function baseFieldDefinitions($entity_type) {
+ $properties['id'] = array(
+ 'label' => t('Flagging ID'),
+ 'description' => t('The Flagging ID.'),
+ 'type' => 'integer_field',
+ 'read-only' => TRUE,
+ );
+ $properties['type'] = array(
+ 'label' => t('Type'),
+ 'description' => t('The flag type.'),
+ 'type' => 'string_field',
+ 'read-only' => TRUE,
+ );
+ $properties['uuid'] = array(
+ 'label' => t('UUID'),
+ 'description' => t('The node UUID.'),
+ 'type' => 'uuid_field',
+ 'read-only' => TRUE,
+ );
+ $properties['uid'] = array(
+ 'label' => t('User ID'),
+ 'description' => t('The ID of the flagging user.'),
+ 'type' => 'entity_reference_field',
+ 'settings' => array(
+ 'target_type' => 'user',
+ 'default_value' => 0,
+ ),
+ );
+ $properties['created'] = array(
+ 'label' => t('Created'),
+ 'description' => t('The time that the flagging was created.'),
+ 'type' => 'integer_field',
+ );
+
+ return $properties;
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/FlaggingInterface.php b/lib/Drupal/flag/FlaggingInterface.php
new file mode 100644
index 0000000..c75bd44
--- /dev/null
+++ b/lib/Drupal/flag/FlaggingInterface.php
@@ -0,0 +1,16 @@
+
Date: Sat, 26 Oct 2013 18:11:20 -0500
Subject: [PATCH 343/629] Repurposed Flag annotation and plugin for FlagType.
---
flag.services.yml | 4 +-
.../Annotation/{Flag.php => FlagType.php} | 0
...nManager.php => FlagTypePluginManager.php} | 0
.../flag/Plugin/Derivative/FlagBase.php | 44 -------------------
.../Flag/{FlagBase.php => FlagTypeBase.php} | 0
5 files changed, 2 insertions(+), 46 deletions(-)
rename lib/Drupal/flag/Annotation/{Flag.php => FlagType.php} (100%)
rename lib/Drupal/flag/{FlagPluginManager.php => FlagTypePluginManager.php} (100%)
delete mode 100644 lib/Drupal/flag/Plugin/Derivative/FlagBase.php
rename lib/Drupal/flag/Plugin/Flag/{FlagBase.php => FlagTypeBase.php} (100%)
diff --git a/flag.services.yml b/flag.services.yml
index 191cf27..1ad7e6e 100644
--- a/flag.services.yml
+++ b/flag.services.yml
@@ -1,4 +1,4 @@
services:
- plugin.manager.flag.flag:
- class: Drupal\Flag\FlagPluginManager
+ plugin.manager.flag.flagtype:
+ class: Drupal\Flag\FlagTypePluginManager
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
diff --git a/lib/Drupal/flag/Annotation/Flag.php b/lib/Drupal/flag/Annotation/FlagType.php
similarity index 100%
rename from lib/Drupal/flag/Annotation/Flag.php
rename to lib/Drupal/flag/Annotation/FlagType.php
diff --git a/lib/Drupal/flag/FlagPluginManager.php b/lib/Drupal/flag/FlagTypePluginManager.php
similarity index 100%
rename from lib/Drupal/flag/FlagPluginManager.php
rename to lib/Drupal/flag/FlagTypePluginManager.php
diff --git a/lib/Drupal/flag/Plugin/Derivative/FlagBase.php b/lib/Drupal/flag/Plugin/Derivative/FlagBase.php
deleted file mode 100644
index 7e3f134..0000000
--- a/lib/Drupal/flag/Plugin/Derivative/FlagBase.php
+++ /dev/null
@@ -1,44 +0,0 @@
-flagStorage = $flag_storage;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container, $base_plugin_id) {
- return new static(
- $container->get('entity.manager')->getStorageController('flag')
- );
- }
-
- /**
- * {@inheritdoc}
- */
- public function getDerivativeDefinitions(array $base_plugin_definition) {
- foreach ($this->flagStorage->loadMultiple() as $flag => $entity) {
- $this->derivatives[$flag] = $base_plugin_definition;
- $this->derivatives[$flag]['admin_label'] = $entity->label();
- $this->derivatives[$flag]['cache'] = DRUPAL_NO_CACHE;
- }
- return $this->derivatives;
- }
-}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/Flag/FlagBase.php b/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/Flag/FlagBase.php
rename to lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
From 40c1f32cf4b2c64b88604ac8fa8183b3d8d229ee Mon Sep 17 00:00:00 2001
From: Tess
Date: Sat, 26 Oct 2013 18:12:15 -0500
Subject: [PATCH 344/629] Initial FlagType plugin code.
---
lib/Drupal/flag/Annotation/FlagType.php | 14 ++------------
lib/Drupal/flag/FlagTypePluginManager.php | 4 ++--
lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php | 9 ++++-----
3 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/lib/Drupal/flag/Annotation/FlagType.php b/lib/Drupal/flag/Annotation/FlagType.php
index 604b4bd..a1cba41 100644
--- a/lib/Drupal/flag/Annotation/FlagType.php
+++ b/lib/Drupal/flag/Annotation/FlagType.php
@@ -12,11 +12,11 @@
/**
- * Defines a Flag annotation object.
+ * Defines a FlagType annotation object.
*
* @Annotation
*/
-class Flag extends Plugin {
+class FlagType extends Plugin {
/**
* The plugin ID.
@@ -34,14 +34,4 @@ class Flag extends Plugin {
*/
public $title;
-
- /**
- * A class to make the plugin derivative aware.
- *
- * @var string
- *
- * @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator
- */
- public $derivative;
-
}
diff --git a/lib/Drupal/flag/FlagTypePluginManager.php b/lib/Drupal/flag/FlagTypePluginManager.php
index 3313239..8221374 100644
--- a/lib/Drupal/flag/FlagTypePluginManager.php
+++ b/lib/Drupal/flag/FlagTypePluginManager.php
@@ -13,10 +13,10 @@
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Plugin\DefaultPluginManager;
-class FlagPluginManager extends DefaultPluginManager {
+class FlagTypePluginManager extends DefaultPluginManager {
/**
- * Constructs a new FlagPluginManager.
+ * Constructs a new FlagTypePluginManager.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
diff --git a/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php b/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
index e3df92e..b38656f 100644
--- a/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
+++ b/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
@@ -11,16 +11,15 @@
use Drupal\core\Plugin\PluginBase;
/**
- * Class FlagBase
+ * Class FlagTypeBase
* @package Drupal\flag\Plugin\Flag
*
* @Flag{
- * id = "flag_base",
- * title = @Translation("Flag"),
- * derivative = "Drupal\flag\Plugin\Derivative\FlagBase"
+ * id = "flagtype_base",
+ * title = @Translation("Flag Type"),
* }
*/
-class FlagBase extends PluginBase{
+class FlagTypeBase extends PluginBase{
/**
* {@inheritdoc}
From ca0dee9adb30ebd3303535a9b40399a0953a9001 Mon Sep 17 00:00:00 2001
From: Tess
Date: Sun, 27 Oct 2013 20:29:49 -0500
Subject: [PATCH 345/629] Fixed broken plugin manager definitions.
---
flag.services.yml | 2 +-
lib/Drupal/flag/Entity/Flag.php | 12 ++++++
lib/Drupal/flag/FlagTypePluginManager.php | 4 +-
lib/Drupal/flag/Form/FlagAddPageForm.php | 2 +-
lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php | 39 +++++++++++++++++++-
5 files changed, 54 insertions(+), 5 deletions(-)
diff --git a/flag.services.yml b/flag.services.yml
index 1ad7e6e..23e248b 100644
--- a/flag.services.yml
+++ b/flag.services.yml
@@ -1,4 +1,4 @@
services:
plugin.manager.flag.flagtype:
- class: Drupal\Flag\FlagTypePluginManager
+ class: Drupal\flag\FlagTypePluginManager
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 6c31ebc..62395a1 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -8,6 +8,7 @@
namespace Drupal\flag\Entity;
+use Drupal\Component\Plugin\DefaultSinglePluginBag;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Entity\Annotation\EntityType;
@@ -162,6 +163,17 @@ class Flag extends ConfigEntityBase implements FlagInterface {
*/
public $weight = 0;
+ protected $typesBag;
+
+ /**
+ * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::__construct();
+ */
+ public function __construct(array $values, $entity_type) {
+ parent::__construct($values, $entity_type);
+
+ $this->typesBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.flagtype'), $this->types, array());
+ }
+
public function enable() {
$this->enabled = TRUE;
}
diff --git a/lib/Drupal/flag/FlagTypePluginManager.php b/lib/Drupal/flag/FlagTypePluginManager.php
index 8221374..ffb8d9e 100644
--- a/lib/Drupal/flag/FlagTypePluginManager.php
+++ b/lib/Drupal/flag/FlagTypePluginManager.php
@@ -29,9 +29,9 @@ class FlagTypePluginManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
- parent::__construct('Plugin/Flag/FlagBase', $namespaces, 'Drupal\flag\Annotation\Flag');
+ parent::__construct('Plugin/Flag/FlagTypeBase', $namespaces, 'Drupal\flag\Annotation\FlagType');
-// $this->alterInfo($module_handler, 'tour_tips_info');
+// $this->alterInfo($module_handler, 'flag_type_info');
$this->setCacheBackend($cache_backend, $language_manager, 'tour');
}
diff --git a/lib/Drupal/flag/Form/FlagAddPageForm.php b/lib/Drupal/flag/Form/FlagAddPageForm.php
index 31efe73..b883986 100644
--- a/lib/Drupal/flag/Form/FlagAddPageForm.php
+++ b/lib/Drupal/flag/Form/FlagAddPageForm.php
@@ -22,7 +22,7 @@ public function getFormID() {
public function buildForm(array $form, array &$form_state) {
$types = array();
- // @todo Convert to a Drupal service?
+ // @todo Use \Drupal::service() to get a list of FlagType plugins.
foreach (flag_fetch_definition() as $type => $info) {
$types[$type] = $info['title'] . '' . $info['description'] . '
';
}
diff --git a/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php b/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
index b38656f..197aff9 100644
--- a/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
+++ b/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
@@ -19,7 +19,7 @@
* title = @Translation("Flag Type"),
* }
*/
-class FlagTypeBase extends PluginBase{
+class FlagTypeBase extends PluginBase {
/**
* {@inheritdoc}
@@ -27,4 +27,41 @@ class FlagTypeBase extends PluginBase{
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
+
+ public funciton flag() {
+
+ }
+
+ /**
+ * Declares the options this flag supports, and their default values.
+ *
+ * Derived classes should want to override this.
+ *//*
+ public function options() {
+
+ }*/
+
+ /**
+ * Provides a form for setting options.
+ *
+ * Derived classes should want to override this.
+ */
+ public function optionsForm(&$form) {
+
+ }
+
+ /**
+ * Implements access_multiple() implemented by each child class.
+ *
+ * @abstract
+ *
+ * @return
+ * An array keyed by entity ids, whose values represent the access to the
+ * corresponding entity. The access value may be FALSE if access should be
+ * denied, or NULL (or not set) if there is no restriction to be made. It
+ * should NOT be TRUE.
+ */
+ public function type_access_multiple($entity_ids, $account) {
+ return array();
+ }
}
\ No newline at end of file
From a1d429d86a5a565670e5ae8dc6462b9b5cbad14a Mon Sep 17 00:00:00 2001
From: Tess
Date: Mon, 28 Oct 2013 19:59:36 -0500
Subject: [PATCH 346/629] All FlagType plugins load.
---
lib/Drupal/flag/FlagTypePluginManager.php | 2 +-
lib/Drupal/flag/Form/FlagAddPageForm.php | 2 +
.../flag/Plugin/Flag/BrokenFlagType.php | 31 +++++
.../flag/Plugin/Flag/CommentFlagType.php | 80 +++++++++++
.../flag/Plugin/Flag/EntityFlagType.php | 125 ++++++++++++++++++
lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php | 15 ++-
lib/Drupal/flag/Plugin/Flag/NodeFlagType.php | 96 ++++++++++++++
lib/Drupal/flag/Plugin/Flag/UserFlagType.php | 80 +++++++++++
8 files changed, 424 insertions(+), 7 deletions(-)
create mode 100644 lib/Drupal/flag/Plugin/Flag/BrokenFlagType.php
create mode 100644 lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
create mode 100644 lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
create mode 100644 lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
create mode 100644 lib/Drupal/flag/Plugin/Flag/UserFlagType.php
diff --git a/lib/Drupal/flag/FlagTypePluginManager.php b/lib/Drupal/flag/FlagTypePluginManager.php
index ffb8d9e..a8ad403 100644
--- a/lib/Drupal/flag/FlagTypePluginManager.php
+++ b/lib/Drupal/flag/FlagTypePluginManager.php
@@ -29,7 +29,7 @@ class FlagTypePluginManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
- parent::__construct('Plugin/Flag/FlagTypeBase', $namespaces, 'Drupal\flag\Annotation\FlagType');
+ parent::__construct('Plugin/Flag', $namespaces, 'Drupal\flag\Annotation\FlagType');
// $this->alterInfo($module_handler, 'flag_type_info');
$this->setCacheBackend($cache_backend, $language_manager, 'tour');
diff --git a/lib/Drupal/flag/Form/FlagAddPageForm.php b/lib/Drupal/flag/Form/FlagAddPageForm.php
index b883986..532cdee 100644
--- a/lib/Drupal/flag/Form/FlagAddPageForm.php
+++ b/lib/Drupal/flag/Form/FlagAddPageForm.php
@@ -23,6 +23,8 @@ public function getFormID() {
public function buildForm(array $form, array &$form_state) {
$types = array();
// @todo Use \Drupal::service() to get a list of FlagType plugins.
+ // print_r(\Drupal::service('plugin.manager.flag.flagtype')->getDefinitions());
+
foreach (flag_fetch_definition() as $type => $info) {
$types[$type] = $info['title'] . '' . $info['description'] . '
';
}
diff --git a/lib/Drupal/flag/Plugin/Flag/BrokenFlagType.php b/lib/Drupal/flag/Plugin/Flag/BrokenFlagType.php
new file mode 100644
index 0000000..d220e59
--- /dev/null
+++ b/lib/Drupal/flag/Plugin/Flag/BrokenFlagType.php
@@ -0,0 +1,31 @@
+ $this->entity_type)), 'error');
+ $form = array();
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
new file mode 100644
index 0000000..0a76b88
--- /dev/null
+++ b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
@@ -0,0 +1,80 @@
+ '',
+ );
+ return $options;
+ }
+
+ /**
+ * Options form extras for comment flags.
+ */
+ public function options_form(&$form) {
+ parent::options_form($form);
+
+ $form['access']['access_author'] = array(
+ '#type' => 'radios',
+ '#title' => t('Flag access by content authorship'),
+ '#options' => array(
+ '' => t('No additional restrictions'),
+ 'comment_own' => t('Users may only flag own comments'),
+ 'comment_others' => t('Users may only flag comments by others'),
+ 'node_own' => t('Users may only flag comments of nodes they own'),
+ 'node_others' => t('Users may only flag comments of nodes by others'),
+ ),
+ '#default_value' => $this->access_author,
+ '#description' => t("Restrict access to this flag based on the user's ownership of the content. Users must also have access to the flag through the role settings."),
+ );
+ }
+
+ public function type_access_multiple($entity_ids, $account) {
+ $access = array();
+
+ // If all subtypes are allowed, we have nothing to say here.
+ if (empty($this->types)) {
+ return $access;
+ }
+
+ // Ensure node types are granted access. This avoids a
+ // node_load() on every type, usually done by applies_to_entity_id().
+ $query = db_select('comment', 'c');
+ $query->innerJoin('node', 'n', 'c.nid = n.nid');
+ $result = $query
+ ->fields('c', array('cid'))
+ ->condition('c.cid', $entity_ids, 'IN')
+ ->condition('n.type', $this->types, 'NOT IN')
+ ->execute();
+ foreach ($result as $row) {
+ $access[$row->nid] = FALSE;
+ }
+
+ return $access;
+ }
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
new file mode 100644
index 0000000..1900a91
--- /dev/null
+++ b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
@@ -0,0 +1,125 @@
+ array(),
+ // Output the flag as individual pseudofields.
+ 'show_as_field' => FALSE,
+ // Add a checkbox for the flag in the entity form.
+ // @see hook_field_attach_form().
+ 'show_on_form' => FALSE,
+ 'access_author' => '',
+ 'show_contextual_link' => FALSE,
+ );
+ return $options;
+ }
+
+ /**
+ * Options form extras for the generic entity flag.
+ */
+ function options_form(&$form) {
+ $bundles = array();
+ $bundle_info = entity_get_bundles($this->entity_type);
+ foreach ($bundle_info as $bundle_key => $info) {
+ $bundles[$bundle_key] = $info['label'];
+ }
+ $form['access']['types'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Bundles'),
+ '#options' => $bundles,
+ '#description' => t('Select the bundles that this flag may be used on. Leave blank to allow on all bundles for the entity type.'),
+ '#default_value' => $this->types,
+ );
+
+ // Add checkboxes to show flag link on each entity view mode.
+ $options = array();
+ $defaults = array();
+ $view_modes = entity_get_view_modes($this->entity_type);
+ foreach ($view_modes as $name => $view_mode) {
+ $options[$name] = t('Display on @name view mode', array('@name' => $view_mode['label']));
+ $defaults[$name] = !empty($this->show_in_links[$name]) ? $name : 0;
+ }
+
+ $form['display']['show_in_links'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Display in entity links'),
+ '#description' => t('Show the flag link with the other links on the entity.'),
+ '#options' => $options,
+ '#default_value' => $defaults,
+ );
+
+ $form['display']['show_as_field'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Display link as field'),
+ '#description' => t('Show the flag link as a pseudofield, which can be ordered among other entity elements in the "Manage display" settings for the entity type.'),
+ '#default_value' => isset($this->show_as_field) ? $this->show_as_field : TRUE,
+ );
+ if (empty($entity_info['fieldable'])) {
+ $form['display']['show_as_field']['#disabled'] = TRUE;
+ $form['display']['show_as_field']['#description'] = t("This entity type is not fieldable.");
+ }
+
+ $form['display']['show_on_form'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Display checkbox on entity edit form'),
+ '#default_value' => $this->show_on_form,
+ '#weight' => 5,
+ );
+
+ // We use FieldAPI to put the flag checkbox on the entity form, so therefore
+ // require the entity to be fielable. Since this is a potential DX
+ // headscratcher for a developer wondering where this option has gone,
+ // we disable it and explain why.
+ if (empty($entity_info['fieldable'])) {
+ $form['display']['show_on_form']['#disabled'] = TRUE;
+ $form['display']['show_on_form']['#description'] = t('This is only possible on entities which are fieldable.');
+ }
+ $form['display']['show_contextual_link'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Display in contextual links'),
+ '#default_value' => $this->show_contextual_link,
+ '#description' => t('Note that not all entity types support contextual links.'),
+ '#access' => module_exists('contextual'),
+ '#weight' => 10,
+ );
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php b/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
index 197aff9..f2a818e 100644
--- a/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
+++ b/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
@@ -14,10 +14,10 @@
* Class FlagTypeBase
* @package Drupal\flag\Plugin\Flag
*
- * @Flag{
+ * @FlagType(
* id = "flagtype_base",
- * title = @Translation("Flag Type"),
- * }
+ * title = @Translation("Flag Type Base")
+ * )
*/
class FlagTypeBase extends PluginBase {
@@ -25,6 +25,7 @@ class FlagTypeBase extends PluginBase {
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
+ $configuration += $this->options();
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
@@ -36,10 +37,12 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
* Declares the options this flag supports, and their default values.
*
* Derived classes should want to override this.
- *//*
+ *
+ * @todo Rename to defaultConfiguration()?
+ */
public function options() {
-
- }*/
+ return array();
+ }
/**
* Provides a form for setting options.
diff --git a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
new file mode 100644
index 0000000..2a27da9
--- /dev/null
+++ b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
@@ -0,0 +1,96 @@
+ 0,
+ );
+ return $options;
+ }
+
+ /**
+ * Options form extras for node flags.
+ */
+ public function options_form(&$form) {
+ parent::options_form($form);
+
+ $form['access']['access_author'] = array(
+ '#type' => 'radios',
+ '#title' => t('Flag access by content authorship'),
+ '#options' => array(
+ '' => t('No additional restrictions'),
+ 'own' => t('Users may only flag content they own'),
+ 'others' => t('Users may only flag content of others'),
+ ),
+ '#default_value' => $this->access_author,
+ '#description' => t("Restrict access to this flag based on the user's ownership of the content. Users must also have access to the flag through the role settings."),
+ );
+
+ // Support for i18n flagging requires Translation helpers module.
+ $form['i18n'] = array(
+ '#type' => 'radios',
+ '#title' => t('Internationalization'),
+ '#options' => array(
+ '1' => t('Flag translations of content as a group'),
+ '0' => t('Flag each translation of content separately'),
+ ),
+ '#default_value' => $this->i18n,
+ '#description' => t('Flagging translations as a group effectively allows users to flag the original piece of content regardless of the translation they are viewing. Changing this setting will not update content that has been flagged already.'),
+ '#access' => module_exists('translation_helpers'),
+ '#weight' => 5,
+ );
+
+ // Override the UI texts for nodes.
+ $form['display']['show_on_form'] = array(
+ '#title' => t('Display checkbox on node edit form'),
+ '#description' => t('If you elect to have a checkbox on the node edit form, you may specify its initial state in the settings form for each content type.', array('@content-types-url' => url('admin/structure/types'))),
+ ) + $form['display']['show_on_form'];
+ }
+
+ function type_access_multiple($entity_ids, $account) {
+ $access = array();
+
+ // If all subtypes are allowed, we have nothing to say here.
+ if (empty($this->types)) {
+ return $access;
+ }
+
+ // Ensure that only flaggable node types are granted access. This avoids a
+ // node_load() on every type, usually done by applies_to_entity_id().
+ $result = db_select('node', 'n')->fields('n', array('nid'))
+ ->condition('nid', array_keys($entity_ids), 'IN')
+ ->condition('type', $this->types, 'NOT IN')
+ ->execute();
+ foreach ($result as $row) {
+ $access[$row->nid] = FALSE;
+ }
+
+ return $access;
+ }
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
new file mode 100644
index 0000000..5ff0285
--- /dev/null
+++ b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
@@ -0,0 +1,80 @@
+ TRUE,
+ 'access_uid' => '',
+ );
+ return $options;
+ }
+
+ /**
+ * Options form extras for user flags.
+ */
+ function options_form(&$form) {
+ parent::options_form($form);
+ $form['access']['types'] = array(
+ // A user flag doesn't support node types.
+ // TODO: Maybe support roles instead of node types.
+ '#type' => 'value',
+ '#value' => array(0 => 0),
+ );
+ $form['access']['access_uid'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Users may flag themselves'),
+ '#description' => t('Disabling this option may be useful when setting up a "friend" flag, when a user flagging themself does not make sense.'),
+ '#default_value' => $this->access_uid ? 0 : 1,
+ );
+ $form['display']['show_on_profile'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Display link on user profile page'),
+ '#description' => t('Show the link formatted as a user profile element.'),
+ '#default_value' => $this->show_on_profile,
+ // Put this above 'show on entity'.
+ '#weight' => -1,
+ );
+ }
+
+ function type_access_multiple($entity_ids, $account) {
+ $access = array();
+
+ // Exclude anonymous.
+ if (array_key_exists(0, $entity_ids)) {
+ $access[0] = FALSE;
+ }
+
+ // Prevent users from flagging themselves.
+ if ($this->access_uid == 'others' && array_key_exists($account->uid, $entity_ids)) {
+ $access[$account->uid] = FALSE;
+ }
+
+ return $access;
+ }
+
+}
\ No newline at end of file
From fc5ca39d8a8d2a23eaef28ea42e488c7cdbb69f5 Mon Sep 17 00:00:00 2001
From: Tess
Date: Tue, 19 Nov 2013 19:46:48 -0600
Subject: [PATCH 347/629] Fixed local action link on flag entity form, added
initial action link plugin code.
---
.idea/.name | 1 +
flag.install | 4 +-
flag.local_actions.yml | 5 ++
flag.module | 51 ++++++++++++-----
flag.services.yml | 3 +
lib/Drupal/flag/ActionLinkPluginManager.php | 29 ++++++++++
lib/Drupal/flag/ActionLinkTypeBase.php | 55 +++++++++++++++++++
.../flag/ActionLinkTypePluginInterface.php | 18 ++++++
lib/Drupal/flag/Annotation/ActionLinkType.php | 47 ++++++++++++++++
lib/Drupal/flag/Entity/Flag.php | 16 ++++++
lib/Drupal/flag/Entity/Flagging.php | 5 +-
lib/Drupal/flag/Flag.php | 40 ++++++++++++++
lib/Drupal/flag/FlagTypePluginManager.php | 2 +-
lib/Drupal/flag/Form/FlagAddForm.php | 2 +-
lib/Drupal/flag/Plugin/ActionLink/Reload.php | 26 +++++++++
lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php | 12 +++-
16 files changed, 294 insertions(+), 22 deletions(-)
create mode 100644 .idea/.name
create mode 100644 flag.local_actions.yml
create mode 100644 lib/Drupal/flag/ActionLinkPluginManager.php
create mode 100644 lib/Drupal/flag/ActionLinkTypeBase.php
create mode 100644 lib/Drupal/flag/ActionLinkTypePluginInterface.php
create mode 100644 lib/Drupal/flag/Annotation/ActionLinkType.php
create mode 100644 lib/Drupal/flag/Flag.php
create mode 100644 lib/Drupal/flag/Plugin/ActionLink/Reload.php
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..551c90f
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+flag
\ No newline at end of file
diff --git a/flag.install b/flag.install
index 3f07700..d7d20ba 100644
--- a/flag.install
+++ b/flag.install
@@ -64,7 +64,7 @@ function flag_schema() {
$schema['flagging'] = array(
'description' => 'Objects that have been flagged.',
'fields' => array(
- 'flagging_id' => array(
+ 'id' => array(
'description' => 'The unique ID for this particular tag.',
'type' => 'serial',
'unsigned' => TRUE,
@@ -115,7 +115,7 @@ function flag_schema() {
'disp-size' => 11,
)
),
- 'primary key' => array('flagging_id'),
+ 'primary key' => array('id'),
'unique keys' => array(
'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
),
diff --git a/flag.local_actions.yml b/flag.local_actions.yml
new file mode 100644
index 0000000..b9b57dc
--- /dev/null
+++ b/flag.local_actions.yml
@@ -0,0 +1,5 @@
+flag_add_page_action:
+ route_name: flag_add_page
+ title: 'Add New Flag'
+ appears_on:
+ - flag.flag_list
\ No newline at end of file
diff --git a/flag.module b/flag.module
index cdc25b9..58bf883 100644
--- a/flag.module
+++ b/flag.module
@@ -193,7 +193,6 @@ function flag_menu() {
'weight' => -10,
);
$items[FLAG_ADMIN_PATH . '/add'] = array(
- 'title' => 'Add flag',
'route_name' => 'flag_add_page',
'type' => MENU_SIBLING_LOCAL_TASK,
'weight' => 1,
@@ -693,9 +692,10 @@ function flag_form_node_type_form_alter(&$form, &$form_state, $form_id) {
* @see flag_field_attach_submit().
*/
function flag_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
- list($id) = entity_extract_ids($entity_type, $entity);
+ $id = $entity->id;
+
// Some modules are being stupid here. Commerce!
- if (empty($id)) {
+ if (empty($entity->id)) {
$id = NULL;
}
@@ -846,6 +846,7 @@ function flag_field_attach_save($entity_type, $entity) {
* Implements hook_contextual_links_view_alter().
*/
function flag_contextual_links_view_alter(&$element, $items) {
+/*
if (isset($element['#element']['#entity_type'])) {
$entity_type = $element['#element']['#entity_type'];
@@ -884,7 +885,7 @@ function flag_contextual_links_view_alter(&$element, $items) {
'html' => TRUE,
);
}
- }
+ }*/
}
/**
@@ -897,9 +898,35 @@ function flag_contextual_links_view_alter(&$element, $items) {
function flag_entity_view($entity, $type, $view_mode, $langcode) {
// Get all possible flags for this entity type.
$flags = flag_get_flags($type);
+
+ foreach ($flags as $flag) {
+
+ if($flag->isFlagged()) {
+ $action_link_url = "/unflag";
+ }
+ else {
+ $action_link_url = "/flag";
+ }
+
+ $action_link_url .= "/" . $flag->id . "/" . $entity->id();
+
+ $entity->content['flag_' . $flag->id] = array(
+ '#markup' => '' . l($flag->flag_short, $action_link_url) . '
',
+ '#weight' => 10,
+ );
+/*
+ $links = array(
+ '#prefix' => '',
+ '#markup' => l($flag->flag_short, $action_link_url),
+ '#suffix' => '
',
+ );
+*/
+ }
+
+ /**
foreach ($flags as $flag) {
// Check if the flag outputs on entity view.
- if (!($flag->show_as_field || $flag->shows_in_entity_links($view_mode))) {
+ if (!($flag->show_as_field)) { //} || $flag->shows_in_entity_links($view_mode))) {
// Flag is not configured to output on entity view, so skip it to save on
// calls to access checks.
continue;
@@ -928,7 +955,7 @@ function flag_entity_view($entity, $type, $view_mode, $langcode) {
// The flag links are actually fully rendered theme functions.
// The HTML attribute is set to TRUE to allow whatever the themer desires.
$links['flag-' . $flag->name] = array(
- 'title' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id),
+ 'title' => $flag->flag_short, //theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id),
'html' => TRUE,
);
}
@@ -940,15 +967,11 @@ function flag_entity_view($entity, $type, $view_mode, $langcode) {
);
}
}
-
+ */
// If any links were made, add them to the entity's links array.
- if (isset($links)) {
- $entity->content['links']['flag'] = array(
- '#theme' => 'links',
- '#links' => $links,
- '#attributes' => array('class' => array('links', 'inline')),
- );
- }
+// if (isset($links)) {
+// $entity->content['links']['flag'] = $links;
+ // }
}
/**
diff --git a/flag.services.yml b/flag.services.yml
index 23e248b..554fa2b 100644
--- a/flag.services.yml
+++ b/flag.services.yml
@@ -2,3 +2,6 @@ services:
plugin.manager.flag.flagtype:
class: Drupal\flag\FlagTypePluginManager
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
+ plugin.manager.action_link:
+ class: Drupal\flag\ActionLinkPluginManager
+ arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
diff --git a/lib/Drupal/flag/ActionLinkPluginManager.php b/lib/Drupal/flag/ActionLinkPluginManager.php
new file mode 100644
index 0000000..81ee91e
--- /dev/null
+++ b/lib/Drupal/flag/ActionLinkPluginManager.php
@@ -0,0 +1,29 @@
+alterInfo($module_handler, 'flag_link_type_info');
+ $this->setCacheBackend($cache_backend, $language_manager, 'flag_link_type_info');
+ }
+
+}
diff --git a/lib/Drupal/flag/ActionLinkTypeBase.php b/lib/Drupal/flag/ActionLinkTypeBase.php
new file mode 100644
index 0000000..4bde528
--- /dev/null
+++ b/lib/Drupal/flag/ActionLinkTypeBase.php
@@ -0,0 +1,55 @@
+setConfiguration($configuration);
+ }
+
+ public function buildLink() {
+ return "";
+ }
+
+ public function buildConfigurationForm(array $form, array &$form_state) {
+ return $form;
+ }
+
+ public function submitConfigurationForm(array &$form, array &$form_state) {
+
+ }
+
+ public function validateConfigurationForm(array &$form, array &$form_state) {
+
+ }
+
+ public function defaultConfiguration() {
+ return array();
+ }
+
+ public function getConfiguration() {
+ return $configuration;
+ }
+
+ public function setConfiguration(array $configuration) {
+ $this->configuration = $configuration;
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/ActionLinkTypePluginInterface.php b/lib/Drupal/flag/ActionLinkTypePluginInterface.php
new file mode 100644
index 0000000..e0d746f
--- /dev/null
+++ b/lib/Drupal/flag/ActionLinkTypePluginInterface.php
@@ -0,0 +1,18 @@
+enabled = FALSE;
}
+ public function isFlagged(AccountInterface $account = NULL) {
+ if($account == NULL) {
+ global $user;
+ $account = $user;
+ }
+
+ $query = \Drupal::entityQuery('flagging');
+ $query->condition('uid', $account->id());
+
+ $result = $query->execute();
+
+ if (isset($result['node'])) {
+ $flagging_ids = array_keys($result['flagging']);
+ }
+ }
+
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Entity/Flagging.php b/lib/Drupal/flag/Entity/Flagging.php
index 1dd9507..f81fc20 100644
--- a/lib/Drupal/flag/Entity/Flagging.php
+++ b/lib/Drupal/flag/Entity/Flagging.php
@@ -23,10 +23,9 @@
* label = @Translation("Flagging"),
* module = "flag",
* controllers = {
- * "storage" = "FieldableDatabaseStorageController",
- * "form" = {
- * }
+ * "storage" = "Drupal\Core\Entity\FieldableDatabaseStorageController",
* },
+ * base_table = "flagging",
* fieldable = TRUE,
* entity_keys = {
* "id" = "id",
diff --git a/lib/Drupal/flag/Flag.php b/lib/Drupal/flag/Flag.php
new file mode 100644
index 0000000..9785935
--- /dev/null
+++ b/lib/Drupal/flag/Flag.php
@@ -0,0 +1,40 @@
+getDefinition($entity_type);
+ }
+
+ return \Drupal::service('plugin.manager.flag.flagtype')->getDefinitions();
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/FlagTypePluginManager.php b/lib/Drupal/flag/FlagTypePluginManager.php
index a8ad403..2b21305 100644
--- a/lib/Drupal/flag/FlagTypePluginManager.php
+++ b/lib/Drupal/flag/FlagTypePluginManager.php
@@ -32,7 +32,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
parent::__construct('Plugin/Flag', $namespaces, 'Drupal\flag\Annotation\FlagType');
// $this->alterInfo($module_handler, 'flag_type_info');
- $this->setCacheBackend($cache_backend, $language_manager, 'tour');
+ $this->setCacheBackend($cache_backend, $language_manager, 'flag');
}
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Form/FlagAddForm.php b/lib/Drupal/flag/Form/FlagAddForm.php
index 67b14ef..218a738 100644
--- a/lib/Drupal/flag/Form/FlagAddForm.php
+++ b/lib/Drupal/flag/Form/FlagAddForm.php
@@ -332,7 +332,7 @@ public function validate(array $form, array &$form_state) {
public function save(array $form, array &$form_state) {
$flag = $this->entity;
- $form_state['values']['title'] = trim($form_state['values']['title']);
+ $form_state['values']['label'] = trim($form_state['values']['label']);
$flag->enable();
$status = $flag->save();
diff --git a/lib/Drupal/flag/Plugin/ActionLink/Reload.php b/lib/Drupal/flag/Plugin/ActionLink/Reload.php
new file mode 100644
index 0000000..bb9619e
--- /dev/null
+++ b/lib/Drupal/flag/Plugin/ActionLink/Reload.php
@@ -0,0 +1,26 @@
+
Date: Tue, 19 Nov 2013 22:36:23 -0600
Subject: [PATCH 348/629] Removed a bunch of D7 code.
---
flag.flag.inc | 110 --
flag.info.inc | 98 --
flag.module | 8 +-
flag.rules.inc | 582 -----------
flag_actions.info | 9 -
flag_actions.install | 95 --
flag_actions.module | 692 -------------
includes/flag.actions.inc | 243 -----
includes/flag.admin.inc | 345 -------
includes/flag.cookie_storage.inc | 170 ---
includes/flag.entity.inc | 24 -
includes/flag.export.inc | 138 ---
includes/flag.features.inc | 124 ---
includes/flag.pages.inc | 165 ---
includes/views/flag.views.inc | 272 -----
includes/views/flag.views_convert.inc | 235 -----
.../views/flag_handler_argument_entity_id.inc | 46 -
includes/views/flag_handler_field_flagged.inc | 36 -
includes/views/flag_handler_field_ops.inc | 163 ---
.../views/flag_handler_filter_flagged.inc | 33 -
includes/views/flag_handler_relationships.inc | 267 -----
includes/views/flag_handler_sort_flagged.inc | 47 -
..._plugin_argument_validate_flaggability.inc | 226 ----
.../flag_is_flagged/flag_is_flagged.inc | 96 --
plugins/content_types/flag_link/flag_link.inc | 115 ---
tests/flag.test | 971 ------------------
tests/flagaccesstest/flagaccesstest.info | 6 -
tests/flagaccesstest/flagaccesstest.module | 26 -
28 files changed, 4 insertions(+), 5338 deletions(-)
delete mode 100644 flag.flag.inc
delete mode 100644 flag.info.inc
delete mode 100644 flag.rules.inc
delete mode 100644 flag_actions.info
delete mode 100644 flag_actions.install
delete mode 100644 flag_actions.module
delete mode 100644 includes/flag.actions.inc
delete mode 100644 includes/flag.admin.inc
delete mode 100644 includes/flag.cookie_storage.inc
delete mode 100644 includes/flag.entity.inc
delete mode 100644 includes/flag.export.inc
delete mode 100644 includes/flag.features.inc
delete mode 100644 includes/flag.pages.inc
delete mode 100644 includes/views/flag.views.inc
delete mode 100644 includes/views/flag.views_convert.inc
delete mode 100644 includes/views/flag_handler_argument_entity_id.inc
delete mode 100644 includes/views/flag_handler_field_flagged.inc
delete mode 100644 includes/views/flag_handler_field_ops.inc
delete mode 100644 includes/views/flag_handler_filter_flagged.inc
delete mode 100644 includes/views/flag_handler_relationships.inc
delete mode 100644 includes/views/flag_handler_sort_flagged.inc
delete mode 100644 includes/views/flag_plugin_argument_validate_flaggability.inc
delete mode 100644 plugins/access/flag_is_flagged/flag_is_flagged.inc
delete mode 100644 plugins/content_types/flag_link/flag_link.inc
delete mode 100644 tests/flag.test
delete mode 100644 tests/flagaccesstest/flagaccesstest.info
delete mode 100644 tests/flagaccesstest/flagaccesstest.module
diff --git a/flag.flag.inc b/flag.flag.inc
deleted file mode 100644
index 695a800..0000000
--- a/flag.flag.inc
+++ /dev/null
@@ -1,110 +0,0 @@
- array(
- 'title' => t('Nodes'),
- 'description' => t("Nodes are a Drupal site's primary content."),
- 'handler' => '\Drupal\flag\Handlers\NodeFlag',
- ),
- 'user' => array(
- 'title' => t('Users'),
- 'description' => t('Users who have created accounts on your site.'),
- 'handler' => '\Drupal\flag\Handlers\UserFlag',
- ),
- );
-
- if (module_exists('comment')) {
- $definitions['comment'] = array(
- 'title' => t('Comments'),
- 'description' => t('Comments are responses to node content.'),
- 'handler' => '\Drupal\flag\Handlers\CommentFlag',
- 'module' => 'comment',
- );
- }
-
- if (module_exists('taxonomy')) {
- $definitions['taxonomy_term'] = array(
- 'title' => t('Taxonomy Terms'),
- 'description' => t('Taxonomy terms are used to categorize content.'),
- 'handler' => '\Drupal\flag\Handlers\Flag',
- 'module' => 'taxonomy',
- );
- }
-
- return $definitions;
-}
-
-/**
- * Implements hook_flag_type_info_alter().
- *
- * Step in and add flag types for any entities not yet catered for, using the
- * basic flag_entity handler. This allows other modules to provide more
- * specialized handlers for entities in hook_flag_type_info() as normal.
- */
-function flag_flag_type_info_alter(&$definitions) {
- foreach (entity_get_info() as $entity_type => $entity_info) {
- // Only add flag support for entities that don't yet have them, and which
- // are non-config entities.
- if (!isset($definitions[$entity_type]) && empty($entity_info['configuration'])) {
- // We deliberately exclude taxonomy vocabularies from the list of
- // supported entity types because they aren't fieldable or directly
- // viewable, which makes them impossible to flag.
- if ($entity_type === 'taxonomy_vocabulary') {
- continue;
- }
-
- $definitions[$entity_type] = array(
- 'title' => $entity_info['label'],
- 'description' => t('@entity-type entity', array('@entity-type' => $entity_info['label'])),
- 'handler' => 'flag_entity',
- );
- }
- }
-}
-
-/**
- * Implements hook_flag_link_type_info().
- */
-function flag_flag_link_type_info() {
- return array(
- 'toggle' => array(
- 'title' => t('JavaScript toggle'),
- 'description' => t('An AJAX request will be made and degrades to type "Normal link" if JavaScript is not available.'),
- 'uses standard js' => TRUE,
- 'uses standard css' => TRUE,
- ),
- 'normal' => array(
- 'title' => t('Normal link'),
- 'description' => t('A normal non-JavaScript request will be made and the current page will be reloaded.'),
- 'uses standard js' => FALSE,
- 'uses standard css' => FALSE,
- ),
- 'confirm' => array(
- 'title' => t('Confirmation form'),
- 'description' => t('The user will be taken to a confirmation form on a separate page to confirm the flag.'),
- 'options' => array(
- 'flag_confirmation' => '',
- 'unflag_confirmation' => '',
- ),
- 'uses standard js' => FALSE,
- 'uses standard css' => FALSE,
- 'provides form' => TRUE,
- ),
- );
-}
diff --git a/flag.info.inc b/flag.info.inc
deleted file mode 100644
index 69bbb5c..0000000
--- a/flag.info.inc
+++ /dev/null
@@ -1,98 +0,0 @@
-flag_FLAGNAME, boolean.
- * - per-user flags:
- * - entity->flag_FLAGNAME_users, list of users.
- * - user->flag_FLAGNAME_flagged, list of user's flagged entities.
- */
-function flag_entity_property_info_alter(&$info) {
- foreach (flag_get_flags() as $flag) {
- if ($flag->global) {
- // Global flags.
- // Boolean property on entity type.
- // This can go on either the entity as a whole, or on bundles, depending
- // on whether the flag is limited by bundle.
- $property_definition = array(
- 'label' => t('Whether the entity is flagged with flag @flag', array(
- '@flag' => $flag->name,
- )),
- 'description' => t('Whether the entity is flagged with flag @flag.', array(
- '@flag' => $flag->name,
- )),
- 'type' => 'boolean',
- 'getter callback' => 'flag_properties_get_flagging_boolean',
- 'computed' => TRUE,
- 'flag_name' => $flag->name,
- );
- if (count($flag->types)) {
- // Bundle specific property.
- foreach ($flag->types as $type) {
- $info[$flag->entity_type]['bundles'][$type]['properties']['flag_' . $flag->name] = $property_definition;
- }
- }
- else {
- // Generic property, applies for all bundles.
- $info[$flag->entity_type]['properties']['flag_' . $flag->name] = $property_definition;
- }
- }
- else {
- // Per-user flags.
- // User property: list of flagged entities by the user.
- $info['user']['properties']['flag_' . $flag->name . '_flagged'] = array(
- 'label' => t('Flagged @entity-type with flag @flag', array(
- '@entity-type' => $flag->entity_type,
- '@flag' => $flag->name,
- )),
- 'description' => t('Returns a list of entities a user flagged with flag @flag.', array(
- '@flag' => $flag->name,
- )),
- 'type' => 'list<' . $flag->entity_type . '>',
- 'getter callback' => 'flag_properties_get_flagged_entities',
- 'computed' => TRUE,
- 'flag_name' => $flag->name,
- 'flag_entity_type' => $flag->entity_type,
- );
- $info['user']['properties']['flag_sid'] = array(
- 'label' => t('Flag user session identifier'),
- 'description' => t('Returns the sessions id used to distinguish anonymous users from each other.'),
- 'type' => 'text',
- 'getter callback' => 'flag_properties_get_user_sid',
- 'computed' => TRUE,
- );
- // Entity property: list of users who have flagged this entity.
- // This can go on either the entity as a whole, or on bundles, depending
- // on whether the flag is limited by bundle.
- $property_definition = array(
- 'label' => t('Users who flagged the entity with flag @flag', array(
- '@flag' => $flag->name,
- )),
- 'description' => t('Returns a list of users who flagged an entity with flag @flag.', array(
- '@flag' => $flag->name,
- )),
- 'type' => 'list',
- 'getter callback' => 'flag_properties_get_flagging_users',
- 'computed' => TRUE,
- 'flag_name' => $flag->name,
- );
- if (count($flag->types)) {
- // Bundle specific property.
- foreach ($flag->types as $type) {
- $info[$flag->entity_type]['bundles'][$type]['properties']['flag_' . $flag->name . '_user'] = $property_definition;
- }
- }
- else {
- // Generic property, applies for all bundles.
- $info[$flag->entity_type]['properties']['flag_' . $flag->name . '_user'] = $property_definition;
- }
- }
- }
-}
diff --git a/flag.module b/flag.module
index 58bf883..612a3a2 100644
--- a/flag.module
+++ b/flag.module
@@ -217,7 +217,7 @@ function flag_menu() {
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
-
+/*
$items[FLAG_ADMIN_PATH . '/manage/%flag'] = array(
'load arguments' => array(TRUE), // Allow for disabled flags.
'page callback' => 'drupal_get_form',
@@ -263,7 +263,7 @@ function flag_menu() {
'file' => 'includes/flag.export.inc',
'type' => MENU_CALLBACK,
);
-
+*/
$items['flag/%/%flag/%'] = array(
'title' => 'Flag',
'page callback' => 'flag_page',
@@ -1463,7 +1463,7 @@ function flag_flag_access_multiple($flag, $entity_ids, $account) {
/**
* Implements hook_theme().
- */
+ *//*
function flag_theme() {
$path = drupal_get_path('module', 'flag') . '/theme';
@@ -1513,7 +1513,7 @@ function flag_theme() {
),
);
}
-
+*/
/**
* A preprocess function for our theme('flag'). It generates the
* variables needed there.
diff --git a/flag.rules.inc b/flag.rules.inc
deleted file mode 100644
index 23cefcc..0000000
--- a/flag.rules.inc
+++ /dev/null
@@ -1,582 +0,0 @@
- array(
- 'label' => t('flag'),
- 'ui class' => 'FlagRulesUIClass',
- 'wrapper class' => 'FlagRulesDataWrapper',
- 'wrap' => TRUE,
- ),
- 'flagging' => array(
- 'label' => t('flagging'),
- 'parent' => 'entity',
- 'group' => t('flag'),
- ),
- );
-}
-
-/**
- * A custom wrapper class for flags to be used with Rules.
- * @ingroup rules
- */
-class FlagRulesDataWrapper extends RulesIdentifiableDataWrapper implements RulesDataWrapperSavableInterface {
-
- protected function extractIdentifier($flag) {
- return $flag->name;
- }
-
- protected function load($name) {
- return flag_get_flag($name);
- }
-
- public function save() {
- $flag = $this->value();
- $flag->save();
- }
-
- public function validate($value) {
- if (isset($value) && is_string($value)) {
- return TRUE;
- }
- elseif (isset($value) && is_object($value) && $value instanceof flag_flag) {
- return TRUE;
- }
- return parent::validate($value);
- }
-}
-
-/**
- * UI for inputing flags.
- * @ingroup rules
- */
-class FlagRulesUIClass extends RulesDataUI implements RulesDataDirectInputFormInterface {
-
- public static function getDefaultMode() {
- return 'input';
- }
-
- public static function inputForm($name, $info, $settings, RulesPlugin $element) {
- $options = _flag_rules_flags_options(isset($info['flag_type']) ? $info['flag_type'] : NULL);
- $header = array(
- 'title' => t('Flag:'),
- 'type' => t('The flag type'),
- 'global' => t('Is the flag global?'),
- );
- $settings += array($name => isset($info['default value']) ? $info['default value'] : '');
-
- $form[$name] = array(
- '#type' => 'tableselect',
- '#header' => $header,
- '#options' => $options,
- '#required' => empty($info['optional']),
- '#multiple' => FALSE,
- '#default_value' => $settings[$name],
- '#empty' => t('There is no suiting flag available.')
- );
- return $form;
- }
-
- public static function render($value) {
- $flag = flag_get_flag($value);
-
- if ($flag === FALSE) {
- return array();
- }
-
- return array(
- 'content' => array('#markup' => check_plain($flag->get_title())),
- '#attributes' => array('class' => array('rules-parameter-flag')),
- );
- }
-}
-
-function _flag_rules_flags_options($flag_type = NULL) {
- $flags = flag_get_flags();
- $options = array();
- foreach ($flags as $flag) {
- if (!isset($flag_type) || $flag->entity_type == $flag_type) {
- $options[$flag->name] = array(
- 'title' => $flag->get_title(),
- 'type' => $flag->entity_type,
- 'global' => $flag->global ? t('Yes') : t('No'),
- );
- }
- }
- return $options;
-}
-
-/**
- * Implements hook_rules_event_info().
- */
-function flag_rules_event_info() {
- $items = array();
-
- $flags = flag_get_flags();
- foreach ($flags as $flag) {
- // We only support flags on entities.
- if ($info = entity_get_info($flag->entity_type)) {
- $variables = array(
- 'flag' => array(
- 'type' => 'flag',
- 'label' => t('flag'),
- 'flag_type' => $flag->entity_type,
- ),
- 'flagged_' . $flag->entity_type => array(
- 'type' => $flag->entity_type,
- 'label' => $info['label'],
- ),
- 'flagging_user' => array(
- 'type' => 'user',
- 'label' => t('flagging user'),
- ),
- 'flagging' => array(
- 'type' => 'flagging',
- 'label' => t('flagging'),
- ),
- );
-
- // For each flag we define two events.
- $items['flag_flagged_' . $flag->name] = array(
- 'group' => t('Flag'),
- 'label' => t('A @flag-type has been flagged, under "@flag-title"', array('@flag-title' => $flag->get_title(), '@flag-type' => t($flag->entity_type))),
- 'variables' => $variables,
- 'access callback' => 'flag_rules_integration_access',
- );
- $items['flag_unflagged_' . $flag->name] = array(
- 'group' => t('Flag'),
- 'label' => t('A @flag-type has been unflagged, under "@flag-title"', array('@flag-title' => $flag->get_title(), '@flag-type' => t($flag->entity_type))),
- 'variables' => $variables,
- 'access callback' => 'flag_rules_integration_access',
- );
- }
- }
- return $items;
-}
-
-/**
- * Implements hook_rules_action_info().
- */
-function flag_rules_action_info() {
- $param_defaults = array(
- 'flagging_user' => array(
- 'type' => 'user',
- 'label' => t('User on whose behalf to flag'),
- 'description' => t('For non-global flags, this is the user on whose behalf to flag the object. In addition, if checked below, the access permissions to the flag are checked against this user.'),
- ),
- 'permission_check' => array(
- 'type' => 'boolean',
- 'label' => t('Skip permission check'),
- 'description' => t('Whether to ignore permissions of the user on whose behalf to flag.'),
- 'restriction' => 'input',
- ),
- );
- $items = array(
- 'flag_trim' => array(
- 'label' => t('Trim a flag'),
- 'base' => 'flag_rules_action_trim',
- 'parameter' => array(
- 'flag' => array(
- 'type' => 'flag',
- 'label' => t('Flag'),
- ),
- 'flagging_user' => array(
- 'type' => 'user',
- 'label' => t('User whose flag to trim'),
- 'description' => t('For non-global flags, this is the user whose flag to trim. (For global flags, this argument is ignored.)'),
- ),
- 'cutoff_size' => array(
- 'type' => 'integer',
- 'label' => t('Flag queue size'),
- 'description' => t('The maximum number of objects to keep in the queue. Newly flagged objects will be kept; older ones will be removed. Tip: by typing "1" here you implement a singleton.'),
- ),
- 'trim_newest' => array(
- 'type' => 'boolean',
- 'label' => t('Trim newest flags'),
- 'description' => t('Checking this will trim the newest flags. This will prevent new flags once a limit is reached.'),
- ),
- 'permission_check' => $param_defaults['permission_check'],
- ),
- 'group' => t('Flag'),
- 'access callback' => 'flag_rules_integration_access',
- ),
- 'fetch_overall_flag_count' => array(
- 'label' => t('Fetch overall flag count'),
- 'base' => 'flag_rules_action_fetch_overall_flag_count',
- 'parameter' => array(
- 'flag' => array(
- 'type' => 'flag',
- 'label' => t('Flag'),
- ),
- ),
- 'provides' => array(
- 'overall_flag_count' => array(
- 'label' => t('Overall flag count'),
- 'type' => 'integer',
- ),
- ),
- 'group' => t('Flag'),
- 'access callback' => 'flag_rules_integration_access',
- ),
- 'fetch_entity_flag_count' => array(
- 'label' => t('Fetch entity flag count'),
- 'base' => 'flag_rules_action_fetch_entity_flag_count',
- 'parameter' => array(
- 'flag' => array(
- 'type' => 'flag',
- 'label' => t('Flag'),
- ),
- 'entity_type' => array(
- 'type' => 'text',
- 'label' => t('Entity type'),
- 'options list' => 'flag_rules_get_flag_types',
- 'restriction' => 'input',
- ),
- ),
- 'provides' => array(
- 'entity_flag_count' => array(
- 'label' => t('Entity flag count'),
- 'type' => 'integer',
- ),
- ),
- 'group' => t('Flag'),
- 'access callback' => 'flag_rules_integration_access',
- ),
- 'fetch_user_flag_count' => array(
- 'label' => t('Fetch user flag count'),
- 'base' => 'flag_rules_action_fetch_user_flag_count',
- 'parameter' => array(
- 'flag' => array(
- 'type' => 'flag',
- 'label' => t('Flag'),
- ),
- 'user' => array(
- 'type' => 'user',
- 'label' => t('User'),
- ),
- ),
- 'provides' => array(
- 'user_flag_count' => array(
- 'label' => t('User flag count'),
- 'type' => 'integer',
- ),
- ),
- 'group' => t('Flag'),
- 'access callback' => 'flag_rules_integration_access',
- ),
- );
- foreach (flag_get_types() as $type) {
- $entity_info = entity_get_info($type);
- $label = $entity_info['label'];
- $items += array(
- 'flag_fetch_' . $type . '_by_user' => array(
- 'label' => t('Fetch @label flagged by user', array('@label' => $label)),
- 'base' => 'flag_rules_action_fetch_entity_by_user',
- 'parameter' => array(
- 'flag' => array(
- 'type' => 'flag',
- 'label' => t('Flag'),
- 'flag_type' => $type,
- 'description' => t('The flag to check for.'),
- ),
- 'flagging_user' => array(
- 'type' => 'user',
- 'label' => t('User who flagged the @label', array('@label' => $label)),
- 'description' => t('For non-global flags, this is the user who flagged the @label. (For global flags, this argument is ignored.)', array('@label' => $label)),
- ),
- ),
- 'provides' => array(
- 'content_flagged_by_user' => array(
- 'label' => t('Content flagged by user'),
- 'type' => 'list<' . $type . '>',
- ),
- ),
- 'group' => t('Flag'),
- 'access callback' => 'flag_rules_integration_access',
- ),
- 'flag_flag' . $type => array(
- 'label' => t('Flag a @label', array('@label' => $label)),
- 'base' => 'flag_rules_action_flag',
- 'parameter' => array(
- 'flag' => array(
- 'type' => 'flag',
- 'label' => t('Flag'),
- 'flag_type' => $type,
- 'description' => t('The flag to check for.'),
- ),
- $type => array(
- 'type' => $type,
- 'label' => $label,
- ),
- ) + $param_defaults,
- 'group' => t('Flag'),
- 'access callback' => 'flag_rules_integration_access',
- ),
- 'flag_unflag' . $type => array(
- 'label' => t('Unflag a @label', array('@label' => $label)),
- 'base' => 'flag_rules_action_unflag',
- 'parameter' => array(
- 'flag' => array(
- 'type' => 'flag',
- 'label' => t('Flag'),
- 'flag_type' => $type,
- 'description' => t('The flag to check for.'),
- ),
- $type => array(
- 'type' => $type,
- 'label' => $label,
- ),
- ) + $param_defaults,
- 'group' => t('Flag'),
- 'access callback' => 'flag_rules_integration_access',
- ),
- );
- $items['flag_fetch_users_' . $type] = array(
- 'label' => t('Fetch users who have flagged a @label', array('@label' => $label)),
- 'base' => 'flag_rules_action_fetch_users',
- 'parameter' => array(
- 'flag' => array(
- 'type' => 'flag',
- 'label' => t('Flag'),
- 'flag_type' => $type,
- 'description' => t('Choose the flag for which to fetch the users.'),
- ),
- $type => array(
- 'type' => $type,
- 'label' => $label,
- ),
- ),
- 'provides' => array(
- 'users' => array(
- 'label' => t('Users who flagged'),
- 'type' => 'list',
- ),
- ),
- 'group' => t('Flag'),
- 'access callback' => 'flag_rules_integration_access',
- );
- }
- // For backward compatibility sake. This was the original name of the 'fetch node by user'.
- $items['flag_fetch_entity_by_user'] = $items['flag_fetch_node_by_user'];
- $items['flag_fetch_entity_by_user']['label'] .= ' '. t('(Legacy)');
- return $items;
-}
-
-/**
- * Base action implementation: Flag.
- */
-function flag_rules_action_flag($flag, $entity, $flagging_user, $permissions_check) {
- $flag->flag('flag', $flag->get_entity_id($entity), $flagging_user, $permissions_check);
-}
-
-/**
- * Base action implementation: Unflag.
- */
-function flag_rules_action_unflag($flag, $entity, $flagging_user, $permissions_check) {
- $flag->flag('unflag', $flag->get_entity_id($entity), $flagging_user, $permissions_check);
-}
-
-/**
- * Base action implementation: Trim flag.
- */
-function flag_rules_action_trim($flag, $flagging_user, $cutoff_size, $trim_newest, $permissions_check) {
- // For some reason, when this action fires in response to a flagging event,
- // as an anonymous user, then the $flagging_user is sent through as FALSE.
- // Not sure why. This workaround fixes the problem in this specific case.
- if ($flagging_user === FALSE) {
- $flagging_user = $GLOBALS['user'];
- }
- flag_trim_flag($flag, $flagging_user, $cutoff_size, $trim_newest, $permissions_check);
-}
-
-/**
- * Base action implementation: Fetch users who flagged an entity.
- */
-function flag_rules_action_fetch_users($flag, $entity) {
- $result = db_select('flagging', 'fc')
- ->fields('fc', array('uid'))
- ->condition('entity_type', $flag->entity_type)
- ->condition('entity_id', $flag->get_entity_id($entity))
- ->condition('fid', $flag->fid)
- ->execute();
- $uids = $result->fetchCol();
- // Filter out anonymous users.
- return array('users' => array_filter($uids));
-}
-
-/**
- * Base action implementation: Fetch entities who were flagged a user.
- */
-function flag_rules_action_fetch_entity_by_user($flag, $entity) {
- $user = entity_metadata_wrapper('user', $entity);
- $sid = $user->flag_sid->value();
- $query = db_select('flagging', 'fc')
- ->fields('fc', array('entity_id'))
- ->condition('entity_type', $flag->entity_type)
- ->condition('uid', $user->uid->value())
- ->condition('fid', $flag->fid);
- // Filter out any bad session ids and any users that aren't anonymous.
- if (!empty($sid) && $sid != -1) {
- $query->condition('sid', $sid);
- }
- $result = $query->execute();
- $flagged = $result->fetchCol();
- return array('content_flagged_by_user' => $flagged);
-}
-
-/**
- * Base action implementation: Fetch overall count for a particular flag.
- */
-function flag_rules_action_fetch_overall_flag_count($flag) {
- $count = flag_get_flag_counts($flag->name);
- return array('overall_flag_count' => $count);
-}
-
-/**
- * Helper function which will return all the available flag types.
- *
- * @return
- * An array of flag type names keyed by the type name.
- */
-function flag_rules_get_flag_types() {
- $types = array();
- foreach (flag_get_types() as $type) {
- $types[$type] = $type;
- }
- return $types;
-}
-
-/**
- * Base action implementation: Fetch count of flags for a particular entity.
- */
-function flag_rules_action_fetch_entity_flag_count($flag, $entity_type) {
- $count = flag_get_entity_flag_counts($flag, $entity_type);
- return array('entity_flag_count' => $count);
-}
-
-/**
- * Base action implementation: Fetch user's flag count.
- */
-function flag_rules_action_fetch_user_flag_count($flag, $user) {
- $count = flag_get_user_flag_counts($flag, $user);
- return array('user_flag_count' => $count);
-}
-
-/**
- * Implements hook_rules_condition_info().
- */
-function flag_rules_condition_info() {
- $items = array();
- foreach (flag_get_types() as $type) {
- $entity_info = entity_get_info($type);
- $label = isset($entity_info[$type]['label']) ? $entity_info[$type]['label'] : $type;
- $items += array(
- 'flag_threshold_' . $type => array(
- 'label' => drupal_ucfirst(t('@type has flagging count', array('@type' => $label))),
- 'base' => 'flag_rules_condition_threshold',
- 'parameter' => array(
- 'flag' => array(
- 'type' => 'flag',
- 'label' => t('Flag'),
- 'flag_type' => $type,
- 'description' => t('The flag to check for.')
- ),
- $type => array(
- 'type' => $type,
- 'label' => $label,
- ),
- 'number' => array(
- 'type' => 'integer',
- 'label' => t('Number'),
- 'description' => t('The number against which to test the number of times the object is flagged. For example, if you type "3" here, and choose "Greater than" for the operator, then this condition will return TRUE if the object is flagged more than three times.'),
- ),
- 'operator' => array(
- 'type' => 'text',
- 'label' => t('Comparison operator'),
- 'options list' => 'flag_rules_condition_threshold_operator_options',
- 'restriction' => 'input',
- 'default value' => '=',
- 'optional' => TRUE,
- ),
- ),
- 'group' => t('Flag'),
- 'access callback' => 'flag_rules_integration_access',
- ),
- 'flag_flagged_' . $type => array(
- 'label' => drupal_ucfirst(t('@type is flagged', array('@type' => $label))),
- 'base' => 'flag_rules_condition_flagged',
- 'parameter' => array(
- 'flag' => array(
- 'type' => 'flag',
- 'label' => t('Flag'),
- 'flag_type' => $type,
- 'description' => t('The flag to check for.')
- ),
- $type => array(
- 'type' => $type,
- 'label' => $label,
- ),
- 'flagging_user' => array(
- 'type' => 'user',
- 'label' => t('User on whose behalf to check'),
- 'description' => t('For non-global flags, this is the user on whose behalf the flag is checked.'),
- ),
- ),
- 'group' => t('Flag'),
- 'access callback' => 'flag_rules_integration_access',
- ),
- );
- }
- return $items;
-}
-
-/**
- * Options list callback for the operator parameter of the flagging threshold condition.
- */
-function flag_rules_condition_threshold_operator_options() {
- return array(
- '>' => t('Greater than'),
- '>=' => t('Greater than or equal'),
- '=' => t('Equal to'),
- '<=' => t('Less than or equal'),
- '<' => t('Less than'),
- );
-}
-
-/**
- * Condition: Check flagging count.
- */
-function flag_rules_condition_threshold($flag, $entity, $number, $operator = '=') {
- $count = $flag->get_count($flag->get_entity_id($entity));
-
- switch ($operator) {
- case '>' : return $count > $number;
- case '>=': return $count >= $number;
- case '=' : return $count == $number;
- case '<' : return $count < $number;
- case '<=': return $count <= $number;
- }
-}
-
-/**
- * Condition: Flag is flagged.
- */
-function flag_rules_condition_flagged($flag, $entity, $account) {
- return $flag->is_flagged($flag->get_entity_id($entity), $account->uid);
-}
-
-/**
- * Rules integration access callback.
- */
-function flag_rules_integration_access($type, $name) {
- return user_access('administer flags');
-}
diff --git a/flag_actions.info b/flag_actions.info
deleted file mode 100644
index 9f1403b..0000000
--- a/flag_actions.info
+++ /dev/null
@@ -1,9 +0,0 @@
-name = Flag actions
-description = Execute actions on Flag events.
-core = 7.x
-dependencies[] = flag
-package = Flags
-configure = admin/structure/flags/actions
-
-files[] = flag.install
-files[] = flag_actions.module
\ No newline at end of file
diff --git a/flag_actions.install b/flag_actions.install
deleted file mode 100644
index a41286d..0000000
--- a/flag_actions.install
+++ /dev/null
@@ -1,95 +0,0 @@
- array(
- 'aid' => array(
- 'type' => 'serial',
- 'not null' => TRUE,
- 'disp-width' => '5',
- ),
- 'fid' => array(
- 'type' => 'int',
- 'size' => 'small',
- 'not null' => FALSE,
- 'disp-width' => '5',
- ),
- 'event' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => FALSE,
- ),
- 'threshold' => array(
- 'type' => 'int',
- 'size' => 'small',
- 'not null' => TRUE,
- 'default' => 0,
- 'disp-width' => '5',
- ),
- 'repeat_threshold' => array(
- 'type' => 'int',
- 'size' => 'small',
- 'not null' => TRUE,
- 'default' => 0,
- 'disp-width' => '5',
- ),
- 'callback' => array(
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'parameters' => array(
- 'type' => 'text',
- 'size' => 'big',
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('aid'),
- );
-
- return $schema;
-}
-
-/**
- * Add a "repeat_threshold" value to all existing Flag actions.
- */
-function flag_actions_update_6200() {
- // Add the new repeat_threshold column.
- if (!db_field_exists('flag_actions', 'repeat_threshold')) {
- $column = array(
- 'type' => 'int',
- 'size' => 'small',
- 'not null' => TRUE,
- 'default' => 0,
- 'disp-width' => '5',
- );
- db_add_field('flag_actions', 'repeat_threshold', $column);
- }
-
- // Update the normal threshold column to default to 0.
- $column = array(
- 'type' => 'int',
- 'size' => 'small',
- 'not null' => TRUE,
- 'default' => 0,
- 'disp-width' => '5',
- );
- db_change_field('flag_actions', 'threshold', 'threshold', $column);
-}
diff --git a/flag_actions.module b/flag_actions.module
deleted file mode 100644
index f4c3aed..0000000
--- a/flag_actions.module
+++ /dev/null
@@ -1,692 +0,0 @@
- 'Actions',
- 'page callback' => 'flag_actions_page',
- 'access callback' => 'user_access',
- 'access arguments' => array('administer actions'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 1,
- );
- $items[FLAG_ADMIN_PATH . '/actions/add'] = array(
- 'title' => 'Add action',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('flag_actions_form', NULL, 5),
- 'access callback' => 'user_access',
- 'access arguments' => array('administer actions'),
- 'type' => MENU_CALLBACK,
- );
- $items[FLAG_ADMIN_PATH . '/actions/delete'] = array(
- 'title' => 'Delete action',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('flag_actions_delete_form', 5),
- 'access callback' => 'user_access',
- 'access arguments' => array('administer actions'),
- 'type' => MENU_CALLBACK,
- );
- $items[FLAG_ADMIN_PATH . '/actions/configure'] = array(
- 'title' => 'Edit action',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('flag_actions_form', 5),
- 'access callback' => 'user_access',
- 'access arguments' => array('administer actions'),
- 'type' => MENU_CALLBACK,
- );
-
- return $items;
-}
-
-/**
- * Implements hook_theme().
- */
-function flag_actions_theme() {
- return array(
- 'flag_actions_page' => array(
- 'variables' => array('actions' => NULL, 'form' => NULL),
- ),
- 'flag_actions_add_form' => array(
- 'render element' => 'form',
- ),
- 'flag_actions_flag_form' => array(
- 'render element' => 'form',
- ),
- );
-}
-
-function flag_actions_get_action($aid) {
- $actions = flag_actions_get_actions();
- return $actions[$aid];
-}
-
-function flag_actions_get_actions($flag_name = NULL, $reset = FALSE) {
- $flag_actions = &drupal_static(__FUNCTION__);
- module_load_include('inc', 'flag', 'includes/flag.actions');
-
- // Get a list of all possible actions defined by modules.
- $actions = module_invoke_all('action_info');
-
- // Retrieve the list of user-defined flag actions.
- if (!isset($flag_actions) || $reset) {
- $flag_actions = array();
- $query = db_select('flag_actions', 'a');
- $query->innerJoin('flag', 'f', 'a.fid = f.fid');
- $query->addField('f', 'name', 'flag');
- $result = $query
- ->fields('a')
- ->execute();
- foreach ($result as $action) {
- if (!isset($actions[$action->callback])) {
- $actions[$action->callback] = array(
- 'description' => t('Missing action "@action-callback". Module providing it was either uninstalled or disabled.', array('@action-callback' => $action->callback)),
- 'configurable' => FALSE,
- 'type' => 'node',
- 'missing' => TRUE,
- );
- }
- $action->parameters = unserialize($action->parameters);
- $action->label = $actions[$action->callback]['label'];
- $action->configurable = $actions[$action->callback]['configurable'];
- $action->behavior = isset($actions[$action->callback]['behavior']) ? $actions[$action->callback]['behavior'] : array();
- $action->type = $actions[$action->callback]['type'];
- $action->missing = !empty($actions[$action->callback]['missing']);
-
- $flag_actions[$action->aid] = $action;
- }
- }
-
- // Filter actions to a specified flag.
- if (isset($flag_name)) {
- $specific_flag_actions = array();
- foreach ($flag_actions as $aid => $action) {
- if ($action->flag == $flag_name) {
- $specific_flag_actions[$aid] = $action;
- }
- }
- return $specific_flag_actions;
- }
-
- return $flag_actions;
-}
-
-/**
- * Insert a new flag action.
- *
- * @param $fid
- * The flag object ID.
- * @param $event
- * The flag event, such as "flag" or "unflag".
- * @param $threshold
- * The flagging threshold at which this action will be executed.
- * @param $repeat_threshold
- * The number of additional flaggings after which the action will be repeated.
- * @param $callback
- * The action callback to be executed.
- * @param $parameters
- * The action parameters.
- */
-function flag_actions_insert_action($fid, $event, $threshold, $repeat_threshold, $callback, $parameters) {
- return db_insert('flag_actions')
- ->fields(array(
- 'fid' => $fid,
- 'event' => $event,
- 'threshold' => $threshold,
- 'repeat_threshold' => $repeat_threshold,
- 'callback' => $callback,
- 'parameters' => serialize($parameters),
- ))
- ->execute();
-}
-
-/**
- * Update an existing flag action.
- *
- * @param $aid
- * The flag action ID to update.
- * @param $event
- * The flag event, such as "flag" or "unflag".
- * @param $threshold
- * The flagging threshold at which this action will be executed.
- * @param $repeat_threshold
- * The number of additional flaggings after which the action will be repeated.
- * @param $parameters
- * The action parameters.
- */
-function flag_actions_update_action($aid, $event, $threshold, $repeat_threshold, $parameters) {
- return db_update('flag_actions')
- ->fields(array(
- 'event' => $event,
- 'threshold' => $threshold,
- 'repeat_threshold' => $repeat_threshold,
- 'parameters' => serialize($parameters),
- ))
- ->condition('aid', $aid)
- ->execute();
-}
-
-/**
- * Delete a flag action.
- *
- * @param $aid
- * The flag action ID to delete.
- */
-function flag_actions_delete_action($aid) {
- return db_delete('flag_actions', array('return' => Database::RETURN_AFFECTED))
- ->condition('aid', $aid)
- ->execute();
-}
-
-/**
- * Perform flag actions.
- */
-function flag_actions_do($event, $flag, $entity_id, $account) {
- $actions = flag_actions_get_actions($flag->name);
- if (!$actions) {
- return;
- }
-
- $flag_action = $flag->get_flag_action($entity_id);
- $flag_action->action = $event;
- $flag_action->count = $count = $flag->get_count($entity_id);
- $relevant_objects = $flag->get_relevant_action_objects($entity_id);
- $object_changed = FALSE;
- foreach ($actions as $aid => $action) {
- if ($action->event == 'flag') {
- $at_threshold = ($count == $action->threshold);
- $repeat = $action->repeat_threshold ? (($count > $action->threshold) && (($count - $action->threshold) % $action->repeat_threshold == 0)) : FALSE;
- }
- elseif ($action->event == 'unflag') {
- $at_threshold = ($count == $action->threshold - 1);
- $repeat = $action->repeat_threshold ? (($count < $action->threshold - 1) && (($count - $action->threshold - 1) % $action->repeat_threshold == 0)) : FALSE;
- }
- if (($at_threshold || $repeat) && $action->event == $event && !$action->missing) {
- $context = $action->parameters;
- $context['callback'] = $action->callback;
- // We're setting 'hook' to something, to prevent PHP warnings by actions
- // who read it. Maybe we should set it to nodeapi/comment/user, depending
- // on the flag, because these three are among the only hooks some actions
- // in system.module "know" to work with.
- $context['hook'] = 'flag';
- $context['type'] = $action->type;
- $context['account'] = $account;
- $context['flag'] = $flag;
- $context['flag-action'] = $flag_action;
- // We add to the $context all the objects we know about:
- $context = array_merge($relevant_objects, $context);
- $callback = $action->callback;
-
- if (isset($relevant_objects[$action->type])) {
- $callback($relevant_objects[$action->type], $context);
- }
- else {
- // What object shall we send as last resort? Let's send a node, or
- // the flag's object.
- if (isset($relevant_objects['node'])) {
- $callback($relevant_objects['node'], $context);
- }
- else {
- $callback($relevant_objects[$flag->entity_type], $context);
- }
- }
-
- if (is_array($action->behavior) && in_array('changes_property', $action->behavior)) {
- $object_changed = TRUE;
- }
- }
- }
-
- // Actions by default do not save elements unless the save action is
- // explicitly added. We run it automatically upon flagging.
- if ($object_changed) {
- $save_action = $action->type . '_save_action';
- if (function_exists($save_action)) {
- $save_action($relevant_objects[$action->type]);
- }
- }
-}
-
-/**
- * Menu callback for FLAG_ADMIN_PATH/actions.
- */
-function flag_actions_page() {
- $actions = flag_actions_get_actions();
- $add_action_form = drupal_get_form('flag_actions_add_form');
-
- return theme('flag_actions_page', array('actions' => $actions, 'form' => $add_action_form));
-}
-
-/**
- * Theme the list of actions currently in place for flags.
- */
-function theme_flag_actions_page($variables) {
- $actions = $variables['actions'];
- $add_action_form = $variables['form'];
-
- $rows = array();
- foreach ($actions as $action) {
- $flag = flag_get_flag($action->flag);
-
- // Build a sample string representing repeating actions.
- if ($action->repeat_threshold) {
- $repeat_count = 3;
- $repeat_subtract = ($action->event == 'flag') ? 1 : -1;
- $repeat_samples = array();
- for ($n = 1; $n < $repeat_count + 2; $n++) {
- $sample = $action->threshold + (($n * $action->repeat_threshold) * $repeat_subtract);
- if ($sample > 0) {
- $repeat_samples[] = $sample;
- }
- }
- if (count($repeat_samples) > $repeat_count) {
- $repeat_samples[$repeat_count] = '…';
- }
- $repeat_string = implode(', ', $repeat_samples);
- }
- else {
- $repeat_string = '-';
- }
-
- $row = array();
- $row[] = $flag->get_title();
- $row[] = ($action->event == 'flag' ? '≥ ' : '< ') . $action->threshold;
- $row[] = $repeat_string;
- $row[] = empty($action->missing) ? $action->label : '' . $action->label . '
';
- $row[] = l(t('edit'), FLAG_ADMIN_PATH . '/actions/configure/' . $action->aid);
- $row[] = l(t('delete'), FLAG_ADMIN_PATH . '/actions/delete/' . $action->aid);
- $rows[] = $row;
- }
-
- if (empty($rows)) {
- $rows[] = array(array('data' => t('Currently no flag actions. Use the Add new flag action form to add an action.'), 'colspan' => 6));
- }
-
- $header = array(
- t('Flag'),
- t('Threshold'),
- t('Repeats'),
- t('Action'),
- array('data' => t('Operations'), 'colspan' => 2),
- );
-
- $output = '';
- $output .= theme('table', array('header' => $header, 'rows' => $rows));
- $output .= drupal_render($add_action_form);
- return $output;
-}
-
-/**
- * Modified version of the Add action form that redirects back to the flag list.
- */
-function flag_actions_add_form($form, &$form_state) {
- $flags = flag_get_flags();
- $options = array();
- foreach ($flags as $flag) {
- $options[$flag->name] = $flag->get_title();
- }
-
- if (empty($options)) {
- $options[] = t('No flag available');
- }
-
- $form['flag'] = array(
- '#type' => 'select',
- '#options' => empty($options) ? array(t('No flag available')) : $options,
- '#disabled' => empty($options),
- '#title' => t('Select a flag'),
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Add action'),
- );
-
- return $form;
-}
-
-function flag_actions_add_form_submit($form, &$form_state) {
- if ($form_state['values']['flag']) {
- $form_state['redirect'] = array(FLAG_ADMIN_PATH . '/actions/add/' . $form_state['values']['flag']);
- }
-}
-
-function theme_flag_actions_add_form($variables) {
- $form = $variables['form'];
-
- $fieldset = array(
- '#type' => 'fieldset',
- '#title' => t('Add a new flag action'),
- '#children' => ''. drupal_render($form['flag']) . drupal_render($form['submit']) .'
',
- '#parents' => array('add_action'),
- '#attributes' => array(),
- '#groups' => array('add_action' => array()),
- );
-
- return drupal_render($fieldset) . drupal_render_children($form);
-}
-
-/**
- * Generic configuration form for configuration of flag actions.
- *
- * @param $form_state
- * The form state.
- * @param $aid
- * If editing an action, an action ID must be passed in.
- * @param $flag_name
- * If adding a new action to a flag, a flag name must be specified.
- *
- */
-function flag_actions_form($form, &$form_state, $aid = NULL, $flag_name = NULL) {
- // This is a multistep form. Get the callback value if set and continue.
- if (isset($form_state['storage']['callback'])) {
- $callback = $form_state['storage']['callback'];
- unset($form_state['storage']['callback']);
- }
-
- if (isset($aid)) {
- $action = flag_actions_get_action($aid);
- $callback = $action->callback;
- $flag = flag_get_flag($action->flag);
- drupal_set_title(t('Edit the "@action" action for the @title flag', array('@action' => $action->label, '@title' => $flag->get_title())));
- }
- elseif (isset($flag_name)) {
- $flag = flag_get_flag($flag_name);
- }
-
- if (empty($flag)) {
- drupal_not_found();
- }
-
- $form['new'] = array(
- '#type' => 'value',
- '#value' => isset($callback) ? FALSE: TRUE,
- );
-
- if (!isset($callback)) {
- drupal_set_title(t('Add an action to the @title flag', array('@title' => $flag->get_title())));
-
- $actions = $flag->get_valid_actions();
- $options = array();
- foreach($actions as $key => $action) {
- $options[$key] = $action['label'];
- }
-
- $form['callback'] = array(
- '#title' => t('Select an action'),
- '#type' => 'select',
- '#options' => $options,
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Continue'),
- );
-
- return $form;
- }
- elseif (!isset($action)) {
- $actions = $flag->get_valid_actions();
- $action = (object)$actions[$callback];
- $action->parameters = array();
- $action->event = 'flag';
- $action->threshold = 10;
- $action->repeat_threshold = 0;
- drupal_set_title(t('Add "@action" action to the @title flag', array('@action' => $action->label, '@title' => $flag->get_title())));
- }
-
- $form['flag'] = array(
- '#tree' => TRUE,
- '#weight' => -9,
- '#theme' => 'flag_actions_flag_form',
- '#action' => $action,
- '#flag' => $flag,
- );
-
- $form['flag']['flag'] = array(
- '#type' => 'value',
- '#value' => $flag,
- );
-
- $form['flag']['callback'] = array(
- '#type' => 'value',
- '#value' => $callback,
- );
-
- $form['flag']['aid'] = array(
- '#type' => 'value',
- '#value' => $aid,
- );
-
- $form['flag']['event'] = array(
- '#type' => 'select',
- '#options' => array(
- 'flag' => t('reaches'),
- 'unflag' => t('falls below'),
- ),
- '#default_value' => $action->event,
- );
-
- $form['flag']['threshold'] = array(
- '#type' => 'textfield',
- '#size' => 6,
- '#maxlength' => 6,
- '#default_value' => $action->threshold,
- '#required' => TRUE,
- );
-
- $form['flag']['repeat_threshold'] = array(
- '#type' => 'textfield',
- '#size' => 6,
- '#maxlength' => 6,
- '#default_value' => $action->repeat_threshold,
- );
-
- if ($flag->global) {
- $form['flag']['threshold']['#disabled'] = 1;
- $form['flag']['threshold']['#value'] = 1;
- $form['flag']['repeat_threshold']['#access'] = FALSE;
- $form['flag']['repeat_threshold']['#value'] = 0;
- }
-
- // Merge in the standard flag action form.
- $action_form = $callback .'_form';
- $edit = array();
- if (function_exists($action_form)) {
- $edit += $action->parameters;
- $edit['actions_label'] = $action->label;
- $edit['actions_type'] = $action->type;
- $edit['actions_flag'] = $flag->name;
- $additions = flag_actions_form_additions($action_form, $edit);
- $form = array_merge($form, $additions);
- }
-
- // Add a few customizations to existing flag actions.
- $flag_actions_form = 'flag_actions_'. $callback .'_form';
- if (function_exists($flag_actions_form)) {
- $flag_actions_form($form, $flag, $edit);
- }
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- );
-
- return $form;
-}
-
-/**
- * Execute an action form callback to retrieve form additions.
- *
- * This function prevents the form callback from modifying local variables.
- */
-function flag_actions_form_additions($callback, $edit) {
- return $callback($edit);
-}
-
-/**
- * Generic submit handler for validating flag actions.
- */
-function flag_actions_form_validate($form, &$form_state) {
- // Special validation handlers may be needed to save this form properly.
- // Try to load the action's validation routine if needed.
- if (isset($form_state['values']['flag']['callback'])) {
- $callback = $form_state['values']['flag']['callback'];
- $validate_function = $callback . '_validate';
- if (function_exists($validate_function)) {
- $validate_function($form, $form_state);
- }
- }
-}
-
-/**
- * Generic submit handler for saving flag actions.
- */
-function flag_actions_form_submit($form, &$form_state) {
- // If simply gathering the callback, save it to form state storage and
- // rebuild the form to gather the complete information.
- if ($form_state['values']['new']) {
- $form_state['storage']['callback'] = $form_state['values']['callback'];
- $form_state['rebuild'] = TRUE;
- return;
- }
-
- $aid = $form_state['values']['flag']['aid'];
- $flag = $form_state['values']['flag']['flag'];
- $event = $form_state['values']['flag']['event'];
- $threshold = $form_state['values']['flag']['threshold'];
- $repeat_threshold = $form_state['values']['flag']['repeat_threshold'];
- $callback = $form_state['values']['flag']['callback'];
-
- // Specialized forms may need to execute their own submit handlers on save.
- $submit_function = $callback . '_submit';
- $parameters = function_exists($submit_function) ? $submit_function($form, $form_state) : array();
-
- if (empty($aid)) {
- $aid = flag_actions_insert_action($flag->fid, $event, $threshold, $repeat_threshold, $callback, $parameters);
- $form_state['values']['flag']['aid'] = $aid;
- $form_state['values']['flag']['is_new'] = TRUE;
- }
- else {
- flag_actions_update_action($aid, $event, $threshold, $repeat_threshold, $parameters);
- }
-
- $action = flag_actions_get_action($aid);
-
- drupal_set_message(t('The "@action" action for the @title flag has been saved.', array('@action' => $action->label, '@title' => $flag->get_title())));
- $form_state['redirect'] = FLAG_ADMIN_PATH . '/actions';
-}
-
-function theme_flag_actions_flag_form($variables) {
- $form = $variables['form'];
-
- $event = drupal_render($form['event']);
- $threshold = drupal_render($form['threshold']);
- $repeat_threshold = drupal_render($form['repeat_threshold']);
- $action = $form['#action']->label;
-
- $output = '';
- $output .= '';
- $output .= t('Perform action when content !event !threshold flags', array('!event' => $event, '!threshold' => $threshold));
- if ($form['#flag']->global) {
- $output .= ' ' . t('(global flags always have a threshold of 1)');
- }
- $output .= '
';
- $output .= '';
- if (!$form['#flag']->global) {
- $output .= t('Repeat this action every !repeat_threshold additional flags after the threshold is reached', array('!repeat_threshold' => $repeat_threshold));
- }
- $output .= '
';
-
- $element = array(
- '#title' => t('Flagging threshold'),
- '#required' => TRUE,
- );
-
- return $output . drupal_render_children($form);
-}
-
-function flag_actions_delete_form($form, &$form_state, $aid) {
- $action = flag_actions_get_action($aid);
- $flag = flag_get_flag($action->flag);
-
- $form['action'] = array(
- '#type' => 'value',
- '#value' => $action,
- );
-
- $form['flag'] = array(
- '#type' => 'value',
- '#value' => $flag,
- );
-
- $question = t('Delete the "@action" action for the @title flag?', array('@action' => $action->label, '@title' => $flag->get_title()));
- $path = FLAG_ADMIN_PATH . '/actions';
-
- return confirm_form($form, $question, $path, NULL, t('Delete'));
-}
-
-function flag_actions_delete_form_submit(&$form, &$form_state) {
- flag_actions_delete_action($form_state['values']['action']->aid);
- drupal_set_message(t('The "@action" action for the @title flag has been deleted.', array('@action' => $form_state['values']['action']->label, '@title' => $form_state['values']['flag']->get_title())));
- $form_state['redirect'] = FLAG_ADMIN_PATH . '/actions';
-}
-
-/**
- * Make modifications to the "Send e-mail" action form.
- */
-function flag_actions_system_send_email_action_form(&$form, &$flag, $context) {
- if (!isset($context['recipient'])) {
- $form['recipient']['#default_value'] = '[site:mail]';
- }
-
- if (!isset($context['subject'])) {
- $form['subject']['#default_value'] = t('Content Flagged @flag_title', array('@flag_title' => $flag->get_title()));
- }
-
- if (!isset($context['message'])) {
- $form['message']['#default_value'] = t("The @flag_entity_type [flag-action:content-title] has been flagged [flag-action:count] times with the @flag_title flag.\n\nView this @flag_entity_type at [flag-action:content-url].", array('@flag_entity_type' => $flag->entity_type, '@flag_title' => $flag->get_title()));
- }
-
- $form['help'] = array(
- '#type' => 'fieldset',
- '#title' => t('Tokens'),
- '#description' => t('The following tokens can be used in the recipient, subject, or message.'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
- $form['help']['basic'] = array(
- '#markup' => theme('flag_tokens_browser', array('types' => array('flag', 'flag-action'))),
- );
-
- $form['help']['tokens'] = array(
- '#type' => 'fieldset',
- '#title' => t('More tokens'),
- '#description' => t("Depending on the type of the content being flagged, the following tokens can be used in the recipients, subject, or message. For example, if the content being flagged is a node, you can use any of the node tokens --but you can't use the comment tokens: they won't be recognized. Similarly, if the content being flagged is a user, you can use only the user tokens."),
- '#value' => theme('flag_tokens_browser', array('types' => $flag->get_labels_token_types(), 'global_types' => FALSE)),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
-}
diff --git a/includes/flag.actions.inc b/includes/flag.actions.inc
deleted file mode 100644
index f414431..0000000
--- a/includes/flag.actions.inc
+++ /dev/null
@@ -1,243 +0,0 @@
- array(
- 'flag_flag' => array(
- 'label' => t('Object has been flagged with any flag'),
- ),
- 'flag_unflag' => array(
- 'label' => t('Object has been unflagged with any flag')
- ),
- ),
- );
-
- foreach (flag_get_flags() as $flag) {
- $hooks['flag']['flag_flag_' . $flag->name]['label'] = t('A %type has been flagged with %name', array('%type' => $flag->entity_type, '%name' => $flag->name));
- $hooks['flag']['flag_unflag_' . $flag->name]['label'] = t('A %type has been unflagged with %name', array('%type' => $flag->entity_type, '%name' => $flag->name));
- }
-
- return $hooks;
-}
-
-/**
- * Implements hook_action_info().
- */
-function flag_action_info() {
- return array(
- 'flag_node_action' => array(
- 'type' => 'node',
- 'label' => t('Flag (or unflag) a node'),
- 'configurable' => TRUE,
- 'triggers' => array(
- 'node_presave', 'node_insert', 'node_update', 'node_delete', 'node_view',
- 'comment_insert', 'comment_update', 'comment_delete', 'comment_view',
- ),
- ),
- 'flag_comment_action' => array(
- 'type' => 'comment',
- 'label' => t('Flag (or unflag) a comment'),
- 'configurable' => TRUE,
- 'triggers' => array(
- 'comment_insert', 'comment_update', 'comment_delete', 'comment_view',
- ),
- ),
- 'flag_user_action' => array(
- 'type' => 'user',
- 'label' => t('Flag (or unflag) a user'),
- 'configurable' => TRUE,
- 'triggers' => array(
- 'user_insert', 'user_update', 'user_delete', 'user_login', 'user_logout', 'user_view',
- ),
- ),
- );
-}
-
-/**
- * Implements hook_action_info_alter().
- *
- * Enable Flag actions on Node, Comment, and User hooks without
- * the trigger_unlock.module.
- */
-function flag_action_info_alter(&$actions) {
- $node_flags = flag_get_flags('node');
- $comment_flags = flag_get_flags('comment');
- $user_flags = flag_get_flags('user');
-
- foreach ($actions as $name => $action) {
- if (strpos($name, 'node') === 0) {
- $actions[$name]['triggers'][] = 'flag_flag';
- $actions[$name]['triggers'][] = 'flag_unflag';
- foreach ($node_flags as $flag) {
- $actions[$name]['triggers'][] = 'flag_flag_' . $flag->name;
- $actions[$name]['triggers'][] = 'flag_unflag_' . $flag->name;
- }
- }
- if (strpos($name, 'comment') === 0) {
- $actions[$name]['triggers'][] = 'flag_flag';
- $actions[$name]['triggers'][] = 'flag_unflag';
- foreach ($comment_flags as $flag) {
- $actions[$name]['triggers'][] = 'flag_flag_' . $flag->name;
- $actions[$name]['triggers'][] = 'flag_unflag_' . $flag->name;
- }
- }
- if (strpos($name, 'user') === 0) {
- $actions[$name]['triggers'][] = 'flag_flag';
- $actions[$name]['triggers'][] = 'flag_unflag';
- foreach ($user_flags as $flag) {
- $actions[$name]['triggers'][] = 'flag_flag_' . $flag->name;
- $actions[$name]['triggers'][] = 'flag_unflag_' . $flag->name;
- }
- }
- }
-}
-
-/**
- * Implements Drupal action. Flags a node.
- *
- * Note the first parameter is "object" because it may be a comment or a node.
- */
-function flag_node_action(&$object, $context = array()) {
- if ($flag = flag_get_flag($context['flag_action']['flag'])) {
- $account = isset($context['account']) ? $context['account'] : $GLOBALS['user'];
- $flag->flag($context['flag_action']['op'], $object->nid, $account, TRUE);
- }
-}
-
-/**
- * Form for configuring the Flag node action.
- */
-function flag_node_action_form($context = array()) {
- return flag_action_form($context, 'node');
-}
-
-/**
- * Submit function for the Flag node action form.
- */
-function flag_node_action_submit($form, $form_state) {
- return flag_action_submit($form, $form_state);
-}
-
-/**
- * Implements Drupal action. Flags a comment.
- */
-function flag_comment_action(&$comment, $context = array()) {
- if ($flag = flag_get_flag($context['flag_action']['flag'])) {
- $account = isset($context['account']) ? $context['account'] : $GLOBALS['user'];
- $flag->flag($context['flag_action']['op'], $comment->cid, $account, TRUE);
- }
-}
-
-/**
- * Form for configuring the Flag comment action.
- */
-function flag_comment_action_form($context) {
- return flag_action_form($context, 'comment');
-}
-
-/**
- * Submit function for the Flag comment action form.
- */
-function flag_comment_action_submit($form, $form_state) {
- return flag_action_submit($form, $form_state);
-}
-
-/**
- * Implements Drupal action. Flags a user.
- */
-function flag_user_action(&$user, $context = array()) {
- if ($flag = flag_get_flag($context['flag_action']['flag'])) {
- $account = isset($context['account']) ? $context['account'] : $GLOBALS['user'];
- $flag->flag($context['flag_action']['op'], $user->uid, $account, TRUE);
- }
-}
-
-/**
- * Form for configuring the Flag user action.
- */
-function flag_user_action_form($context) {
- return flag_action_form($context, 'user');
-}
-
-/**
- * Submit function for the Flag user action form.
- */
-function flag_user_action_submit($form, $form_state) {
- return flag_action_submit($form, $form_state);
-}
-
-/**
- * Generic form for configuring Flag actions.
- *
- * @param $context
- * The current action context.
- * @param $entity_type
- * The entity type applicable to this action, such as "node" or "comment".
- */
-function flag_action_form($context, $entity_type) {
- $form = array();
-
- $flags = flag_get_flags($entity_type);
- // If this is a flag_action action, do not allow the triggering flag.
- if (isset($context['actions_flag'])) {
- unset($flags[$context['actions_flag']]);
- }
- $options = drupal_map_assoc(array_keys($flags));
-
- $form['flag_action']['#tree'] = TRUE;
- $form['flag_action']['warning'] = array(
- '#markup' => '' . t("Note when setting a flag through actions, the selected flag will be flagged regardless of the user's permissions.") . '
',
- );
- $form['flag_action']['flag'] = array(
- '#title' => t('Flag to affect'),
- '#type' => 'radios',
- '#options' => $options,
- '#required' => TRUE,
- '#description' => t('When this action is fired, which flag should be flagged (or unflagged)?'),
- '#default_value' => isset($context['flag_action']['flag']) ? $context['flag_action']['flag'] : reset($options),
- );
-
- $form['flag_action']['op'] = array(
- '#title' => t('Flag operation'),
- '#type' => 'radios',
- '#options' => array('flag' => t('Flag'), 'unflag' => t('Unflag')),
- '#description' => t('When this action is fired, which operation should be performed on the flag?'),
- '#default_value' => isset($context['flag_action']['op']) ? $context['flag_action']['op'] : 'flag',
- );
-
- if (empty($options)) {
- $error = t('There are no available %type flags. Before you can create an action of this type, you need to create a %type flag.', array('%type' => $entity_type, '!url' => url(FLAG_ADMIN_PATH . '/add')));
- $form['flag_action']['flag']['#type'] = 'item';
- $form['flag_action']['flag']['#markup'] = $error;
- $form['flag_action']['flag']['#element_validate'][] = 'flag_action_validate_flag';
- $form['flag_action']['flag']['#flag_error'] = $error;
- }
-
- return $form;
-}
-
-/**
- * Generic validation handler for validating Flag action configuration.
- */
-function flag_action_validate_flag($element) {
- if (isset($element['#flag_error'])) {
- form_error($element, $element['#flag_error']);
- }
-}
-
-/**
- * Generic submission handler for saving Flag action configuration.
- */
-function flag_action_submit($form, $form_state) {
- return array(
- 'flag_action' => $form_state['values']['flag_action'],
- );
-}
diff --git a/includes/flag.admin.inc b/includes/flag.admin.inc
deleted file mode 100644
index 555e5d4..0000000
--- a/includes/flag.admin.inc
+++ /dev/null
@@ -1,345 +0,0 @@
-name]['weight'] = array(
- '#type' => 'weight',
- '#delta' => count($flags) + 5,
- '#default_value' => $flag->weight,
- '#attributes' => array('class' => array('flag-weight')),
- );
- }
-
- $form['actions'] = array(
- '#type' => 'actions',
- );
-
- if (count($flags) == 1) {
- // Don't show weights with only one flag.
- unset($form['flags'][$flag->name]['weight']);
- }
- elseif (count($flags) > 1) {
- // Only show the form button if there are several flags.
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save flag order'),
- );
- }
-
- return $form;
-}
-
-/**
- * Submit handler for the flag_admin_listing form. Save flag weight ordering.
- */
-function flag_admin_listing_submit($form, &$form_state) {
- foreach ($form['#flags'] as $flag) {
- if ($flag->weight != $form_state['values']['flags'][$flag->name]['weight']) {
- $flag->weight = $form_state['values']['flags'][$flag->name]['weight'];
- $flag->save();
- }
- }
-}
-
-/**
- * Theme the output of the normal, database flags into a table.
- */
-function theme_flag_admin_listing($variables) {
- $form = $variables['form'];
- $flags = $form['#flags'];
-
- $output = '';
-
- foreach ($flags as $flag) {
- $ops = array(
- 'flags_edit' => array('title' => t('edit'), 'href' => $flag->admin_path('edit')),
- 'flags_fields' => array('title' => t('manage fields'), 'href' => $flag->admin_path('fields')),
- 'flags_delete' => array('title' => t('delete'), 'href' => $flag->admin_path('delete')),
- 'flags_export' => array('title' => t('export'), 'href' => $flag->admin_path('export')),
- );
- if (!module_exists('field_ui')) {
- unset($ops['flags_fields']);
- }
- $permission = "flag $flag->name";
- $roles = user_roles(FALSE, $permission);
- $row = array();
- $row[] = check_plain($flag->title) . ' (' . t('Machine name: @name', array('@name' => $flag->name)) . ')';
- if (count($flags) > 1) {
- $row[] = drupal_render($form['flags'][$flag->name]['weight']);
- }
- $row[] = $flag->entity_type;
- $row[] = empty($roles) ? '' . t('No roles') . '' : implode(', ', $roles);
- $row[] = $flag->types ? implode(', ', $flag->types) : '-';
- $row[] = $flag->global ? t('Yes') : t('No');
- $row[] = theme('links', array('links' => $ops));
-
- $rows[] = array(
- 'data' => $row,
- 'class' => array('draggable'),
- );
- }
- if (!$flags) {
- $rows[] = array(
- array('data' => t('No flags are currently defined.'), 'colspan' => 7),
- );
- }
- elseif (count($flags) > 1) {
- drupal_add_tabledrag('flag-admin-listing-table', 'order', 'sibling', 'flag-weight');
- }
-
- $header = array(t('Flag'));
- if (count($flags) > 1) {
- $header[] = t('Weight');
- }
- $header = array_merge($header, array(t('Flag type'), t('Roles'), t('Entity bundles'), t('Global?'), t('Operations')));
- $output .= theme('table', array(
- 'header' => $header,
- 'rows' => $rows,
- 'attributes' => array('id' => 'flag-admin-listing-table'),
- ));
- $output .= drupal_render_children($form);
-
- return $output;
-}
-
-/**
- * Theme the list of disabled flags into a table.
- */
-function theme_flag_admin_listing_disabled($variables) {
- $flags = $variables['flags'];
- $default_flags = $variables['default_flags'];
- $output = '';
-
- // Build a list of disabled, module-based flags.
- $rows = array();
- foreach ($default_flags as $name => $flag) {
- if (!isset($flags[$name])) {
- $ops = array();
- if (!$flag->is_compatible()) {
- $flag_updates_needed = TRUE;
- $ops['flags_update'] = array('title' => '' . t('update code') . '', 'href' => $flag->admin_path('update'), 'html' => TRUE);
- }
- else {
- $ops['flags_enable'] = array('title' => t('enable'), 'href' => $flag->admin_path('edit'));
- }
- // $flag->roles['flag'] not exist on older flags.
- $roles = array_flip(array_intersect(array_flip(user_roles()), !empty($flag->roles['flag']) ? $flag->roles['flag'] : array()));
- $rows[] = array(
- $flag->name,
- $flag->module,
- $flag->entity_type ? $flag->entity_type : t('Unknown'),
- theme('links', array('links' => $ops)),
- );
- }
- }
-
- if (isset($flag_updates_needed)) {
- drupal_set_message(t('Some flags provided by modules need to be updated to a new format before they can be used with this version of Flag. See the disabled flags for a list of flags that need updating.'), 'warning');
- }
-
- if (!empty($rows)) {
- $header = array(t('Disabled Flags'), t('Module'), t('Flag type'), t('Operations'));
- $output .= theme('table', array('header' => $header, 'rows' => $rows));
- }
-
- return $output;
-}
-
-/**
- * FormAPI after_build function set states on link type options fieldsets.
- *
- * We do this in an after build so we handle further link types fieldsets from
- * other modules that provide link types.
- *
- * This expects a link type's fieldset to be $form['display'][link_options_TYPE]
- * so that can be matched up with the radio button value.
- */
-function flag_link_type_options_states($element) {
- $intro_element_values_array = array();
- foreach (element_children($element) as $key) {
- if (isset($element[$key]['#type']) && $element[$key]['#type'] == 'fieldset' && substr($key, 0, 12) == 'link_options') {
- // Trim the radio value from the fieldset key. This assumed the fieldset
- // key is 'link_options_TYPE'.
- $radio_value = substr($key, 13);
- $element[$key]['#states'] = array(
- 'visible' => array(
- ':input[name="link_type"]' => array('value' => $radio_value),
- ),
- );
- // Gather up the radio values for the format we need for a multiple
- // value state.
- $intro_element_values_array[] = array('value' => $radio_value);
- }
- }
-
- $element['link_options_intro']['#states'] = array(
- 'visible' => array(
- ':input[name="link_type"]' => $intro_element_values_array,
- ),
- );
-
- return $element;
-}
-
-/**
- * Form process handler for locking flag properties.
- *
- * Flags defined in code may define an array of properties in $flag->locked that
- * are to be locked and may not be edited by the user.
- */
-function flag_form_locked_process($element, &$form_state, $form) {
- $flag = $form['#flag'];
-
- // Disable access to a form element whose name matches a locked flag property.
- if (isset($element['#name']) && !empty($flag->locked[$element['#name']])) {
- $element['#access'] = FALSE;
- }
-
- // Recurse into the form array.
- foreach (element_children($element) as $key) {
- // Workaround for Core inconvenience: setting #process here prevents an
- // element's essential #process handlers from its hook_element_info()
- // definition from being set in form_builder().
- // @see http://drupal.org/node/1779496
- if (isset($element[$key]['#type']) && ($info = element_info($element[$key]['#type']))) {
- if (isset($info['#process'])) {
- $element[$key]['#process'] = $info['#process'];
- }
- }
-
- $element[$key]['#process'][] = 'flag_form_locked_process';
- }
-
- return $element;
-}
-
-/**
- * Output the access options for roles in a table.
- */
-function theme_flag_form_roles($variables) {
- $element = $variables['element'];
-
- $header = array(
- array('class' => array('checkbox'), 'data' => t('Flag')),
- array('class' => array('checkbox'), 'data' => t('Unflag')),
- t('Role'),
- );
- $rows = array();
- foreach (element_children($element['flag']) as $role) {
- $row = array();
- $role_name = $element['flag'][$role]['#title'];
- unset($element['flag'][$role]['#title']);
- unset($element['unflag'][$role]['#title']);
- $element['flag'][$role]['#attributes']['class'] = array('flag-access');
- $element['unflag'][$role]['#attributes']['class'] = array('unflag-access');
- $row[] = array('class' => array('checkbox'), 'data' => drupal_render($element['flag'][$role]));
- $row[] = array('class' => array('checkbox'), 'data' => drupal_render($element['unflag'][$role]));
- $row[] = $role_name;
- $rows[] = $row;
- }
-
- return theme('table', array(
- 'header' => $header,
- 'rows' => $rows,
- 'attributes' => array(
- 'class' => array('flag-admin-table'),
- 'id' => 'flag-roles',
- ),
- ));
-}
-
-/**
- * Delete flag page.
- */
-function flag_delete_confirm($form, &$form_state, $flag) {
- $form['#flag'] = $flag;
-
- return confirm_form($form,
- t('Are you sure you want to delete %title?', array('%title' => $flag->get_title())),
- !empty($_GET['destination']) ? $_GET['destination'] : FLAG_ADMIN_PATH,
- isset($flag->module) ? t('This flag is provided by the %module module. It will lose any customizations and be disabled.', array('%module' => $flag->module)) : t('This action cannot be undone.'),
- t('Delete'), t('Cancel')
- );
-}
-
-function flag_delete_confirm_submit($form, &$form_state) {
- $flag = $form['#flag'];
- if ($form_state['values']['confirm']) {
- $flag->delete();
- $flag->disable();
- _flag_clear_cache($flag->entity_type, TRUE);
- }
- drupal_set_message(t('Flag @name has been deleted.', array('@name' => $flag->get_title())));
- $form_state['redirect'] = FLAG_ADMIN_PATH;
-}
-
-/**
- * FormAPI after_build function to check that the link type exists.
- */
-function flag_check_link_types($element) {
- $link_types = flag_get_link_types();
- if (!isset($link_types[$element['#value']])) {
- drupal_set_message(t('This flag uses a link type of %type, which does not exist.', array('%type' => $element['#value'])), 'error');
- }
- return $element;
-}
-
-/**
- * Clears various caches when one or more flags are modified.
- *
- * @param $entity_types
- * The entity types for the flags. May be a single value or an array.
- * @param $is_insert_or_delete
- * Whether the modified flag is being inserted (saved for the first time) or
- * deleted. This results in a more vigorous clearing of caches. In
- * particular, when no flags exist yet, no Field admin UI paths exist and these
- * need to be created.
- */
-function _flag_clear_cache($entity_types, $is_insert_or_delete = FALSE) {
- if (!is_array($entity_types)) {
- $entity_types = array($entity_types);
- }
-
- // Reset our flags cache, thereby making the following code aware of the
- // modifications.
- drupal_static_reset('flag_get_flags');
-
- if ($is_insert_or_delete) {
- // A new or deleted flag means we are changing bundles on the Flagging
- // entity, and thus need to clear the entity info cache.
- entity_info_cache_clear();
- }
-
- // Clear FieldAPI's field_extra cache, so our changes to pseudofields are
- // noticed. It's rather too much effort to both a) check whether the
- // pseudofield setting has changed either way, and b) specifically clear just
- // the bundles that are (or were!!) affected, so we just clear for all bundles
- // on our entity type regardlesss.
- foreach ($entity_types as $entity_type) {
- cache_clear_all("field_info:bundle_extra:$entity_type:", 'cache_field', TRUE);
- }
-
- if (module_exists('views')) {
- views_invalidate_cache();
- }
-
- // The title of a flag may appear in the menu (indirectly, via our "default
- // views"), so we need to clear the menu cache. This call also clears the
- // page cache, which is desirable too because the flag labels may have
- // changed.
- menu_rebuild();
-}
diff --git a/includes/flag.cookie_storage.inc b/includes/flag.cookie_storage.inc
deleted file mode 100644
index 856f582..0000000
--- a/includes/flag.cookie_storage.inc
+++ /dev/null
@@ -1,170 +0,0 @@
-flag(145);
- * $storage->unflag(17);
- * @endcode
- *
- * You may delete all the cookies with FlagCookieStorage::drop().
- */
-abstract class FlagCookieStorage {
-
- /**
- * Returns the actual storage object compatible with the flag.
- */
- static function factory($flag) {
- if ($flag->global) {
- return new FlagGlobalCookieStorage($flag);
- }
- else {
- return new FlagNonGlobalCookieStorage($flag);
- }
- }
-
- function __construct($flag) {
- $this->flag = $flag;
- }
-
- /**
- * "Flags" an item.
- *
- * It just records this fact in a cookie.
- */
- abstract function flag($entity_id);
-
- /**
- * "Unflags" an item.
- *
- * It just records this fact in a cookie.
- */
- abstract function unflag($entity_id);
-
- /**
- * Deletes all the cookies.
- *
- * (Etymology: "drop" as in "drop database".)
- */
- static function drop() {
- FlagGlobalCookieStorage::drop();
- FlagNonGlobalCookieStorage::drop();
- }
-}
-
-/**
- * Storage handler for global flags.
- */
-class FlagGlobalCookieStorage extends FlagCookieStorage {
-
- function flag($entity_id) {
- $cookie_key = $this->cookie_key($entity_id);
- setcookie($cookie_key, 1, REQUEST_TIME + $this->get_lifetime(), base_path());
- $_COOKIE[$cookie_key] = 1;
- }
-
- function unflag($entity_id) {
- $cookie_key = $this->cookie_key($entity_id);
- setcookie($cookie_key, 0, REQUEST_TIME + $this->get_lifetime(), base_path());
- $_COOKIE[$cookie_key] = 0;
- }
-
- // Global flags persist for the length of the minimum cache lifetime.
- protected function get_lifetime() {
- $cookie_lifetime = variable_get('cache', 0) ? variable_get('cache_lifetime', 0) : -1;
- // Do not let the cookie lifetime be 0 (which is the no cache limit on
- // anonymous page caching), since it would expire immediately. Usually
- // the no cache limit means caches are cleared on cron, which usually runs
- // at least once an hour.
- if ($cookie_lifetime == 0) {
- $cookie_lifetime = 3600;
- }
- return $cookie_lifetime;
- }
-
- protected function cookie_key($entity_id) {
- return 'flag_global_' . $this->flag->name . '_' . $entity_id;
- }
-
- /**
- * Deletes all the global cookies.
- */
- static function drop() {
- foreach ($_COOKIE as $key => $value) {
- if (strpos($key, 'flag_global_') === 0) {
- setcookie($key, FALSE, 0, base_path());
- unset($_COOKIE[$key]);
- }
- }
- }
-}
-
-/**
- * Storage handler for non-global flags.
- */
-class FlagNonGlobalCookieStorage extends FlagCookieStorage {
-
- // The anonymous per-user flaggings are stored in a single cookie, so that
- // all of them persist as long as the Drupal cookie lifetime.
-
- function __construct($flag) {
- parent::__construct($flag);
- $this->flaggings = isset($_COOKIE['flags']) ? explode(' ', $_COOKIE['flags']) : array();
- }
-
- function flag($entity_id) {
- if (!$this->is_flagged($entity_id)) {
- $this->flaggings[] = $this->cookie_key($entity_id);
- $this->write();
- }
- }
-
- function unflag($entity_id) {
- if (($index = $this->index_of($entity_id)) !== FALSE) {
- unset($this->flaggings[$index]);
- $this->write();
- }
- }
-
- protected function get_lifetime() {
- return min((int) ini_get('session.cookie_lifetime'), (int) ini_get('session.gc_maxlifetime'));
- }
-
- protected function cookie_key($entity_id) {
- return $this->flag->name . '_' . $entity_id;
- }
-
- protected function write() {
- $serialized = implode(' ', array_filter($this->flaggings));
- setcookie('flags', $serialized, REQUEST_TIME + $this->get_lifetime(), base_path());
- $_COOKIE['flags'] = $serialized;
- }
-
- protected function is_flagged($entity_id) {
- return $this->index_of($entity_id) !== FALSE;
- }
-
- protected function index_of($entity_id) {
- return array_search($this->cookie_key($entity_id), $this->flaggings);
- }
-
- /**
- * Deletes the cookie.
- */
- static function drop() {
- if (isset($_COOKIE['flags'])) {
- setcookie('flags', FALSE, 0, base_path());
- unset($_COOKIE['flags']);
- }
- }
-}
diff --git a/includes/flag.entity.inc b/includes/flag.entity.inc
deleted file mode 100644
index 55dba6a..0000000
--- a/includes/flag.entity.inc
+++ /dev/null
@@ -1,24 +0,0 @@
-flaggings fieldable, not the flags.
- * (In the same way that Drupal makes nodes fieldable, not node
- * types).
- */
-
-/**
- * Controller class for flaggings.
- */
-class FlaggingController extends DrupalDefaultEntityController {
-
- protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
- $query = parent::buildQuery($ids, $conditions, $revision_id);
- // Add the flag name, which determines the bundle.
- $query->innerJoin('flag', 'flag', 'base.fid = flag.fid');
- $query->addField('flag', 'name', 'flag_name');
- return $query;
- }
-}
diff --git a/includes/flag.export.inc b/includes/flag.export.inc
deleted file mode 100644
index 9285722..0000000
--- a/includes/flag.export.inc
+++ /dev/null
@@ -1,138 +0,0 @@
-is_compatible()) {
- drupal_set_message(t('Could not export flag %flag-name: Your flag was created by a different version of the Flag module than is now being used.', array('%flag-name' => $flag->name)), 'error');
- continue;
- }
-
- $flag->api_version = FLAG_API_VERSION;
- $new_flag = (array) $flag;
-
- if (!empty($module)) {
- // Even though Flag adds the module name itself later, we add the module
- // name here for reference by other modules (such as Features).
- $new_flag['module'] = $module;
- // Lock the flag name, as is normally desired by modules using
- // hook_flag_default_flags(), and needed by Features.
- $new_flag['locked'] = array('name');
- }
- // Allow other modules to change the exported flag.
- drupal_alter('flag_export', $new_flag);
-
- // Remove properties we don't export.
- $unset_properties = array(
- // Remove the flag ID.
- 'fid',
- // The name is emitted as the key for the array.
- 'name',
- // The entity info is just used as helper data.
- 'entity_info',
- // Remove roles.
- 'roles',
- // Remove errors.
- 'errors',
- );
- foreach ($unset_properties as $property) {
- unset($new_flag[$property]);
- }
-
- $output .= $indent . '// Exported flag: "' . check_plain($flag->get_title()) . '"' . ".\n";
- $output .= $indent . '$flags[\'' . $flag->name . '\'] = ' . (function_exists('features_var_export') ? features_var_export($new_flag, $indent) : var_export($new_flag, TRUE)) . ";\n";
- }
- $output .= $indent . 'return $flags;' . "\n";
- return $output;
-}
-
-/**
- * Page for displaying an upgrade message and export form for Flag 1.x flags.
- */
-function flag_update_page($flag) {
- if ($flag->is_compatible()) {
- drupal_set_message(t('The flag %name is already up-to-date with the latest Flag API and does not need upgrading.', array('%name' => $flag->name)));
- drupal_goto(FLAG_ADMIN_PATH);
- }
-
- drupal_set_message(t('The flag %name is currently using the Flag API version @version, which is not compatible with the current version of Flag. You can upgrade this flag by pasting the below code into @module_flag_default_flags() function in the @module.module file.', array('%name' => $flag->name, '@version' => $flag->api_version, '@module' => $flag->module)), 'warning');
-
- flag_update_export($flag);
-
- return drupal_get_form('flag_export_form', $flag);
-}
-
-/**
- * Update a flag before export.
- *
- * @param $flag
- * The flag object passed by reference.
- */
-function flag_update_export(&$flag) {
- // Set the API version to 1 by default: version 1 did not explicitly define
- // the API version.
- if (empty($flag->api_version)) {
- $flag->api_version = 1;
- }
-
- // Get all our update classes.
- // This is not terribly graceful, but the alternative is declaring our classes
- // explicitly, or registering them with the Drupal autoloader and then running
- // a database query, which seems a waste of space given we only ever need
- // these here.
- $classes = get_declared_classes();
- $update_handlers = array();
- foreach ($classes as $class) {
- // Any class whose name is of the form 'FlagUpdate_foo' is one of ours, we
- // assume. Should this prove problematic, we can add use of reflection here.
- if (substr($class, 0, 11) == 'FlagUpdate_') {
- // @todo: change this to work with the static class when we drop support
- // for PHP 5.2: see commit d5b517.
- $update_handler = new $class;
- // Cast to string, as decimals as array keys seem to be rounded down to
- // ints, WTF PHP?
- $version = (string) $update_handler->old_api_version;
-
- $update_handlers[$version] = $update_handler;
- }
- }
- // Sort the classes by old version number.
- uksort($update_handlers, 'version_compare');
-
- // Work through each update handler.
- foreach ($update_handlers as $old_api_version => $update_handler) {
- // Skip update classes that are older than our current flag.
- if (version_compare($old_api_version, $flag->api_version, '<')) {
- continue;
- }
-
- // Run the update and change the API version on the flag.
- $update_handler->update($flag);
- $flag->api_version = $update_handler->new_api_version;
- }
-}
diff --git a/includes/flag.features.inc b/includes/flag.features.inc
deleted file mode 100644
index 9374930..0000000
--- a/includes/flag.features.inc
+++ /dev/null
@@ -1,124 +0,0 @@
- $flag) {
- $module = '';
- if ($flag = flag_load($flag, TRUE)) {
- // Try to get the module that provides the entity this flag is on.
- // First pass: check whether there's a module that implements
- // hook_flag_type_info() for this entity.
- if (array_key_exists($flag->entity_type, $modules)) {
- $module = $modules[$flag->entity_type];
- }
- else {
- // Second pass: check whether this entity is defined using Entity API
- // and therefore has an extra 'module' property in its information.
- if ($entity_info = entity_get_info($flag->entity_type)) {
- if (isset($entity_info['module'])) {
- $module = $entity_info['module'];
- }
- }
- }
-
- if (!empty($module)) {
- $export['dependencies'][$module] = $module;
- }
-
- $export['features']['flag'][$flag->name] = $flag->name;
- }
- }
-
- return $pipe;
-}
-
-/**
- * Implements hook_features_export_options().
- */
-function flag_features_export_options() {
- $options = array();
- // Get all flags, including disabled defaults.
- $flags = flag_get_flags() + flag_get_default_flags(TRUE);
- foreach ($flags as $name => $flag) {
- $options[$name] = drupal_ucfirst(check_plain($flag->entity_type)) . ': ' . check_plain($flag->title);
- }
- return $options;
-}
-
-/**
- * Implements hook_features_export_render().
- */
-function flag_features_export_render($module, $data) {
- module_load_include('inc', 'flag', '/includes/flag.export');
- $code = flag_export_flags($data, $module, ' ');
- return array('flag_default_flags' => $code);
-}
-
-/**
- * Implements hook_features_revert().
- *
- * @param $module
- * The name of module for which to revert content.
- */
-function flag_features_revert($module = NULL) {
- // Get default flags from features.
- if (module_hook($module, 'flag_default_flags')) {
- module_load_include('inc', 'flag', '/includes/flag.admin');
- $default_flags = module_invoke($module, 'flag_default_flags');
-
- // Build up values for the cache clear.
- $entity_types = array();
-
- // Revert flags that are defined in code.
- foreach ($default_flags as $flag_name => $flag_info) {
- if (is_numeric($flag_name)) {
- // Backward compatibility.
- $flag_name = $flag_info['name'];
- }
- $flag = flag_load($flag_name, TRUE);
- if ($flag && $flag->revert() === FALSE) {
- drupal_set_message(t('Could not revert flag %flag-name to the state described in your code: Your flag was created by a different version of the Flag module than is now being used.', array('%flag-name' => $flag->name)), 'error');
- }
-
- $entity_types[] = $flag->entity_type;
- }
- _flag_clear_cache($entity_types);
- }
-}
-
-/**
- * Helper function; Retrieve the providing modules defining the flags.
- */
-function flag_features_providing_module() {
- $modules = array();
- $hook = 'flag_type_info';
- foreach (module_implements($hook) as $module) {
- foreach (module_invoke($module, $hook) as $key => $value) {
- $modules[$key] = isset($value['module']) ? $value['module'] : $module;
- }
- }
-
- // Any entity type without a flag providing module will be provided by the
- // flag module.
- foreach (entity_get_info() as $entity_type => $entity) {
- if (!isset($modules[$entity_type]) && empty($entity['configuration']) && $entity_type !== 'taxonomy_vocabulary') {
- $modules[$entity_type] = 'flag';
- }
- }
-
- return $modules;
-}
diff --git a/includes/flag.pages.inc b/includes/flag.pages.inc
deleted file mode 100644
index cfb91ba..0000000
--- a/includes/flag.pages.inc
+++ /dev/null
@@ -1,165 +0,0 @@
-errors['token'] = t('Bad token. You seem to have followed an invalid link.');
- }
- elseif ($user->uid == 0 && !$has_js) {
- $flag->errors['javascript'] = t('You must have JavaScript and cookies enabled in your browser to flag content.');
- }
-
- // If no errors have been detected thus far, perform the flagging.
- // Further errors may still be detected during validation and prevent
- // the operation from succeeding.
- if (!$flag->errors) {
- $flag->flag($action, $entity_id);
- }
-
- // If successful, return data according to the request type.
- if ($js) {
- drupal_add_http_header('Content-Type', 'text/javascript; charset=utf-8');
- $flag->link_type = 'toggle';
- // Any errors that have been set will be output below
- // the flag link with javascript.
- print drupal_json_encode(flag_build_javascript_info($flag, $entity_id));
- drupal_exit();
- }
- else {
- $errors = $flag->get_errors();
- if ($errors) {
- // If an error was received, set a message and exit.
- foreach ($errors as $error) {
- drupal_set_message($error, 'error');
- }
- if (isset($errors['access-denied'])) {
- return MENU_ACCESS_DENIED;
- }
- else {
- drupal_goto();
- }
- }
- else {
- drupal_set_message($flag->get_label($action . '_message', $entity_id));
- drupal_goto();
- }
- }
-}
-
-/**
- * Form for confirming the (un)flagging of an entity.
- *
- * @param $action
- * Either 'flag' or 'unflag'.
- * @param $flag
- * A loaded flag object.
- * @param $entity_id
- * The id of the entity to operate on. The type is implicit in the flag.
- *
- * @see flag_confirm_submit()
- */
-function flag_confirm($form, &$form_state, $action, $flag, $entity_id) {
- $form['#flag'] = $flag;
- $form['action'] = array(
- '#type' => 'value',
- '#value' => $action,
- );
- $form['entity_id'] = array(
- '#type' => 'value',
- '#value' => $entity_id,
- );
-
- $question = $flag->get_label($action . '_confirmation', $entity_id);
- $path = isset($_GET['destination']) ? $_GET['destination'] : '';
- $yes = $flag->get_label($action . '_short', $entity_id);
-
- if ($action == 'flag') {
- // If the action 'flag', we're potentially about to create a new
- // flagging entity. We need an empty new entity to pass to FieldAPI.
- $flagging = $flag->new_flagging($entity_id);
- field_attach_form('flagging', $flagging, $form, $form_state);
- $form['#flagging'] = $flagging;
- }
-
- return confirm_form($form, $question, $path, '', $yes);
-}
-
-/**
- * Submit handler for the flag confirm form.
- *
- * Note that validating whether the user may perform the action is done here,
- * rather than in a form validation handler.
- *
- * @see flag_confirm()
- */
-function flag_confirm_submit(&$form, &$form_state) {
- $flag = $form['#flag'];
- $action = $form_state['values']['action'];
- $entity_id = $form_state['values']['entity_id'];
-
- if ($action == 'flag') {
- // If the action 'flag', further build up the new entity from form values.
- $flagging = $form['#flagging'];
- entity_form_submit_build_entity('flagging', $flagging, $form, $form_state);
-
- $result = $flag->flag($action, $entity_id, NULL, FALSE, $flagging);
- }
- else {
- $result = $flag->flag($action, $entity_id, NULL, FALSE);
- }
-
- if (!$result) {
- if ($errors = $flag->get_errors()) {
- foreach ($errors as $error) {
- drupal_set_message($error, 'error');
- }
- }
- }
- else {
- drupal_set_message($flag->get_label($action . '_message', $entity_id));
- }
-}
-
-/**
- * Builds the JavaScript structure describing the flagging operation.
- */
-function flag_build_javascript_info($flag, $entity_id) {
- $errors = $flag->get_errors();
- $info = array(
- 'status' => TRUE,
- 'newLink' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, array(
- 'after_flagging' => TRUE,
- 'errors' => $errors,
- )),
- // Further information for the benefit of custom JavaScript event handlers:
- 'flagSuccess' => !$errors,
- 'contentId' => $entity_id,
- 'entityType' => $flag->entity_type,
- 'flagName' => $flag->name,
- 'flagStatus' => $flag->is_flagged($entity_id) ? 'flagged' : 'unflagged',
- );
- drupal_alter('flag_javascript_info', $info);
- return $info;
-}
diff --git a/includes/views/flag.views.inc b/includes/views/flag.views.inc
deleted file mode 100644
index 4d3c216..0000000
--- a/includes/views/flag.views.inc
+++ /dev/null
@@ -1,272 +0,0 @@
- array(
- 'flag_flaggable_node' => array(
- 'title' => t('Flaggable node'),
- 'flag type' => 'node',
- 'handler' => 'flag_plugin_argument_validate_flaggability',
- 'path' => drupal_get_path('module', 'flag') . '/includes',
- ),
- 'flag_flaggable_user' => array(
- 'title' => t('Flaggable user'),
- 'flag type' => 'user',
- 'handler' => 'flag_plugin_argument_validate_flaggability',
- 'path' => drupal_get_path('module', 'flag') . '/includes',
- ),
- // A comment validator won't be very useful. Moreover, having it will
- // contribute to the argument object's $options polution, so let's skip
- // it.
- ),
- );
-}
-/**
- * Implements hook_views_data().
- */
-function flag_views_data() {
- $data = array();
-
- $data['flagging']['table']['group'] = t('Flags');
- $data['flag_counts']['table']['group'] = t('Flags');
-
- // Notify views from flag 2.x of our changes to views data.
- // @see flag_update_7301().
- $data['flag_content']['moved to'] = 'flagging';
- // @see flag_update_7303().
- $data['flag_content']['content_id']['moved to'] = array('flagging', 'entity_id');
-
- $data['flagging']['uid'] = array(
- 'title' => t('User uid'),
- 'help' => t('The user that flagged an item. If you need more fields than the uid add the "Flags: User" relationship.'),
- 'relationship' => array(
- 'base' => 'users',
- 'title' => t('User'),
- 'help' => t('Relate an item to the user that flagged it.'),
- 'handler' => 'views_handler_relationship',
- 'label' => t('Flag user'),
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_user_name',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_numeric',
- ),
- 'field' => array(
- 'handler' => 'views_handler_field_user',
- ),
- );
-
- $data['flagging']['timestamp'] = array(
- 'title' => t('Flagged time'),
- 'help' => t('Display the time the content was flagged by a user.'),
- 'field' => array(
- 'handler' => 'views_handler_field_date',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort_date',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_date',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_date',
- ),
- );
-
- // Argument for content ID, used for "Who's flagged this" views.
- $data['flagging']['entity_id'] = array(
- 'title' => t('Content ID'),
- 'help' => t('The unique ID of the object that has been flagged.'),
- 'argument' => array(
- 'handler' => 'flag_handler_argument_entity_id',
- ),
- );
-
- // Specialized is null/is not null filter.
- $data['flagging']['flagged'] = array(
- 'title' => t('Flagged'),
- 'real field' => 'uid',
- 'field' => array(
- 'handler' => 'flag_handler_field_flagged',
- 'label' => t('Flagged'),
- 'help' => t('A boolean field to show whether the flag is set or not.'),
- ),
- 'filter' => array(
- 'handler' => 'flag_handler_filter_flagged',
- 'label' => t('Flagged'),
- 'help' => t('Filter to ensure content has or has not been flagged.'),
- ),
- 'sort' => array(
- 'handler' => 'flag_handler_sort_flagged',
- 'label' => t('Flagged'),
- 'help' => t('Sort by whether entities have or have not been flagged.'),
- ),
- );
-
- // Flag content links.
- $data['flagging']['ops'] = array(
- 'title' => t('Flag link'),
- 'help' => t('Display flag/unflag link.'),
- 'field' => array(
- 'handler' => 'flag_handler_field_ops',
- ),
- );
-
- $data['flag_counts']['count'] = array(
- 'title' => t('Flag counter'),
- 'help' => t('The number of times a piece of content is flagged by any user.'),
- 'field' => array(
- 'handler' => 'views_handler_field_numeric',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_numeric',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_numeric',
- ),
- );
-
- $data['flag_counts']['last_updated'] = array(
- 'title' => t('Time last flagged'),
- 'help' => t('The time a piece of content was most recently flagged by any user.'),
- 'field' => array(
- 'handler' => 'views_handler_field_date',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort_date',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_date',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_date',
- ),
- );
-
- return $data;
-}
-
-/**
- * Implements hook_views_data_alter().
- */
-function flag_views_data_alter(&$data) {
-
- foreach (array_keys(flag_fetch_definition()) as $flag_type) {
- $flag = flag_flag::factory_by_entity_type($flag_type);
- $info = $flag->get_views_info();
-
- if (!isset($info)) {
- continue;
- }
-
- if (!empty($info['join field'])) {
- // Add the flag relationship.
- $data[$info['views table']]['flag_content_rel'] = array(
- 'group' => t('Flags'),
- 'title' => $info['title'],
- 'help' => $info['help'],
- 'relationship' => array(
- 'flag type' => $flag_type,
- 'handler' => 'flag_handler_relationship_content',
- 'label' => t('flag'),
- 'base' => 'flagging',
- 'base field' => 'entity_id',
- 'relationship field' => $info['join field'],
- ),
- );
-
- // Add the flag counter relationship.
- $data[$info['views table']]['flag_count_rel'] = array(
- 'group' => t('Flags'),
- 'title' => $info['counter title'],
- 'help' => $info['counter help'],
- 'relationship' => array(
- 'flag type' => $flag_type,
- 'handler' => 'flag_handler_relationship_counts',
- 'label' => t('counter'),
- 'base' => 'flag_counts',
- 'base field' => 'entity_id',
- 'relationship field' => $info['join field'],
- ),
- );
- }
- }
-
- // Add a relationship for the user that flagged any type of content.
- $data['users']['flag_user_content_rel'] = array(
- 'group' => t('Flags'),
- 'title' => t("User's flaggings"),
- 'help' => t('Relate users to the flaggings they have made on objects, using a particular flag.'),
- 'relationship' => array(
- 'base' => 'flagging',
- 'base field' => 'uid',
- 'relationship field' => 'uid',
- 'handler' => 'flag_handler_relationship_user_content',
- 'label' => t('user flagged content'),
- ),
- );
-}
-
-/**
- * Implements hook_views_query_substitutions().
- *
- * Allow replacement of current user's session id so we can cache these queries.
- */
-function flag_views_query_substitutions() {
- return array(
- '***FLAG_CURRENT_USER_SID***' => flag_get_sid(),
- );
-}
-/**
- * A helper function that creates a radio list of available flags.
- *
- * This function is used to select the desired flag when setting up flag
- * relationships and fields.
- */
-function flag_views_flag_config_form($form_type, $entity_type, $current_flag) {
- $flags = flag_get_flags($entity_type);
-
- $options = array();
- foreach ($flags as $flag) {
- $options[$flag->name] = $flag->get_title();
- }
-
- $form = array(
- '#type' => $form_type,
- '#title' => t('Flag'),
- '#options' => $options,
- '#default_value' => $current_flag,
- '#required' => TRUE,
- );
-
- return $form;
-}
-
-/**
- * Helper function that gets the first defined flag and returns its name.
- */
-function flag_views_flag_default($entity_type) {
- $default_flag = &drupal_static(__FUNCTION__, array());
-
- if (!array_key_exists($entity_type, $default_flag)) {
- $flag = array_shift(flag_get_flags($entity_type));
- $default_flag[$entity_type] = $flag ? $flag->name : NULL;
- }
-
- return $default_flag[$entity_type];
-}
diff --git a/includes/views/flag.views_convert.inc b/includes/views/flag.views_convert.inc
deleted file mode 100644
index ed8910d..0000000
--- a/includes/views/flag.views_convert.inc
+++ /dev/null
@@ -1,235 +0,0 @@
-add_item() won't produce
- * the right results, usually needed to set field options or values.
- */
-function flag_views_convert($display, $type, &$view, $field, $id) {
- static $flag_name;
-
- // First, replace any sign of views_bookmark with flag's Views 1 equivelant.
- $key_search = array(
- '^views_bookmark_ops_([0-9]+)' => 'flag_ops_',
- '^views_bookmark_nodes_([0-9]+)' => 'flag_content_',
- '^views_bookmark_users_([0-9]+)' => 'flag_users_',
- '^views_bookmark_node_count_([0-9]+)' => 'flag_counts_',
- );
- foreach ($field as $property => $value) {
- foreach ($key_search as $search => $replace) {
- if (!empty($value) && is_string($value) && preg_match('/' . $search . '/', $value, $matches)) {
- $flag = flag_get_flag(NULL, $matches[1]);
- $replace = $replace . $flag->name;
- $field[$property] = preg_replace('/' . $search . '/', $replace, $value);
- }
- }
- }
-
- // Create a table/field identifier for this field.
- foreach (array('flag_ops_', 'flag_content_', 'flag_users_', 'flag_counts_') as $table) {
- if (strpos($field['tablename'], $table) === 0) {
- $name = str_replace($table, '', $field['tablename']);
- if (!empty($name) && !isset($flag_name)) {
- $flag_name = $name;
- }
- }
- }
-
- // Now update values, options, etc. to those selected in the imported view.
- switch ($type) {
- case 'field':
- switch ($id) {
- case 'ops':
- $new_field = array(
- 'label' => $field['label'],
- 'id' => 'ops',
- 'table' => 'flagging',
- 'field' => 'ops',
- 'relationship' => 'flag_content_rel',
- );
- $new_rel = 'flag_content_rel';
- $flag_content_rel_user = 'current';
- break;
- case 'count':
- $new_field = array(
- 'label' => $field['label'],
- 'id' => 'count',
- 'table' => 'flag_counts',
- 'field' => 'count',
- 'relationship' => 'flag_counts_rel',
- );
- $new_rel = 'flag_counts_rel';
- break;
- case 'name':
- $new_field = array(
- 'label' => $field['label'],
- 'link_to_user' => 1,
- 'id' => 'name',
- 'table' => 'users',
- 'field' => 'name',
- 'relationship' => 'uid',
- );
- $new_rel = 'uid';
- break;
- }
- break;
-
- case 'filter':
- case 'exposed_filter':
- switch ($id) {
- case 'uid':
- // The flagging uid filter means "Include content only flagged by
- // the current user". In D6, this is no longer a filter, but instead
- // part of the relationship. Make the relationship join on the uid.
- if ($field['value'] == '***CURRENT_USER***') {
- $new_rel = 'flag_content_rel';
- $flag_content_rel_user = 'current';
- }
- // Remove the old filter.
- $view->set_item('default', $type, $id, NULL);
- break;
- case 'timestamp':
- $new_field = array(
- 'operator' => $field['operator'],
- 'value' => flag_views_convert_timestamp_value($field['value']),
- 'group' => 0,
- 'id' => 'timestamp',
- 'table' => 'flagging',
- 'field' => 'timestamp',
- 'relationship' => 'flag_content_rel',
- 'exposed' => $type == 'exposed_filter' ? 1 : 0,
- );
- $new_rel = 'flag_content_rel';
- drupal_set_message(t('Flag is not able to convert the Flagged time filter. It\'s value is currently empty, but needs to be populated to work properly.'), 'warning');
- break;
- case 'count':
- $new_field = array(
- 'operator' => $field['operator'],
- 'value' => array('value' => $field['value']),
- 'group' => 0,
- 'id' => 'count',
- 'table' => 'flag_counts',
- 'field' => 'count',
- 'relationship' => 'flag_counts_rel',
- 'exposed' => $type == 'exposed_filter' ? 1 : 0,
- );
- $new_rel = 'flag_counts_rel';
- break;
- }
- break;
-
- case 'argument':
- // Flag in Drupal 5 only provides one argument, and in Views 1 arguments
- // weren't given and ID, so we use the field type.
- if (strpos($field['type'], 'flag_content_') === 0) {
- $new_field = array(
- 'id' => 'uid',
- 'table' => 'users',
- 'field' => 'uid',
- 'relationship' => 'uid',
- );
- $new_rel = 'uid';
- }
- break;
-
- case 'sort':
- switch ($id) {
- case 'count':
- $new_field = array(
- 'order' => $field['sortorder'],
- 'id' => 'count',
- 'table' => 'flag_counts',
- 'field' => 'count',
- 'relationship' => 'flag_counts_rel',
- );
- $new_rel = 'flag_counts_rel';
- break;
- case 'timestamp':
- $new_field = array(
- 'order' => $field['sortorder'],
- 'id' => 'timestamp',
- 'table' => 'flagging',
- 'field' => 'timestamp',
- 'relationship' => 'flag_content_rel',
- );
- $new_rel = 'flag_content_rel';
- break;
- }
- break;
- }
-
- // Add any new fields.
- if (isset($new_field)) {
- // Exposed filters are now wrapped into filters.
- $type = $type == 'exposed_filter' ? 'filter' : $type;
- // Update the type in the view options.
- $view->set_item('default', $type, $id, $new_field);
- }
-
- // Add any new relationships (but only once per view).
- if (isset($new_rel) && !isset($view->display[$display]->display_options['relationships'][$new_rel])) {
- if ($new_rel == 'flag_content_rel') {
- $view->display[$display]->display_options['relationships'][$new_rel] = array(
- 'label' => $flag_name,
- 'required' => 1,
- 'flag' => $flag_name,
- 'user_scope' => 'any',
- 'id' => 'flag_content_rel',
- 'table' => 'node',
- 'field' => 'flag_content_rel',
- 'relationship' => 'none',
- );
- }
- elseif ($new_rel == 'flag_counts_rel') {
- $view->display[$display]->display_options['relationships'][$new_rel] = array(
- 'label' => $flag_name . ' counts',
- 'required' => 0,
- 'flag' => $flag_name,
- 'id' => 'flag_counts_rel',
- 'table' => 'node',
- 'field' => 'flag_counts_rel',
- 'relationship' => 'none',
- );
- }
- elseif ($new_rel == 'uid') {
- $view->display[$display]->display_options['relationships'][$new_rel] = array(
- 'label' => isset($flag_name) ? $flag_name . ' user' : 'user',
- 'required' => 0,
- 'id' => 'uid',
- 'table' => 'flagging',
- 'field' => 'uid',
- 'relationship' => 'flag_content_rel',
- );
- }
- }
-
- // Modify relationships if needed.
- if (isset($flag_content_rel_user) && isset($view->display[$display]->display_options['relationships']['flag_content_rel'])) {
- $view->display[$display]->display_options['relationships']['flag_content_rel']['user_scope'] = 'current';
- }
-}
-
-/**
- * In Views 1, dates were simply stored as a single string. In Views 2, the
- * value is stored as an array of options.
- */
-function flag_views_convert_timestamp_value($value) {
- $type = 'date';
- if (stripos($value, 'now') !== FALSE) {
- $type = 'offset';
- $value = trim(str_ireplace('now', '', $value));
- }
- return array(
- 'type' => $type,
- 'value' => $value,
- 'min' => '',
- 'max' => '',
- );
-}
diff --git a/includes/views/flag_handler_argument_entity_id.inc b/includes/views/flag_handler_argument_entity_id.inc
deleted file mode 100644
index f5d3b1a..0000000
--- a/includes/views/flag_handler_argument_entity_id.inc
+++ /dev/null
@@ -1,46 +0,0 @@
-view->relationship[$this->options['relationship']]->get_flag();
- }
-
- /**
- * Override the behavior of title(). Get the title of the appropriate objects.
- */
- function title_query() {
- if (!($flag = $this->get_flag())) {
- return array(); // Error message is printed by get_flag().
- }
- $views_info = $flag->get_views_info();
-
- $titles = array();
- $placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
-
- $result = db_select($views_info['views table'], 'o')
- ->fields('o', array($views_info['title field']))
- ->condition('o.' . $views_info['join field'], $this->value, 'IN')
- ->execute();
- foreach ($result as $title) {
- $titles[] = check_plain($title->$views_info['title field']);
- }
- return $titles;
- }
-}
diff --git a/includes/views/flag_handler_field_flagged.inc b/includes/views/flag_handler_field_flagged.inc
deleted file mode 100644
index 660f91d..0000000
--- a/includes/views/flag_handler_field_flagged.inc
+++ /dev/null
@@ -1,36 +0,0 @@
-formats['flag'] = array(t('Flagged'), t('Not flagged'));
- // TODO: We could probably lift the '(Un)Flagged message' strings from the
- // flag object, but a) we need to lift that from the relationship we're on
- // and b) they will not necessarily make sense in a static context.
- }
-
- /**
- * Called to add the field to a query.
- */
- function query() {
- $this->ensure_my_table();
- // Add the formula.
- $this->field_alias = $this->query->add_field(NULL, "($this->table_alias.uid IS NOT NULL)", 'flagging_flagged');
-
- $this->add_additional_fields();
- }
-
-}
diff --git a/includes/views/flag_handler_field_ops.inc b/includes/views/flag_handler_field_ops.inc
deleted file mode 100644
index 58830f1..0000000
--- a/includes/views/flag_handler_field_ops.inc
+++ /dev/null
@@ -1,163 +0,0 @@
-view->relationship[$this->options['relationship']])) {
- return $this->view->relationship[$this->options['relationship']]->get_flag();
- }
- }
-
- /**
- * Return the the relationship we're linked to. That is, the alias for its
- * table (which is suitbale for use with the various methods of the 'query'
- * object).
- */
- function get_parent_relationship() {
- $parent = $this->view->relationship[$this->options['relationship']]->options['relationship'];
- if (!$parent || $parent == 'none') {
- return NULL; // Base query table.
- }
- else {
- return $this->view->relationship[$parent]->alias;
- }
- }
-
- function option_definition() {
- $options = parent::option_definition();
- $options['link_type'] = array('default' => '');
- return $options;
- }
-
- function options_form(&$form, &$form_state) {
- parent::options_form($form, $form_state);
-
- $form['link_type'] = array(
- '#type' => 'radios',
- '#title' => t('Link type'),
- '#options' => array('' => t('Use flag link settings')) + _flag_link_type_options(),
- '#default_value' => $this->options['link_type'],
- );
- }
-
- /**
- * Override base ::query(). The purpose here is to make it possible for the
- * render() method to know two things: what's the content ID, and whether
- * it's flagged.
- */
- function query() {
- if (!($flag = $this->get_flag())) {
- return; // Error message is printed in render().
- }
- $info = $flag->get_views_info();
- $parent = $this->get_parent_relationship();
-
- // Find out if the content is flagged. We can't just peek at some field in
- // our loaded table because it doesn't always reflect the user browsing the
- // page. So we explicitly add the flagging table to find this out.
- // If the relationship is created with 'Current User' checked, we probably
- // already have the appropriate join. We just need the appropriate table
- // alias for that join. We look in the relationship settings to see if
- // user_scope is set to 'current' to determine this.
- $relationship = $this->view->relationship[$this->options['relationship']];
- if (isset($relationship->options['user_scope']) && $relationship->options['user_scope'] == 'current') {
- $table_alias = $relationship->alias;
- }
- // Otherwise, let's set up the alias, keeping it unique for this flag in
- // case there are multiple flag relationships in a single view.
- else {
- $table_alias = 'flagging_current_user_' . $flag->fid;
- }
- // Now that we have the table alias, let's see if it's already been joined
- // to. If it hasn't, we'll set up a join.
- if (!isset($this->query->table_queue[$table_alias])) {
- $join = new views_join();
- $join->construct('flagging', $info['views table'], $info['join field'], 'entity_id');
- $join->extra[] = array(
- 'field' => 'fid',
- 'value' => $flag->fid,
- 'numeric' => TRUE,
- );
- if (!$flag->global) {
- $join->extra[] = array(
- 'field' => 'uid',
- 'value' => '***CURRENT_USER***',
- 'numeric' => TRUE,
- );
- $join->extra[] = array(
- 'field' => 'sid',
- 'value' => '***FLAG_CURRENT_USER_SID***',
- 'numeric' => TRUE,
- );
- }
- $table_alias = $this->query->add_table($table_alias, $parent, $join);
- }
- $this->aliases['is_flagged'] = $this->query->add_field($table_alias, 'entity_id');
-
- // Next, find out the content ID. We can't add_field() on this table
- // (flagging), because its entity_id may be NULL (in case no user has
- // flagged this content, and it's a LEFT JOIN). So we reach to the parent
- // relationship and add_field() *its* content ID column.
- $left_table = $this->view->relationship[$this->options['relationship']]->table_alias;
- $this->aliases['entity_id'] = $this->query->add_field($left_table, $info['join field']);
- }
-
- /**
- * Find out if the flag applies to each item seen on the page. It's done in a
- * separate DB query to to avoid complexity and to make 'many to one' tests
- * (e.g. checking user roles) possible without causing duplicate rows.
- */
- function pre_render(&$values) {
- if (!($flag = $this->get_flag())) {
- return; // Error message is printed in render().
- }
-
- $ids = array();
- foreach ($values as $row) {
- $entity_id = $row->{$this->aliases['entity_id']};
- $is_flagged = $row->{$this->aliases['is_flagged']};
- if (isset($entity_id)) {
- $ids[$entity_id] = $is_flagged ? 'unflag' : 'flag';
- }
- }
- $this->flag_applies = $ids ? $flag->access_multiple($ids) : array();
- }
-
- function render($values) {
- if (!($flag = $this->get_flag())) {
- return t('Missing flag'); // get_flag() itself will print a more detailed message.
- }
-
- $entity_id = $values->{$this->aliases['entity_id']};
- $is_flagged = $values->{$this->aliases['is_flagged']};
-
- if (empty($this->flag_applies[$entity_id])) {
- // Flag does not apply to this content.
- return;
- }
-
- if (!empty($this->options['link_type'])) {
- $flag->link_type = $this->options['link_type'];
- }
- return $flag->theme($is_flagged ? 'unflag' : 'flag', $entity_id);
- }
-}
diff --git a/includes/views/flag_handler_filter_flagged.inc b/includes/views/flag_handler_filter_flagged.inc
deleted file mode 100644
index d22c40b..0000000
--- a/includes/views/flag_handler_filter_flagged.inc
+++ /dev/null
@@ -1,33 +0,0 @@
- 1);
- return $options;
- }
-
- function options_form(&$form, &$form_state) {
- parent::options_form($form, $form_state);
- $form['value']['#type'] = 'radios';
- $form['value']['#title'] = t('Status');
- $form['value']['#options'] = array(1 => t('Flagged'), 0 => t('Not flagged'), 'All' => t('All'));
- $form['value']['#default_value'] = empty($this->options['value']) ? '0' : $this->options['value'];
- $form['value']['#description'] = '' . t('This filter is only needed if the relationship used has the "Include only flagged content" option unchecked. Otherwise, this filter is useless, because all records are already limited to flagged content.') . '
' . t('By choosing Not flagged, it is possible to create a list of content that is specifically not flagged.', array('@unflagged-url' => 'http://drupal.org/node/299335')) . '
';
- }
-
- function query() {
- $operator = $this->value ? 'IS NOT' : 'IS';
- $this->query->add_where($this->options['group'], $this->relationship . '.uid', NULL, $operator . ' NULL');
- }
-}
diff --git a/includes/views/flag_handler_relationships.inc b/includes/views/flag_handler_relationships.inc
deleted file mode 100644
index 9a7c964..0000000
--- a/includes/views/flag_handler_relationships.inc
+++ /dev/null
@@ -1,267 +0,0 @@
- NULL);
- $options['required'] = array('default' => 1);
- return $options;
- }
-
- /**
- * Make sure the flag exists.
- *
- * When importing views, or when deleting flags, inconsistent views may
- * result. This validator is called by Views before saving or previewing a
- * view.
- */
- function validate() {
- $errors = array();
- $tokens = array(
- '@relationship-name' => $this->ui_name() . ' ' . $this->admin_summary(),
- '@flag-name' => $this->options['flag'],
- );
- if (!$this->options['flag']) {
- $errors[] = t('You must pick a flag to use for the relationship "@relationship-name".', $tokens);
- }
- elseif (!flag_get_flag($this->options['flag'])) {
- $errors[] = t('This view is looking for a flag by the name "@flag-name", but there is no such flag. Perhaps it was deleted. Please update the relationship "@relationship-name" in this view to use an existing flag.', $tokens);
- }
- return $errors;
- }
-
- function get_flag_type() {
- return isset($this->definition['flag type']) ? $this->definition['flag type'] : NULL;
- }
-
- /**
- * Returns the flag object.
- */
- function get_flag() {
-
- // Backward compatibility: There may exist old views on the system whose
- // 'flag' option isn't set. (This happens if the admin had skippped
- // clicking the 'Update' button.) When run, these views should behave as
- // if the first flag was selected.
- if (!isset($this->options['flag'])) {
- $this->options['flag'] = flag_views_flag_default($this->get_flag_type());
- }
-
- // Validation: Since validate() is called only when in Views's
- // administrative UI, we need to do validation at "run time" ourselves.
- if (($errors = $this->validate())) {
- foreach ($errors as $error) {
- drupal_set_message($error, 'error');
- }
- }
-
- return flag_get_flag($this->options['flag']);
- }
-
- // @todo: It's logical that this class should also implement options_form(),
- // to show the flag selector, and query(), to filter on the flag.
-}
-
-/**
- * Specialized relationship handler associating flags and content.
- *
- * @ingroup views
- */
-class flag_handler_relationship_content extends flag_handler_relationship {
-
- function option_definition() {
- $options = parent::option_definition();
- $options['user_scope'] = array('default' => 'current');
- return $options;
- }
-
- function options_form(&$form, &$form_state) {
- parent::options_form($form, $form_state);
- $entity_type = $this->definition['flag type'];
- $form['label']['#description'] .= ' ' . t('The name of the selected flag makes a good label.');
- $form['flag'] = flag_views_flag_config_form('radios', $entity_type, $this->options['flag']);
-
- $form['user_scope'] = array(
- '#type' => 'radios',
- '#title' => t('By'),
- '#options' => array('current' => t('Current user'), 'any' => t('Any user')),
- '#default_value' => $this->options['user_scope'],
- );
-
- $form['required']['#title'] = t('Include only flagged content');
- $form['required']['#description'] = t('If checked, only content that has this flag will be included. Leave unchecked to include all content; or, in combination with the Flagged filter, to limit the results to specifically unflagged content.', array('@unflagged-url' => 'http://drupal.org/node/299335'));
-
- if (!$form['flag']['#options']) {
- $form = array(
- 'error' => array(
- '#markup' => '' . t('No %type flags exist. You must first create a %type flag before being able to use this relationship type.', array('%type' => $entity_type, '@create-url' => url(FLAG_ADMIN_PATH))) . '
',
- ),
- );
- $form_state['no flags exist'] = TRUE;
- }
- if (module_exists('session_api')) {
- $form['session_warning'] = array(
- '#markup' => '' . t('Warning: Adding this relationship for any flag that contains anonymous flagging access will disable page caching for anonymous users when this view is executed. (But this is only true when the relationship is constrained to "Current user", not to "Any user".) It is recommended to create a dedicated page for views containing anonymous user data.') . '
',
- );
- }
- }
-
- function options_validate(&$form, &$form_state) {
- if (!empty($form_state['no flags exist'])) {
- form_error($form, t('You must first create a flag'));
- }
- }
-
- function admin_summary() {
- return $this->options['user_scope'] == 'current' ? t('by current user') : t('by any user');
- }
-
- function ui_name($short = FALSE) {
- // We put the bookmark name in the UI string to save space.
- return t('!group: !title', array('!group' => $this->definition['group'], '!title' => empty($this->options['flag']) ? t('(Please select a flag)') : $this->options['flag']));
- }
-
- /**
- * Called to implement a relationship in a query.
- */
- function query() {
- if (!($flag = $this->get_flag())) {
- return;
- }
-
- $this->definition['extra'][] = array(
- 'field' => 'fid',
- 'value' => $flag->fid,
- 'numeric' => TRUE,
- );
- if ($this->options['user_scope'] == 'current' && !$flag->global) {
- $this->definition['extra'][] = array(
- 'field' => 'uid',
- 'value' => '***CURRENT_USER***',
- 'numeric' => TRUE,
- );
- $flag_roles = user_roles(FALSE, "flag $flag->name");
- if (isset($flag_roles[DRUPAL_ANONYMOUS_RID])) {
- // Disable page caching for anonymous users.
- drupal_page_is_cacheable(FALSE);
-
- // Add in the SID from Session API for anonymous users.
- $this->definition['extra'][] = array(
- 'field' => 'sid',
- 'value' => '***FLAG_CURRENT_USER_SID***',
- 'numeric' => TRUE,
- );
- }
- }
- parent::query();
- }
-}
-
-/**
- * Specialized relationship handler associating flag counts and content.
- *
- * @ingroup views
- */
-class flag_handler_relationship_counts extends flag_handler_relationship {
-
- function options_form(&$form, &$form_state) {
- parent::options_form($form, $form_state);
- $entity_type = $this->definition['flag type'];
- $form['flag'] = flag_views_flag_config_form('radios', $entity_type, $this->options['flag']);
-
- $form['required']['#title'] = t('Include only flagged content');
- $form['required']['#description'] = t('If checked, only content that is flagged will be included.');
- }
-
- function admin_summary() {
- // Nothing to show.
- }
-
- function ui_name($short = FALSE) {
- // We put the bookmark name in the UI string to save space.
- return t('!group: !title counter', array('!group' => $this->definition['group'], '!title' => $this->options['flag']));
- }
-
- /**
- * Called to implement a relationship in a query.
- */
- function query() {
- if (!($flag = $this->get_flag())) {
- return;
- }
-
- $this->definition['extra'][] = array(
- 'field' => 'fid',
- 'value' => $flag->fid,
- 'numeric' => TRUE,
- );
- if (!empty($this->options['required'])) {
- // Unfortunately, we may have zeros in our table, so having
- // parent::query() do INNER JOIN doesn't suffice. We need to filter these
- // zeros out.
- // @todo Make sure zero records aren't written in the first place, and
- // remove this code.
- $this->definition['extra'][] = array(
- 'field' => 'count',
- 'operator' => '>',
- 'value' => '0',
- 'numeric' => TRUE,
- );
- }
- parent::query();
- }
-}
-
-/**
- * Specialized relationship handler associating flags and users.
- *
- * @ingroup views
- */
-class flag_handler_relationship_user_content extends flag_handler_relationship {
-
- function options_form(&$form, &$form_state) {
- parent::options_form($form, $form_state);
- $form['label']['#description'] .= ' ' . t('Including name of the selected flag helps identify this relationship.');
-
- $form['flag'] = flag_views_flag_config_form('radios', NULL, $this->options['flag']);
- $form['flag']['#title'] = t('Flagged');
-
- $form['required']['#title'] = t('Include only users who have flagged content.');
- $form['required']['#description'] = t('If checked, only users that have flagged any content with this flag will be included.');
- }
-
- function admin_summary() {
- return $this->options['flag'];
- }
-
- /**
- * Called to implement a relationship in a query.
- */
- function query() {
- if (!($flag = $this->get_flag())) {
- return;
- }
-
- $this->definition['extra'][] = array(
- 'field' => 'fid',
- 'value' => $flag->fid,
- 'numeric' => TRUE,
- );
- parent::query();
- }
-}
-
diff --git a/includes/views/flag_handler_sort_flagged.inc b/includes/views/flag_handler_sort_flagged.inc
deleted file mode 100644
index 63c2787..0000000
--- a/includes/views/flag_handler_sort_flagged.inc
+++ /dev/null
@@ -1,47 +0,0 @@
- t('Unflagged first'),
- 'DESC' => t('Flagged first'),
- );
- }
-
- /**
- * Display whether or not the sort order is ascending or descending
- */
- function admin_summary() {
- if (!empty($this->options['exposed'])) {
- return t('Exposed');
- }
-
- // Get the labels defined in sort_options().
- $sort_options = $this->sort_options();
- return $sort_options[strtoupper($this->options['order'])];
- }
-
- function query() {
- $this->ensure_my_table();
- // Add the ordering.
- // Using IS NOT NULL means that the ASC/DESC ordering work in the same
- // direction as sorting by flagging date: empty results come first.
- $this->query->add_orderby(NULL, "($this->table_alias.uid IS NOT NULL)", $this->options['order']);
- }
-
-}
diff --git a/includes/views/flag_plugin_argument_validate_flaggability.inc b/includes/views/flag_plugin_argument_validate_flaggability.inc
deleted file mode 100644
index f653412..0000000
--- a/includes/views/flag_plugin_argument_validate_flaggability.inc
+++ /dev/null
@@ -1,226 +0,0 @@
-flag_type = $this->definition['flag type'];
- }
-
- function option_definition() {
- $options = parent::option_definition();
- $options['flag_name'] = array('default' => '*relationship*');
- $options['flag_test'] = array('default' => 'flaggable');
- $options['flag_id_type'] = array('default' => 'id');
- return $options;
- }
-
- function options_form(&$form, &$form_state) {
- // If there are no flag relationships set, skip this form of validation.
- $flags = flag_get_flags($this->flag_type);
- if (!$flags) {
- return array();
- }
- $options = $this->flags_options();
-
- $form['flag_name'] = array(
- '#type' => 'radios',
- '#title' => t('Flag'),
- '#options' => $options,
- '#default_value' => $this->options['flag_name'],
- '#description' => t('Select the flag to validate against.'),
- );
- if (!$options) {
- $form['flag_name']['#description'] = '' . t('No %type flags exist. You must first create a %type flag before being able to use one.', array('%type' => $this->flag_type, '@create-url' => FLAG_ADMIN_PATH)) . '
';
- }
-
- $form['flag_test'] = array(
- '#type' => 'select',
- '#title' => t('Validate the @type only if', array('@type' => $this->flag_type)),
- '#options' => $this->tests_options(),
- '#default_value' => $this->options['flag_test'],
- );
-
- // This validator supports the "multiple IDs" syntax. It may not be
- // extremely useful, but similar validators do support this and it's a good
- // thing to be compatible.
- $form['flag_id_type'] = array(
- '#type' => 'select',
- '#title' => t('Argument type'),
- '#options' => array(
- 'id' => t('ID'),
- 'ids' => t('IDs separated by , or +'),
- ),
- '#default_value' => $this->options['flag_id_type'],
- );
- }
-
- /**
- * Returns form #options for the flags. Returns empty array if no flags were
- * found.
- */
- function flags_options() {
- $flags = flag_get_flags($this->flag_type);
- if (!$flags) {
- return array();
- }
- else {
- foreach ($flags as $flag) {
- $options[$flag->name] = $flag->get_title();
- }
- $options['*relationship*'] = t('Pick the first flag mentioned in the relationships.');
- return $options;
- }
- }
-
- /**
- * Migrate existing Views 2 options to Views 3.
- */
- function convert_options(&$options) {
- $prefix = 'validate_argument_' . $this->flag_type . '_';
- if (!isset($options['flag_name']) && !empty($this->argument->options[$prefix . 'flag_name'])) {
- $options['flag_name'] = $this->argument->options[$prefix . 'flag_name'];
- $options['flag_test'] = $this->argument->options[$prefix . 'flag_test'];
- $options['flag_id_type'] = $this->argument->options[$prefix . 'flag_id_type'];
- }
- }
-
- /**
- * Declares all tests. This scheme makes it easy for derived classes to add
- * and remove tests.
- */
- function tests_info($which = NULL) {
- return array(
- 'flaggable' => array(
- 'title' => t('It is flaggable'),
- 'callback' => 'test_flaggable',
- ),
- 'flagged' => array(
- 'title' => t('It is flagged at least once'),
- 'callback' => 'test_flagged',
- ),
- 'flagged_by_current_user' => array(
- 'title' => t('It is flagged by the current user'),
- 'callback' => 'test_flagged_by_current_user',
- ),
- );
- }
-
- function tests_options() {
- $options = array();
- foreach ($this->tests_info() as $id => $info) {
- $options[$id] = $info['title'];
- }
- return $options;
- }
-
- function get_flag() {
- $flag_name = $this->options['flag_name'];
-
- if ($flag_name == '*relationship*') {
- // Pick the first flag mentioned in the relationships.
- foreach ($this->view->relationship as $id => $handler) {
- // Note: we can't do $handler->field, because the relationship handler's init() may overwrite it.
- if (strpos($handler->options['field'], 'flag') !== FALSE && !empty($handler->options['flag'])) {
- $flag = flag_get_flag($handler->options['flag']);
- if ($flag && $flag->entity_type == $this->flag_type) {
- return $flag;
- }
- }
- }
- }
-
- return flag_get_flag($flag_name);
- }
-
- /**
- * Tests whether the argument is flaggable, or flagged, or flagged by current
- * user. These are three possible tests, and which of the three to actually
- * carry out is determined by 'flag_test'.
- */
- function validate_argument($argument) {
- $flag_test = $this->options['flag_test'];
- $id_type = $this->options['flag_id_type'];
-
- $flag = $this->get_flag();
- if (!$flag) {
- // Validator is misconfigured somehow.
- return TRUE;
- }
-
- if ($id_type == 'id') {
- if (!is_numeric($argument)) {
- // If a user is being smart and types several IDs where only one is
- // expected, we invalidate this.
- return FALSE;
- }
- }
-
- $ids = views_break_phrase($argument, $this);
- if ($ids->value == array(-1)) {
- // Malformed argument syntax. Invalidate.
- return FALSE;
- }
- $ids = $ids->value;
-
- // Delegate the testing to the particual test method. $passed then
- // holds the IDs that passed the test.
- $tests_info = $this->tests_info();
- $method = $tests_info[$flag_test]['callback'];
- if (method_exists($this, $method)) {
- $passed = $this->$method($ids, $flag);
- }
- else {
- $passed = array();
- }
-
- // If some IDs exist that haven't $passed our test then validation fails.
- $failed = array_diff($ids, $passed);
- return empty($failed);
- }
-
- //
- // The actual tests. They return the IDs that passed.
- //
-
- function test_flaggable($ids, $flag) {
- return array_filter($ids, array($flag, 'applies_to_entity_id'));
- }
-
- function test_flagged($ids, $flag) {
- // view_break_phrase() is guaranteed to return only integers, so this is SQL safe.
- $flattened_ids = implode(',', $ids);
- return $this->_test_by_sql("SELECT entity_id FROM {flag_counts} WHERE fid = :fid AND entity_id IN ($flattened_ids) AND count > 0", array(':fid' => $flag->fid));
- }
-
- function test_flagged_by_current_user($ids, $flag) {
- global $user;
- if (!$user->uid) {
- // Anonymous user
- return array();
- }
- $flattened_ids = implode(',', $ids);
- return $this->_test_by_sql("SELECT entity_id FROM {flagging} WHERE fid = :fid AND entity_id IN ($flattened_ids) AND uid = :uid", array(':fid' => $flag->fid, ':uid' => $user->uid));
- }
-
- // Helper: executes an SQL query and returns all the entity_id's.
- function _test_by_sql($sql, $args) {
- $passed = array();
- $result = db_query($sql, $args);
- foreach ($result as $row) {
- $passed[] = $row->entity_id;
- }
- return $passed;
- }
-}
-
diff --git a/plugins/access/flag_is_flagged/flag_is_flagged.inc b/plugins/access/flag_is_flagged/flag_is_flagged.inc
deleted file mode 100644
index 68e1021..0000000
--- a/plugins/access/flag_is_flagged/flag_is_flagged.inc
+++ /dev/null
@@ -1,96 +0,0 @@
- t("Entity is flagged"),
- 'description' => t('Control access by whether or not an entity is flagged.'),
- 'callback' => 'flag_flag_is_flagged_access_check',
- 'default' => array('flag_name' => ''),
- 'settings form' => 'flag_flag_is_flagged_access_settings',
- 'summary' => 'flag_flag_is_flagged_access_summary',
- 'get child' => 'flag_flag_is_flagged_access_get_child',
- 'get children' => 'flag_flag_is_flagged_access_get_children',
-);
-
-/*
- * Implements plugin get_child callback.
- */
-function flag_flag_is_flagged_access_get_child($plugin, $parent, $child) {
- $plugins = flag_flag_is_flagged_access_get_children($plugin, $parent);
- return $plugins[$parent . ':' . $child];
-}
-
-/*
- * Implements plugin get_children callback.
- */
-function flag_flag_is_flagged_access_get_children($plugin, $parent) {
- $plugins = array();
- $entities = entity_get_info();
-
- foreach ($entities as $entity_type => $info) {
- if (entity_type_supports($entity_type, 'view')) {
- $plugin['title'] = t('@entity_type is flagged', array('@entity_type' => $info['label']));
- $plugin['keyword'] = $entity_type;
- $plugin['name'] = $parent . ':' . $entity_type;
- $plugin['required context'] = new ctools_context_required(t('Entity'), $entity_type);
- $plugins[$parent . ':' . $entity_type] = $plugin;
- }
- }
-
- return $plugins;
-}
-
-/**
- * Settings form.
- */
-function flag_flag_is_flagged_access_settings(&$form, &$form_state, $conf) {
- $options = array();
-
- $plugin = $form_state['plugin'];
- $entity_type = explode(':', $plugin['name']);
- $entity_type = $entity_type[1];
-
- foreach (flag_get_flags($entity_type) as $flag) {
- $options[$flag->name] = check_plain($flag->title);
- }
-
- $form['settings']['flag_name'] = array(
- '#title' => t('Flag name'),
- '#type' => 'radios',
- '#options' => $options,
- '#description' => t('Include only flagged content.'),
- '#default_value' => $conf['flag_name'],
- );
- return $form;
-}
-
-/**
- * Check for access.
- */
-function flag_flag_is_flagged_access_check($conf, $context) {
- $flag = flag_get_flag($conf['flag_name']);
- if (!$flag || empty($context->data)) {
- return FALSE;
- }
-
- // Get the ID of the entity.
- list($id) = entity_extract_ids($flag->entity_type, $context->data);
-
- return $flag->is_flagged($id);
-}
-
-/**
- * Provide a summary description based upon the specified context
- */
-function flag_flag_is_flagged_access_summary($conf, $context) {
- $flag = flag_get_flag($conf['flag_name']);
-
- if ($flag) {
- return t('@identifier is flagged with "@flag"', array('@flag' => check_plain($flag->title), '@identifier' => $context->identifier));
- }
- else {
- return t('Missing/ deleted flag "@flag"', array('@flag' => $conf['flag_name']));
- }
-}
diff --git a/plugins/content_types/flag_link/flag_link.inc b/plugins/content_types/flag_link/flag_link.inc
deleted file mode 100644
index 33de132..0000000
--- a/plugins/content_types/flag_link/flag_link.inc
+++ /dev/null
@@ -1,115 +0,0 @@
- t('Flag link'),
- 'description' => t('Add a flag link of a certain flag type for entities.'),
- 'defaults' => array('flag_name' => ''),
- 'content type' => 'flag_flag_link_content_type_info',
-);
-
-/**
- * Get the entity content type info.
- */
-function flag_flag_link_content_type_info($entity_type) {
- $types = flag_flag_link_content_type_content_types();
- if (isset($types[$entity_type])) {
- return $types[$entity_type];
- }
-}
-
-/**
- * Implements hook_PLUGIN_content_type_content_types().
- */
-function flag_flag_link_content_type_content_types() {
- $types = array();
- $entities = entity_get_info();
-
- foreach ($entities as $entity_type => $info) {
- if (entity_type_supports($entity_type, 'view')) {
- $types[$entity_type] = array(
- 'title' => t('Flag for @entity_type', array('@entity_type' => $info['label'])),
- 'category' => t('Entity'),
- 'required context' => new ctools_context_required(t('Entity'), $entity_type),
- );
- }
- }
-
- return $types;
-}
-
-/**
- * Render callback.
- */
-function flag_flag_link_content_type_render($subtype, $conf, $args, $context) {
- $flag = flag_get_flag($conf['flag_name']);
- if (!$flag) {
- return;
- }
-
- if (empty($context->data)) {
- return;
- }
-
- // Get the ID of the entity.
- list($id,,) = entity_extract_ids($flag->entity_type, $context->data);
- $link = flag_create_link($flag->name, $id);
-
- if (!$link) {
- return;
- }
-
- $block = new stdClass();
- $block->module = 'flag';
- $block->title = t('Flag link');
- $block->delta = $flag->name;
-
- $block->content = $link;
- return $block;
-}
-
-/**
- * Form callback.
- */
-function flag_flag_link_content_type_edit_form($form, &$form_state) {
- $conf = $form_state['conf'];
- $entity_type = $form_state['subtype_name'];
- $options = array();
-
- foreach (flag_get_flags($entity_type) as $flag) {
- $options[$flag->name] = $flag->title;
- }
-
- $form['flag_name'] = array(
- '#type' => 'select',
- '#title' => t('Flag name'),
- '#default_value' => $conf['flag_name'],
- '#options' => $options,
- '#description' => t('Select a flag.'),
- '#required' => TRUE,
- '#disabled' => !$options,
- );
-
- return $form;
-}
-
-/**
- * Form submit.
- */
-function flag_flag_link_content_type_edit_form_submit($form, &$form_state) {
- // Copy everything from our defaults.
- foreach (array_keys($form_state['plugin']['defaults']) as $key) {
- $form_state['conf'][$key] = $form_state['values'][$key];
- }
-}
-
-/**
- * Returns the administrative title for a flag link.
- */
-function flag_flag_link_content_type_admin_title($subtype, $conf) {
- if ($flag = flag_get_flag($conf['flag_name'])) {
- return t('Flag link of @flag', array('@flag' => $flag->title));
- }
-}
diff --git a/tests/flag.test b/tests/flag.test
deleted file mode 100644
index 8d67758..0000000
--- a/tests/flag.test
+++ /dev/null
@@ -1,971 +0,0 @@
-save();
- // Reset our cache so our permissions show up.
- drupal_static_reset('flag_get_flags');
-
- // Reset permissions so that permissions for this flag are available.
- $this->checkPermissions(array(), TRUE);
-
- return $flag;
- }
-
-}
-
-/**
- * Test CRUD operations on Flagging entities.
- */
-class FlagFlaggingCRUDTestCase extends FlagTestCaseBase {
-
- /**
- * Implements getInfo().
- */
- public static function getInfo() {
- return array(
- 'name' => 'Flagging CRUD',
- 'description' => 'Basic CRUD operations on flagging entities.',
- 'group' => 'Flag',
- );
- }
-
- /**
- * Implements setUp().
- */
- function setUp() {
- parent::setUp('flag');
-
- $flag_data = array(
- 'entity_type' => 'node',
- 'name' => 'test_flag',
- 'title' => 'Test Flag',
- 'global' => 0,
- 'types' => array(
- 0 => 'article',
- ),
- 'flag_short' => 'Flag this item',
- 'flag_long' => '',
- 'flag_message' => '',
- 'unflag_short' => 'Unflag this item',
- 'unflag_long' => '',
- 'unflag_message' => '',
- 'unflag_denied_text' => 'You may not unflag this item',
- 'link_type' => 'normal',
- 'weight' => 0,
- 'show_on_form' => 0,
- 'access_author' => '',
- 'show_contextual_link' => 0,
- 'show_in_links' => array(
- 'full' => 1,
- 'teaser' => 1,
- ),
- 'i18n' => 0,
- 'api_version' => 3,
- );
- $this->flag = $this->createFlag($flag_data);
-
- // Create test user who can flag and unflag.
- $this->flag_unflag_user = $this->drupalCreateUser(array('flag test_flag', 'unflag test_flag'));
- $this->drupalLogin($this->flag_unflag_user);
- }
-
- /**
- * Test creation of a flagging entity with flagging_save().
- */
- function testFlaggingCreate() {
- // Create an article node that we try to create a flagging entity for.
- $title = $this->randomName(8);
- $node = array(
- 'title' => $title,
- 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
- 'uid' => 1,
- 'type' => 'article',
- 'is_new' => TRUE,
- );
- $node = node_submit((object) $node);
- node_save($node);
-
- // Create a flagging entity and save it.
- $flagging = array(
- 'fid' => $this->flag->fid,
- 'entity_type' => 'node',
- 'entity_id' => $node->nid,
- 'uid' => $this->flag_unflag_user->uid,
- );
-
- $flagging = (object) $flagging;
- flagging_save($flagging);
-
- // Test flagging has a flagging_id
- $this->assertTrue(!empty($flagging->flagging_id), 'The flagging entity has an entity id.');
-
- // Test the database record exists.
- $result = db_query("SELECT * FROM {flagging} WHERE fid = :fid AND entity_id = :nid AND uid = :uid", array(
- ':fid' => $this->flag->fid,
- ':nid' => $node->nid,
- ':uid' => $this->flag_unflag_user->uid,
- ));
- $records = $result->fetchAll();
- $this->assertTrue(count($records), 'The flagging record exists in the database.');
-
- // Test node is flagged.
- // The current user is not the same as the user logged into the internal
- // browser, so we have to pass the UID param explicitly.
- $this->assertTrue($this->flag->is_flagged($node->nid, $this->flag_unflag_user->uid), 'The node has been flagged by creating the flagging.');
- }
-
- /**
- * Test throwing of exceptions with flagging_save().
- */
- function testFlaggingCreateException() {
- // Create an article node that we try to create a flagging entity for.
- $title = $this->randomName(8);
- $node = array(
- 'title' => $title,
- 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
- 'uid' => 1,
- 'type' => 'article',
- 'is_new' => TRUE,
- );
- $node = node_submit((object) $node);
- node_save($node);
-
- // Create test user who can't use this flag.
- $no_flag_user = $this->drupalCreateUser(array());
-
- // Create a flagging entity with that tries to perform an flagging action
- // that is not permitted.
- $flagging = array(
- 'fid' => $this->flag->fid,
- 'entity_type' => 'node',
- 'entity_id' => $node->nid,
- 'uid' => $no_flag_user->uid,
- );
-
- $flagging = (object) $flagging;
- try {
- flagging_save($flagging);
- $this->fail(t('Expected exception has not been thrown.'));
- }
- catch (Exception $e) {
- $this->pass(t('Expected exception has been thrown.'));
- }
- }
-
- /**
- * Test creation of a flagging entity with flagging_save().
- */
- function testFlaggingUpdate() {
- // Create an article node that we try to create a flagging entity for.
- $title = $this->randomName(8);
- $node = array(
- 'title' => $title,
- 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
- 'uid' => 1,
- 'type' => 'article',
- 'is_new' => TRUE,
- );
- $node = node_submit((object) $node);
- node_save($node);
-
- // Flag the node as the user.
- $flag = flag_get_flag('test_flag');
- $flag->flag('flag', $node->nid, $this->flag_unflag_user);
-
- // Get the flagging record back from the database.
- $result = db_query("SELECT * FROM {flagging} WHERE fid = :fid AND entity_id = :nid AND uid = :uid", array(
- ':fid' => $this->flag->fid,
- ':nid' => $node->nid,
- ':uid' => $this->flag_unflag_user->uid,
- ));
- $record = $result->fetchObject();
-
- // Load the flagging entity we just created.
- $flagging = flagging_load($record->flagging_id);
-
- // Save it, as if we were updating field values.
- flagging_save($flagging);
-
- // This should have no effect: the node should still be flagged.
- $this->assertTrue($this->flag->is_flagged($node->nid, $this->flag_unflag_user->uid), 'The node is still flagged after updating the flagging.');
- }
-
-}
-
-/**
- * Test Flag admin UI.
- */
-class FlagAdminTestCase extends FlagTestCaseBase {
- var $_flag = FALSE;
-
- /**
- * Implements getInfo().
- */
- public static function getInfo() {
- return array(
- 'name' => 'Flag admin tests',
- 'description' => 'Add, edit and delete flags.',
- 'group' => 'Flag',
- );
- }
-
- /**
- * Implements setUp().
- */
- function setUp() {
- parent::setUp('flag');
-
- // Create and login user
- $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer flags'));
- $this->drupalLogin($admin_user);
- }
-
- /**
- * Create a flag through the UI and ensure that it is saved properly.
- */
- function testFlagAdmin() {
- // Add a new flag using the UI.
- $edit = array(
- 'name' => drupal_strtolower($this->randomName()),
- 'title' => $this->randomName(),
- 'flag_short' => 'flag short [node:nid]',
- 'flag_long' => 'flag long [node:nid]',
- 'flag_message' => 'flag message [node:nid]',
- 'unflag_short' => 'unflag short [node:nid]',
- 'unflag_long' => 'unflag long [node:nid]',
- 'unflag_message' => 'unflag message [node:nid]',
- 'roles[flag][2]' => TRUE,
- 'roles[unflag][2]' => TRUE,
- 'types[article]' => FALSE,
- 'types[page]' => TRUE,
- 'show_in_links[full]' => FALSE,
- 'show_in_links[teaser]' => FALSE,
- 'show_in_links[rss]' => FALSE,
- 'show_in_links[search_index]' => FALSE,
- 'show_in_links[search_result]' => FALSE,
- 'show_on_form' => FALSE,
- 'link_type' => 'toggle',
- );
- $saved = $edit;
- $saved['roles'] = array('flag' => array(2), 'unflag' => array(2));
- $saved['types'] = array('page');
- $saved['show_in_links'] = array('full' => 0, 'teaser' => 0, 'rss' => 0, 'search_index' => 0, 'search_result' => 0);
- unset($saved['roles[flag][2]'], $saved['roles[unflag][2]'], $saved['types[article]'], $saved['types[page]'], $saved['show_in_links[full]'], $saved['show_in_links[teaser]'], $saved['show_in_links[rss]'], $saved['show_in_links[search_index]'], $saved['show_in_links[search_result]']);
-
- $this->drupalPost(FLAG_ADMIN_PATH . '/add/node', $edit, t('Save flag'));
-
- drupal_static_reset('flag_get_flags');
- $flag = flag_get_flag($edit['name']);
- // Load the roles array for checking it matches.
- $flag->fetch_roles();
-
- // Check that the flag object is in the database.
- $this->assertTrue($flag != FALSE, t('Flag object found in database'));
-
- // Check each individual property of the flag and make sure it was set.
- foreach ($saved as $property => $value) {
- $this->assertEqual($flag->$property, $value, t('Flag property %property properly saved.', array('%property' => $property)));
- }
-
- // Check permissions.
- $permissions = user_role_permissions(user_roles());
- foreach ($saved['roles'] as $action => $rids) {
- foreach ($rids as $rid) {
- $permission_string = "$action ". $saved['name'];
- $this->assertTrue(isset($permissions[$rid][$permission_string]), t('Permission %perm set for flag.', array(
- '%perm' => $permission_string,
- )));
- }
- }
-
- // Edit the flag through the UI.
- $edit = array(
- 'name' => drupal_strtolower($this->randomName()),
- 'title' => $this->randomName(),
- 'flag_short' => 'flag 2 short [node:nid]',
- 'flag_long' => 'flag 2 long [node:nid]',
- 'flag_message' => 'flag 2 message [node:nid]',
- 'unflag_short' => 'unflag 2 short [node:nid]',
- 'unflag_long' => 'unflag 2 long [node:nid]',
- 'unflag_message' => 'unflag 2 message [node:nid]',
- 'roles[flag][2]' => TRUE,
- 'roles[unflag][2]' => TRUE,
- 'types[article]' => TRUE,
- 'types[page]' => FALSE,
- 'show_in_links[full]' => TRUE,
- 'show_in_links[teaser]' => TRUE,
- 'show_in_links[rss]' => FALSE,
- 'show_in_links[search_index]' => FALSE,
- 'show_in_links[search_result]' => FALSE,
- 'show_on_form' => TRUE,
- 'link_type' => 'normal',
- );
- $saved = $edit;
- $saved['roles'] = array('flag' => array(2), 'unflag' => array(2));
- $saved['types'] = array('article');
- $saved['show_in_links'] = array('full' => TRUE, 'teaser' => TRUE, 'rss' => 0, 'search_index' => 0, 'search_result' => 0);
- unset($saved['roles[flag][2]'], $saved['roles[unflag][2]'], $saved['types[article]'], $saved['types[page]'], $saved['show_in_links[full]'], $saved['show_in_links[teaser]'], $saved['show_in_links[rss]'], $saved['show_in_links[search_index]'], $saved['show_in_links[search_result]']);
-
- $this->drupalPost(FLAG_ADMIN_PATH . '/manage/' . $flag->name, $edit, t('Save flag'));
-
- drupal_static_reset('flag_get_flags');
- $flag = flag_get_flag($edit['name']);
- // Load the roles array for checking it matches.
- $flag->fetch_roles();
-
- // Check that the flag object is in the database.
- $this->assertTrue($flag != FALSE, t('Flag object found in database'));
-
- // Check each individual property of the flag and make sure it was set.
- foreach ($saved as $property => $value) {
- $this->assertEqual($flag->$property, $value, t('Flag property %property properly saved.', array('%property' => $property)));
- }
-
- // Clear the user access cache so our changes to permissions are noticed.
- drupal_static_reset('user_access');
- drupal_static_reset('user_role_permissions');
-
- // Check permissions.
- $permissions = user_role_permissions(user_roles());
-
- foreach ($saved['roles'] as $action => $rids) {
- foreach ($rids as $rid) {
- $permission_string = "$action ". $saved['name'];
- $this->assertTrue(isset($permissions[$rid][$permission_string]), t('Permission %perm set for flag.', array(
- '%perm' => $permission_string,
- )));
- }
- }
-
- // Delete the flag through the UI.
- $this->drupalPost(FLAG_ADMIN_PATH . '/manage/' . $flag->name . '/delete', array(), t('Delete'));
- drupal_static_reset('flag_get_flags');
- $this->assertFalse(flag_get_flag($flag->name), t('Flag successfully deleted.'));
- }
-
-}
-
-/**
- * Access to flags using the entity forms.
- *
- * @todo: complete this test class.
- */
-class FlagAccessFormTestCase extends FlagTestCaseBase {
-
- /**
- * Implements getInfo().
- */
- public static function getInfo() {
- return array(
- 'name' => 'Flag access: entity forms',
- 'description' => 'Access to flag and unflag entities via entity forms.',
- 'group' => 'Flag',
- );
- }
-
- /**
- * Implements setUp().
- */
- function setUp() {
- parent::setUp('flag');
- }
-
- /**
- * Test scenarios with no access to a global flag.
- */
- function testFlagAccessGlobalNone() {
- // Create a global flag on article nodes.
- $flag_data = array(
- 'entity_type' => 'node',
- 'name' => 'global_flag',
- 'title' => 'Global Flag',
- 'global' => 1,
- 'types' => array(
- 0 => 'article',
- ),
- 'flag_short' => 'Flag this item',
- 'flag_long' => '',
- 'flag_message' => '',
- 'unflag_short' => 'Unflag this item',
- 'unflag_long' => '',
- 'unflag_message' => '',
- 'unflag_denied_text' => 'You may not unflag this item',
- 'link_type' => 'normal',
- 'weight' => 0,
- // Show the flag on the form.
- 'show_on_form' => 1,
- 'access_author' => '',
- 'show_contextual_link' => 0,
- 'show_in_links' => array(
- 'full' => 1,
- 'teaser' => 1,
- ),
- 'i18n' => 0,
- 'api_version' => 3,
- );
- $flag = $this->createFlag($flag_data);
-
- // Create test user who can't us this flag, but can create nodes.
- $no_flag_user = $this->drupalCreateUser(array('create article content'));
- $this->drupalLogin($no_flag_user);
-
- $this->drupalGet('node/add/article');
-
- // Check that the flag form element cannot be seen
- $this->assertNoText('Flag this item', t('Flag form element was not found.'));
-
- // Have the user create a node.
- $edit = array(
- 'title' => 'node 1',
- );
- $this->drupalPost('node/add/article', $edit, t('Save'));
-
- $node = $this->drupalGetNodeByTitle($edit["title"]);
-
- // Check the new node has not been flagged.
- $this->assertFalse($flag->is_flagged($node->nid), t('New node is not flagged.'));
-
- // Now set the variable so that the flag is set by default on new nodes.
- variable_set('flag_' . $flag->name . '_default_' . 'article', 1);
-
- // Create another new node.
- $edit = array(
- 'title' => 'node 2',
- );
- $this->drupalPost('node/add/article', $edit, t('Save'));
-
- $node = $this->drupalGetNodeByTitle($edit["title"]);
-
- // Check the new node has been flagged, despite the user not having access
- // to the flag.
- $this->assertTrue($flag->is_flagged($node->nid), t('New node is flagged.'));
- }
-
-}
-
-/**
- * Access to flags using the basic flag link.
- */
-class FlagAccessLinkTestCase extends FlagTestCaseBase {
-
- /**
- * Implements getInfo().
- */
- public static function getInfo() {
- return array(
- 'name' => 'Flag access tests',
- 'description' => 'Access to flag and unflag entities using the basic link.',
- 'group' => 'Flag',
- );
- }
-
- /**
- * Implements setUp().
- */
- function setUp() {
- parent::setUp('flag');
-
- // Create a test flag on article nodes.
- $flag_data = array(
- 'entity_type' => 'node',
- 'name' => 'test_flag',
- 'title' => 'Test Flag',
- 'global' => 0,
- 'types' => array(
- 0 => 'article',
- ),
- 'flag_short' => 'Flag this item',
- 'flag_long' => '',
- 'flag_message' => '',
- 'unflag_short' => 'Unflag this item',
- 'unflag_long' => '',
- 'unflag_message' => '',
- 'unflag_denied_text' => 'You may not unflag this item',
- // Use the normal link type as it involves no intermediary page loads.
- 'link_type' => 'normal',
- 'weight' => 0,
- 'show_on_form' => 0,
- 'access_author' => '',
- 'show_contextual_link' => 0,
- 'show_in_links' => array(
- 'full' => 1,
- 'teaser' => 1,
- ),
- 'i18n' => 0,
- 'api_version' => 3,
- );
- $flag = $this->createFlag($flag_data);
-
- // Create an article node that various users will try to flag.
- $title = $this->randomName(8);
- $node = array(
- 'title' => $title,
- 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
- 'uid' => 1,
- 'type' => 'article',
- 'is_new' => TRUE,
- );
- $node = node_submit((object) $node);
- node_save($node);
- $this->nid = $node->nid;
- }
-
- /**
- * Test that a user without flag access can't see the flag.
- */
- function testFlagAccessNone() {
- // Create test user who can't flag at all.
- $no_flag_user = $this->drupalCreateUser(array());
- $this->drupalLogin($no_flag_user);
-
- // Look at our node.
- $this->drupalGet('node/' . $this->nid);
-
- $this->assertNoLink('Flag this item', 0, 'The flag link does not appear on the page');
- }
-
- /**
- * Test that a user with only flag access can flag but not unflag.
- */
- function testFlagAccessFlagOnly() {
- // Create test user who can flag but not unflag.
- $flag_user = $this->drupalCreateUser(array('flag test_flag',));
- $this->drupalLogin($flag_user);
-
- // Look at our node.
- $this->drupalGet('node/' . $this->nid);
-
- $this->assertLink('Flag this item', 0, 'The flag link appears on the page.');
-
- // Click the link to flag the node.
- $this->clickLink(t('Flag this item'));
-
- $this->assertText('You may not unflag this item', 0, 'The unflag denied text appears on the page after flagging.');
- }
-
- /**
- * Test that a user with flag access can flag and unflag.
- */
- function testFlagAccessFlagUnflag() {
- // Create test user who can flag and unflag.
- $flag_unflag_user = $this->drupalCreateUser(array('flag test_flag', 'unflag test_flag'));
- $this->drupalLogin($flag_unflag_user);
-
- // Look at our node.
- $this->drupalGet('node/' . $this->nid);
-
- $this->assertLink('Flag this item', 0, 'The flag link appears on the page.');
-
- // Click the link to flag the node.
- $this->clickLink(t('Flag this item'));
-
- $this->assertLink('Unflag this item', 0, 'The unflag link appears on the page after flagging.');
-
- // Click the link to unflag the node.
- $this->clickLink(t('Unflag this item'));
-
- $this->assertLink('Flag this item', 0, 'The flag link appears on the page after unflagging.');
- }
-
-}
-
-/**
- * Test the 'confirm form' link type.
- */
-class FlagLinkTypeConfirmTestCase extends DrupalWebTestCase {
-
- /**
- * Implements getInfo().
- */
- public static function getInfo() {
- return array(
- 'name' => 'Flag confirm link tests',
- 'description' => 'Flag confirm form link type.',
- 'group' => 'Flag',
- );
- }
-
- /**
- * Implements setUp().
- */
- function setUp() {
- parent::setUp('flag');
-
- // Create a test flag on article nodes.
- // Keep the original data so we can compare strings.
- $this->flag_data = array(
- 'entity_type' => 'node',
- 'name' => 'test_flag',
- 'title' => 'Test Flag',
- 'global' => 0,
- 'types' => array(
- 0 => 'article',
- ),
- 'flag_short' => 'Flag this item',
- 'flag_long' => '',
- 'flag_message' => 'You have flagged this item.',
- 'unflag_short' => 'Unflag this item',
- 'unflag_long' => '',
- 'unflag_message' => 'You have unflagged this item',
- 'unflag_denied_text' => 'You may not unflag this item',
- 'link_type' => 'confirm',
- 'flag_confirmation' => 'Are you sure you want to flag this item?',
- 'unflag_confirmation' => 'Are you sure you want to unflag this item?',
- 'weight' => 0,
- 'show_on_form' => 0,
- 'access_author' => '',
- 'show_contextual_link' => 0,
- 'show_in_links' => array(
- 'full' => 1,
- 'teaser' => 1,
- ),
- 'i18n' => 0,
- 'api_version' => 3,
- );
- $flag = flag_flag::factory_by_array($this->flag_data);
- $flag->save();
- // Reset our cache so our permissions show up.
- drupal_static_reset('flag_get_flags');
-
- // Reset permissions so that permissions for this flag are available.
- $this->checkPermissions(array(), TRUE);
-
- // Create test user who can flag and unflag.
- $flag_unflag_user = $this->drupalCreateUser(array('flag test_flag', 'unflag test_flag'));
- $this->drupalLogin($flag_unflag_user);
-
- // Create an article node to flag and unflag.
- $title = $this->randomName(8);
- $node = array(
- 'title' => $title,
- 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
- 'uid' => 1,
- 'type' => 'article',
- 'is_new' => TRUE,
- );
- $node = node_submit((object) $node);
- node_save($node);
- $this->nid = $node->nid;
- }
-
- /**
- * Test that a user sees the flag confirm form.
- */
- function testFlag() {
- // Look at our node.
- $this->drupalGet('node/' . $this->nid);
-
- $this->assertLink($this->flag_data['flag_short'], 0, 'The flag link appears on the page');
-
- // Click the link to flag the node.
- $this->clickLink($this->flag_data['flag_short']);
-
- $this->assertUrl('flag/confirm/flag/test_flag/' . $this->nid, array(
- 'query' => array(
- 'destination' => 'node/' . $this->nid,
- ),
- ), 'On confirm flagging form page.');
-
- $this->assertText($this->flag_data['flag_confirmation'], 'The flag confirmation text appears as the confirmation page title.');
-
- // Click the button to confirm the flagging.
- $this->drupalPost(NULL, array(), $this->flag_data['flag_short']);
-
- $this->assertText($this->flag_data['flag_message'], 'The flag message appears once the item has been flagged.');
- $this->assertLink($this->flag_data['unflag_short'], 0, 'The unflag link appears once the item has been flagged.');
-
- // Click the link to unflag the node.
- $this->clickLink($this->flag_data['unflag_short']);
-
- $this->assertUrl('flag/confirm/unflag/test_flag/' . $this->nid, array(
- 'query' => array(
- 'destination' => 'node/' . $this->nid,
- ),
- ), t('On confirm unflagging form page.'));
-
- $this->assertText($this->flag_data['unflag_confirmation'], 'The unflag confirmation text appears as the confirmation page title.');
-
- // Click the button to confirm the flagging.
- $this->drupalPost(NULL, array(), $this->flag_data['unflag_short']);
-
- $this->assertText($this->flag_data['unflag_message'], 'The unflag message appears once the item has been flagged.');
- }
-
-}
-
-/**
- * Verifies the implementation of hook_flag_access().
- */
-class FlagHookFlagAccessTestCase extends FlagTestCaseBase {
-
- /**
- * Implements getInfo().
- */
- public static function getInfo() {
- return array(
- 'name' => 'Flag hook_flag_access() tests',
- 'description' => 'Checks the ability of modules to use hook_flag_access().',
- 'group' => 'Flag',
- );
- }
-
- /**
- * Implements setUp().
- */
- function setUp() {
- parent::setUp('flag');
-
- $success = module_enable(array('flagaccesstest'), FALSE);
-
- // Create a test flag on article nodes.
- $flag_data = array(
- 'entity_type' => 'node',
- 'name' => 'test_flag',
- 'title' => 'Test Flag',
- 'global' => 0,
- 'types' => array(
- 0 => 'article',
- ),
- 'flag_short' => 'Flag this item',
- 'flag_long' => '',
- 'flag_message' => '',
- 'unflag_short' => 'Unflag this item',
- 'unflag_long' => '',
- 'unflag_message' => '',
- 'unflag_denied_text' => 'You may not unflag this item',
- // Use the normal link type as it involves no intermediary page loads.
- 'link_type' => 'normal',
- 'weight' => 0,
- 'show_on_form' => 0,
- 'access_author' => '',
- 'show_contextual_link' => 0,
- 'show_in_links' => array(
- 'full' => 1,
- 'teaser' => 1,
- ),
- 'i18n' => 0,
- 'api_version' => 3,
- );
- $flag = $this->createFlag($flag_data);
-
- // Create an article node that various users will try to flag.
- $title = $this->randomName(8);
- $node = array(
- 'title' => $title,
- 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
- 'uid' => 1,
- 'type' => 'article',
- 'is_new' => TRUE,
- );
- $node = node_submit((object) $node);
- node_save($node);
- $this->nid = $node->nid;
- }
-
- /**
- * Verifies that the user sees the flag if a module returns NULL (Ignore).
- */
- function testFlagAccessIgnore() {
- variable_set('FlagHookFlagAccessTestCaseMode', 'ignore');
- $flag_user = $this->drupalCreateUser(array('flag test_flag', 'unflag test_flag'));
- $this->drupalLogin($flag_user);
-
- // Look at our node.
- $this->drupalGet('node/' . $this->nid);
-
- $this->assertLink('Flag this item', 0, 'The flag link appears on the page.');
-
- // Click the link to flag the node.
- $this->clickLink(t('Flag this item'));
-
- $this->assertLink('Unflag this item', 0, 'The unflag link appears on the page after flagging.');
-
- // Click the link to unflag the node.
- $this->clickLink(t('Unflag this item'));
-
- $this->assertLink('Flag this item', 0, 'The flag link appears on the page after unflagging.');
- }
-
- /**
- * Verifies that the user sees the flag if a module returns TRUE (Allow).
- */
- function testFlagAccessAllow() {
- variable_set('FlagHookFlagAccessTestCaseMode', 'allow');
- $flag_user = $this->drupalCreateUser(array('flag test_flag', 'unflag test_flag'));
- $this->drupalLogin($flag_user);
-
- // Look at our node.
- $this->drupalGet('node/' . $this->nid);
-
- $this->assertLink('Flag this item', 0, 'The flag link appears on the page.');
-
- // Click the link to flag the node.
- $this->clickLink(t('Flag this item'));
-
- $this->assertLink('Unflag this item', 0, 'The unflag link appears on the page after flagging.');
-
- // Click the link to unflag the node.
- $this->clickLink(t('Unflag this item'));
-
- $this->assertLink('Flag this item', 0, 'The flag link appears on the page after unflagging.');
- }
-
- /**
- * Verifies that the user sees the flag if a module returns TRUE (Allow) to override default access check.
- */
- function testFlagAccessAllowOverride() {
- variable_set('FlagHookFlagAccessTestCaseMode', 'allow');
- $flag_user = $this->drupalCreateUser(array());
- $this->drupalLogin($flag_user);
-
- // Look at our node.
- $this->drupalGet('node/' . $this->nid);
-
- $this->assertLink('Flag this item', 0, 'The flag link appears on the page.');
-
- // Click the link to flag the node.
- $this->clickLink(t('Flag this item'));
-
- $this->assertLink('Unflag this item', 0, 'The unflag link appears on the page after flagging.');
-
- // Click the link to unflag the node.
- $this->clickLink(t('Unflag this item'));
-
- $this->assertLink('Flag this item', 0, 'The flag link appears on the page after unflagging.');
- }
-
- /**
- * Verifies that the user does not see the flag if a module returns FALSE (Deny).
- */
- function testFlagAccessDeny() {
- variable_set('FlagHookFlagAccessTestCaseMode', 'deny');
- $flag_user = $this->drupalCreateUser(array('flag test_flag', 'unflag test_flag'));
- $this->drupalLogin($flag_user);
-
- // Look at our node.
- $this->drupalGet('node/' . $this->nid);
-
- $this->assertNoLink('Flag this item', 0, 'The flag link does not appear on the page.');
- }
-
-}
-
-/**
- * Test use of EntityFieldQueries with flagging entities.
- */
-class FlagEntityFieldQueryTestCase extends FlagTestCaseBase {
-
- /**
- * Implements getInfo().
- */
- public static function getInfo() {
- return array(
- 'name' => 'Flagging Entity Field Query Extension',
- 'description' => 'Entity Field Query for flagging entities.',
- 'group' => 'Flag',
- );
- }
-
- /**
- * Implements setUp().
- */
- function setUp() {
- parent::setUp('flag');
-
- $flag_data = array(
- 'entity_type' => 'node',
- 'name' => 'test_flag_1',
- 'title' => 'Test Flag',
- 'global' => 0,
- 'types' => array(
- 0 => 'article',
- ),
- 'flag_short' => 'Flag this item',
- 'flag_long' => '',
- 'flag_message' => '',
- 'unflag_short' => 'Unflag this item',
- 'unflag_long' => '',
- 'unflag_message' => '',
- 'unflag_denied_text' => 'You may not unflag this item',
- // Use the normal link type as it involves no intermediary page loads.
- 'link_type' => 'normal',
- 'weight' => 0,
- 'show_on_form' => 0,
- 'access_author' => '',
- 'show_contextual_link' => 0,
- 'show_in_links' => array(
- 'full' => 1,
- 'teaser' => 1,
- ),
- 'i18n' => 0,
- 'api_version' => 3,
- );
-
- $this->flag1 = $this->createFlag($flag_data);
- $flag_data['name'] = 'test_flag_2';
- $this->flag2 = $this->createFlag($flag_data);
- $flag_data['name'] = 'test_flag_3';
- $this->flag3 = $this->createFlag($flag_data);
-
- // Create test user who can flag and unflag.
- $this->flag_unflag_user = $this->drupalCreateUser(array('flag test_flag_1', 'unflag test_flag_1', 'flag test_flag_2', 'unflag test_flag_2'));
- $this->drupalLogin($this->flag_unflag_user);
-
- }
-
- /**
- * Test use of EntityFieldQuery with flagging entities.
- */
- function testEntityFieldQuery() {
- $node_settings = array(
- 'title' => $this->randomName(),
- 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
- 'uid' => 1,
- 'type' => 'article',
- 'is_new' => TRUE,
- );
- $node = $this->drupalCreateNode($node_settings);
-
- flag('flag', 'test_flag_1', $node->nid, $this->flag_unflag_user);
- flag('flag', 'test_flag_2', $node->nid, $this->flag_unflag_user);
-
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'flagging')
- ->entityCondition('bundle', 'test_flag_1');
-
- $flagged = $query->execute();
- $this->assertEqual(count($flagged['flagging']), 1);
-
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'flagging')
- ->entityCondition('bundle', 'test%', 'like');
- $flagged = $query->execute();
- $this->assertEqual(count($flagged['flagging']), 2);
-
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'flagging')
- ->entityCondition('bundle', array('test_flag_1', 'test_flag_2'), 'IN');
- $this->assertEqual(count($flagged['flagging']), 2);
- }
-
-}
diff --git a/tests/flagaccesstest/flagaccesstest.info b/tests/flagaccesstest/flagaccesstest.info
deleted file mode 100644
index 3c9c176..0000000
--- a/tests/flagaccesstest/flagaccesstest.info
+++ /dev/null
@@ -1,6 +0,0 @@
-name = Flag hook_flag_access test
-description = Tests for hook_flag_access
-core = 7.x
-dependencies[] = flag
-package = Flags
-hidden = TRUE
diff --git a/tests/flagaccesstest/flagaccesstest.module b/tests/flagaccesstest/flagaccesstest.module
deleted file mode 100644
index 62a2ce7..0000000
--- a/tests/flagaccesstest/flagaccesstest.module
+++ /dev/null
@@ -1,26 +0,0 @@
-
Date: Thu, 21 Nov 2013 23:12:18 -0600
Subject: [PATCH 349/629] FlagType plugins now specify the entity types to
which they apply.
---
flag.module | 136 +-----------------
lib/Drupal/flag/Form/FlagAddPageForm.php | 10 +-
.../flag/Plugin/Flag/CommentFlagType.php | 9 ++
.../flag/Plugin/Flag/EntityFlagType.php | 12 ++
lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php | 8 +-
lib/Drupal/flag/Plugin/Flag/NodeFlagType.php | 9 ++
lib/Drupal/flag/Plugin/Flag/UserFlagType.php | 9 ++
7 files changed, 51 insertions(+), 142 deletions(-)
diff --git a/flag.module b/flag.module
index 612a3a2..17136f5 100644
--- a/flag.module
+++ b/flag.module
@@ -12,111 +12,6 @@ define('FLAG_ADMIN_PATH_START', 3);
use Drupal\flag\Handlers\AbstractFlag;
-/**
- * Implements hook_entity_info().
- */
-function flag_entity_info() {
- $return = array(
- 'flagging' => array(
- 'label' => t('Flagging'),
- 'controller class' => 'FlaggingController',
- 'base table' => 'flagging',
- 'fieldable' => TRUE,
- 'entity keys' => array(
- 'id' => 'flagging_id',
- 'bundle' => 'flag_name',
- ),
- // The following tells Field UI how to extract the bundle name from a
- // $flag object when we're visiting ?q=admin/.../manage/%flag/fields.
- 'bundle keys' => array(
- 'bundle' => 'name',
- ),
- 'bundles' => array(),
- // The following tells EntityAPI how to save flaggings, thus allowing use
- // of Entity metadata wrappers (if present).
- 'save callback' => 'flagging_save',
- ),
- );
-
- // Add bundle info but bypass flag_get_flags() as we cannot use it here, as
- // it calls entity_get_info().
- $result = db_query("SELECT name, title FROM {flag}");
- $flag_names = $result->fetchAllKeyed();
- foreach ($flag_names as $flag_name => $flag_title) {
- $return['flagging']['bundles'][$flag_name] = array(
- 'label' => $flag_title,
- 'admin' => array(
- 'path' => FLAG_ADMIN_PATH . '/manage/%flag',
- 'real path' => FLAG_ADMIN_PATH . '/manage/' . $flag_name,
- 'bundle argument' => FLAG_ADMIN_PATH_START + 1,
- 'access arguments' => array('administer flags'),
- ),
- );
- }
-
- return $return;
-}
-
-/**
- * Loads a flagging entity.
- *
- * @param $flagging_id
- * The 'flagging_id' database serial column.
- * @param $reset
- * Whether to reset the DrupalDefaultEntityController cache.
- *
- * @return
- * The entity object, or FALSE if it can't be found.
- */
-function flagging_load($flagging_id, $reset = FALSE) {
- // The flag machine name is loaded in by FlaggingController::buildQuery().
- $result = entity_load('flagging', array($flagging_id), array(), $reset);
- return reset($result);
-}
-
-/**
- * Saves a flagging entity.
- *
- * For a new flagging, throws an exception is the flag action is not allowed for
- * the given combination of flag, entity, and user.
- *
- * @param $flagging
- * The flagging entity. This may have either flag_name or the flag fid set,
- * and may also omit the uid property to use the current user.
- *
- * @throws Exception
- */
-function flagging_save($flagging) {
- // Get the flag, either way.
- if (isset($flagging->flag_name)) {
- $flag = flag_get_flag($flagging->flag_name);
- }
- else {
- $flag = flag_get_flag(NULL, $flagging->fid);
- }
-
- if (!$flag) {
- throw new Exception('Flag not found for flagging entity.');
- }
-
- // Fill in properties that may be omitted.
- $flagging->fid = $flag->fid;
- $flagging->flag_name = $flag->name;
-
- if (!empty($flagging->uid)) {
- $account = user_load($flagging->uid);
- }
- else {
- $account = NULL;
- }
-
- $result = $flag->flag('flag', $flagging->entity_id, $account, FALSE, $flagging);
-
- if (!$result) {
- throw new Exception('Flag action not allowed for given flagging entity properties.');
- }
-}
-
// @todo: Implement flagging_view(). Not extremely useful. I already have it.
// @todo: When renaming a flag: Call field_attach_rename_bundle().
@@ -263,7 +158,6 @@ function flag_menu() {
'file' => 'includes/flag.export.inc',
'type' => MENU_CALLBACK,
);
-*/
$items['flag/%/%flag/%'] = array(
'title' => 'Flag',
'page callback' => 'flag_page',
@@ -282,7 +176,7 @@ function flag_menu() {
'file' => 'includes/flag.pages.inc',
'type' => MENU_CALLBACK,
);
-
+*/
return $items;
}
@@ -445,34 +339,6 @@ function flag_help($path, $arg) {
}
}
-/**
- * Implements hook_init()
- *
- * @todo Figure out where Rules module, see https://drupal.org/node/1211396
- */
-function flag_init() {
- module_load_include('inc', 'flag', 'includes/flag.actions');
-}
-
-/**
- * Implements hook_hook_info().
- */
-function flag_hook_info() {
- $hooks['flag_type_info'] = array(
- 'group' => 'flag',
- );
- $hooks['flag_type_info_alter'] = array(
- 'group' => 'flag',
- );
- $hooks['flag_link_type_info'] = array(
- 'group' => 'flag',
- );
- $hooks['flag_link_type_info_alter'] = array(
- 'group' => 'flag',
- );
- return $hooks;
-}
-
/**
* Get a flag type definition.
*
diff --git a/lib/Drupal/flag/Form/FlagAddPageForm.php b/lib/Drupal/flag/Form/FlagAddPageForm.php
index 532cdee..53aad74 100644
--- a/lib/Drupal/flag/Form/FlagAddPageForm.php
+++ b/lib/Drupal/flag/Form/FlagAddPageForm.php
@@ -23,10 +23,14 @@ public function getFormID() {
public function buildForm(array $form, array &$form_state) {
$types = array();
// @todo Use \Drupal::service() to get a list of FlagType plugins.
- // print_r(\Drupal::service('plugin.manager.flag.flagtype')->getDefinitions());
- foreach (flag_fetch_definition() as $type => $info) {
- $types[$type] = $info['title'] . '' . $info['description'] . '
';
+ $plugins = \Drupal::service('plugin.manager.flag.flagtype')->getDefinitions();
+
+ foreach ($plugins as $type => $plugin) {
+ $class = $plugin['class'];
+ foreach ($class::entityTypes() as $entityID => $info) {
+ $types[$entityID] = $info['title'] . '' . $info['description'] . '
';
+ }
}
$form['type'] = array(
diff --git a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
index 0a76b88..ae1a48e 100644
--- a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
@@ -25,6 +25,15 @@ class CommentFlagType extends EntityFlagType {
public $access_author;
+ public static function entityTypes() {
+ return array(
+ 'comment' => array(
+ 'title' => t('Comments'),
+ 'description' => t('Comments are responses to node content.'),
+ ),
+ );
+ }
+
public function options() {
$options = parent::options();
$options += array(
diff --git a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
index 1900a91..92dc5fc 100644
--- a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
@@ -33,6 +33,18 @@ class EntityFlagType extends FlagTypeBase {
public $show_contextual_link;
+ public static function entityTypes() {
+ $entity_types = array();
+ foreach (entity_get_info() as $entity_id => $entity_info) {
+ $entity_types[$entity_id] = array(
+ 'title' => $entity_info['label'],
+ 'description' => t('@entity-type entity', array('@entity-type' => $entity_info['label'])),
+ );
+ }
+
+ return $entity_types;
+ }
+
function options() {
$options = parent::options();
$options += array(
diff --git a/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php b/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
index a238d69..46851c4 100644
--- a/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
+++ b/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
@@ -8,7 +8,7 @@
namespace Drupal\flag\Plugin\Flag;
-use Drupal\core\Plugin\PluginBase;
+use Drupal\Component\Plugin\PluginBase;
/**
* Class FlagTypeBase
@@ -19,7 +19,7 @@
* title = @Translation("Flag Type Base")
* )
*/
-class FlagTypeBase extends PluginBase {
+abstract class FlagTypeBase extends PluginBase {
/**
* {@inheritdoc}
@@ -29,8 +29,8 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
- public funciton flag() {
-
+ public static function entityTypes() {
+ return array();
}
/**
diff --git a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
index 2a27da9..adb473c 100644
--- a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
@@ -25,6 +25,15 @@ class NodeFlagType extends EntityFlagType {
public $access_author;
+ public static function entityTypes() {
+ return array(
+ 'node' => array(
+ 'title' => t('Nodes'),
+ 'description' => t("Nodes are a Drupal site's primary content."),
+ ),
+ );
+ }
+
public function options() {
$options = parent::options();
// Use own display settings in the meanwhile.
diff --git a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
index 5ff0285..4495c08 100644
--- a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
@@ -25,6 +25,15 @@ class UserFlagType extends FlagTypeBase {
public $show_on_profile;
+ public static function entityTypes() {
+ return array(
+ 'user' => array(
+ 'title' => t('Users'),
+ 'description' => t('Users who have created accounts on your site.'),
+ ),
+ );
+ }
+
function options() {
$options = parent::options();
$options += array(
From db9e697c4c3fdf4ba989885c47d2daddd45443ea Mon Sep 17 00:00:00 2001
From: Tess
Date: Tue, 26 Nov 2013 23:18:09 -0600
Subject: [PATCH 350/629] Added initial work on the new add form.
---
flag.services.yml | 2 +-
lib/Drupal/flag/ActionLinkPluginManager.php | 9 ++++
lib/Drupal/flag/FlagTypePluginManager.php | 10 ++++
lib/Drupal/flag/Form/FlagAddForm.php | 1 +
lib/Drupal/flag/Form/FlagAddPageForm.php | 50 ++++++++++++++++++-
.../flag/Plugin/Derivative/EntityFlagType.php | 31 ++++++++++++
.../flag/Plugin/Flag/EntityFlagType.php | 10 +++-
lib/Drupal/flag/Plugin/Flag/UserFlagType.php | 3 +-
8 files changed, 111 insertions(+), 5 deletions(-)
create mode 100644 lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
diff --git a/flag.services.yml b/flag.services.yml
index 554fa2b..f144eed 100644
--- a/flag.services.yml
+++ b/flag.services.yml
@@ -2,6 +2,6 @@ services:
plugin.manager.flag.flagtype:
class: Drupal\flag\FlagTypePluginManager
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
- plugin.manager.action_link:
+ plugin.manager.flag.linktype:
class: Drupal\flag\ActionLinkPluginManager
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
diff --git a/lib/Drupal/flag/ActionLinkPluginManager.php b/lib/Drupal/flag/ActionLinkPluginManager.php
index 81ee91e..1841988 100644
--- a/lib/Drupal/flag/ActionLinkPluginManager.php
+++ b/lib/Drupal/flag/ActionLinkPluginManager.php
@@ -26,4 +26,13 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
$this->setCacheBackend($cache_backend, $language_manager, 'flag_link_type_info');
}
+ public function getAllLinkTypes() {
+ $linkTypes = array();
+ foreach($this->getDefinitions() as $pluginID => $pluginDef) {
+ $linkTypes[$pluginID] = t($pluginDef['label']);
+ }
+
+ return $linkTypes;
+ }
+
}
diff --git a/lib/Drupal/flag/FlagTypePluginManager.php b/lib/Drupal/flag/FlagTypePluginManager.php
index 2b21305..ed5c650 100644
--- a/lib/Drupal/flag/FlagTypePluginManager.php
+++ b/lib/Drupal/flag/FlagTypePluginManager.php
@@ -35,4 +35,14 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
$this->setCacheBackend($cache_backend, $language_manager, 'flag');
}
+ public function getAllFlagTypes() {
+ $flagTypes = array();
+
+ foreach ($this->getDefinitions() as $pluginID => $pluginDef) {
+ $flagTypes[$pluginID] = t($pluginDef['title']);
+ }
+
+ return $flagTypes;
+ }
+
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Form/FlagAddForm.php b/lib/Drupal/flag/Form/FlagAddForm.php
index 218a738..4d59a15 100644
--- a/lib/Drupal/flag/Form/FlagAddForm.php
+++ b/lib/Drupal/flag/Form/FlagAddForm.php
@@ -14,6 +14,7 @@
class FlagAddForm extends EntityFormController {
public function buildForm(array $form, array &$form_state, $entity_type = NULL) {
+ //@todo Check all non-form_* params with check_plain().
$form = parent::buildForm($form, $form_state);
$flag = $this->entity; //\Drupal\flag\Handlers\AbstractFlag::factory_by_entity_type($entity_type);
diff --git a/lib/Drupal/flag/Form/FlagAddPageForm.php b/lib/Drupal/flag/Form/FlagAddPageForm.php
index 53aad74..8aea581 100644
--- a/lib/Drupal/flag/Form/FlagAddPageForm.php
+++ b/lib/Drupal/flag/Form/FlagAddPageForm.php
@@ -21,11 +21,59 @@ public function getFormID() {
}
public function buildForm(array $form, array &$form_state) {
+
+ $form['flag_basic_info'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Flag basic info'),
+ '#collapsable' => FALSE,
+ '#weight' => -10,
+ );
+ $form['flag_basic_info']['label'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Label'),
+ '#description' => t('A short, descriptive title for this flag. It will be used in administrative interfaces to refer to this flag, and in page titles and menu items of some views this module provides (theses are customizable, though). Some examples could be Bookmarks, Favorites, or Offensive.', array('@insite-views-url' => url('admin/structure/views'))),
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#weight' => -3,
+ );
+ $form['flag_basic_info']['id'] = array(
+ '#type' => 'machine_name',
+ '#title' => t('Machine name'),
+ '#description' => t('The machine-name for this flag. It may be up to 32 characters long and may only contain lowercase letters, underscores, and numbers. It will be used in URLs and in all API calls.'),
+ '#weight' => -2,
+ '#machine_name' => array(
+ 'exists' => 'flag_load_by_id',
+ 'source' => array('flag_basic_info', 'label'),
+ ),
+ );
+
+ $form['flag_type_info'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Type and Action'),
+ '#attributes' => array(
+ 'class' => array('container-inline'),
+ ),
+ );
+
+ $form['flag_type_info']['flag_entity_type'] = array(
+ '#type' => 'select',
+ '#title' => t('Flag'),
+ '#options' => \Drupal::service('plugin.manager.flag.flagtype')->getAllFlagTypes(),
+ );
+
+ $form['flag_type_info']['flag_link_type'] = array(
+ '#type' => 'select',
+ '#title' => t('using'),
+ '#options' => \Drupal::service('plugin.manager.flag.linktype')->getAllLinkTypes(),
+ );
+
$types = array();
// @todo Use \Drupal::service() to get a list of FlagType plugins.
$plugins = \Drupal::service('plugin.manager.flag.flagtype')->getDefinitions();
+// print_r($plugins);
+/*
foreach ($plugins as $type => $plugin) {
$class = $plugin['class'];
foreach ($class::entityTypes() as $entityID => $info) {
@@ -41,7 +89,7 @@ public function buildForm(array $form, array &$form_state) {
'#required' => TRUE,
'#options' => $types,
);
-
+*/
$form['actions'] = array(
'#type' => 'actions',
);
diff --git a/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php b/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
new file mode 100644
index 0000000..b6269c9
--- /dev/null
+++ b/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
@@ -0,0 +1,31 @@
+ $entity_info) {
+ $derivatives[$entity_id] = array(
+ 'title' => $entity_id . " flag type",
+ 'entity' => $entity_id,
+ ) + $base_plugin_def;
+ }
+
+ return $derivatives;
+ }
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
index 92dc5fc..633efea 100644
--- a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
@@ -18,7 +18,8 @@
*
* @FlagType(
* id = "flagtype_entity",
- * title = @Translation("Flag Type Entity")
+ * title = @Translation("Flag Type Entity"),
+ * derivative = "Drupal\flag\Plugin\Derivative\EntityFlagType"
* )
*/
class EntityFlagType extends FlagTypeBase {
@@ -33,7 +34,12 @@ class EntityFlagType extends FlagTypeBase {
public $show_contextual_link;
- public static function entityTypes() {
+ public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
+ array_push($this->types, $plugin_definition['entity']);
+ parent::__construct($configuration, $plugin_id, $plugin_definition);
+ }
+
+ public static function entityTypes() {
$entity_types = array();
foreach (entity_get_info() as $entity_id => $entity_info) {
$entity_types[$entity_id] = array(
diff --git a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
index 4495c08..62f2ae7 100644
--- a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
@@ -16,7 +16,8 @@
*
* @FlagType(
* id = "flagtype_user",
- * title = @Translation("Flag Type User")
+ * title = @Translation("Flag Type User"),
+ * entity = "user"
* )
*/
class UserFlagType extends FlagTypeBase {
From cb9c0939a8286d9793a5df68952eba967ec3769d Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 8 Dec 2013 14:16:39 -0600
Subject: [PATCH 351/629] Removed .idea folder from repo, added .gitignore
file.
---
.gitignore | 1 +
.idea/.name | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)
create mode 100644 .gitignore
delete mode 100644 .idea/.name
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..485dee6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.idea
diff --git a/.idea/.name b/.idea/.name
deleted file mode 100644
index 551c90f..0000000
--- a/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-flag
\ No newline at end of file
From 5ac5f7061baaef74560353d4aa7e629427a8653a Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 8 Dec 2013 14:54:20 -0600
Subject: [PATCH 352/629] Added missing use statement to FlaggingInterface.php
---
lib/Drupal/flag/FlaggingInterface.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/Drupal/flag/FlaggingInterface.php b/lib/Drupal/flag/FlaggingInterface.php
index c75bd44..e75dc72 100644
--- a/lib/Drupal/flag/FlaggingInterface.php
+++ b/lib/Drupal/flag/FlaggingInterface.php
@@ -8,6 +8,7 @@
namespace Drupal\flag;
+use Drupal\Core\Entity\ContentEntityInterface;
interface FlaggingInterface extends ContentEntityInterface {
From 8dddc0d893ad7e08005fc55fe10d2f92501d97f3 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 8 Dec 2013 17:12:23 -0600
Subject: [PATCH 353/629] Moved FlagTypeBase and FlagTypeBroken out of the
plugin directory. Changed plugin titles.
---
lib/Drupal/flag/{Plugin/Flag => }/BrokenFlagType.php | 0
lib/Drupal/flag/{Plugin/Flag => }/FlagTypeBase.php | 0
lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php | 2 +-
lib/Drupal/flag/Plugin/Flag/CommentFlagType.php | 2 +-
lib/Drupal/flag/Plugin/Flag/NodeFlagType.php | 2 +-
lib/Drupal/flag/Plugin/Flag/UserFlagType.php | 2 +-
6 files changed, 4 insertions(+), 4 deletions(-)
rename lib/Drupal/flag/{Plugin/Flag => }/BrokenFlagType.php (100%)
rename lib/Drupal/flag/{Plugin/Flag => }/FlagTypeBase.php (100%)
diff --git a/lib/Drupal/flag/Plugin/Flag/BrokenFlagType.php b/lib/Drupal/flag/BrokenFlagType.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/Flag/BrokenFlagType.php
rename to lib/Drupal/flag/BrokenFlagType.php
diff --git a/lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php b/lib/Drupal/flag/FlagTypeBase.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/Flag/FlagTypeBase.php
rename to lib/Drupal/flag/FlagTypeBase.php
diff --git a/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php b/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
index b6269c9..e5d4679 100644
--- a/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
+++ b/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
@@ -21,7 +21,7 @@ public function getDerivativeDefinitions(array $base_plugin_def) {
$derivatives = array();
foreach (entity_get_info() as $entity_id => $entity_info) {
$derivatives[$entity_id] = array(
- 'title' => $entity_id . " flag type",
+ 'title' => $entity_id,
'entity' => $entity_id,
) + $base_plugin_def;
}
diff --git a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
index ae1a48e..5e4ee65 100644
--- a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
@@ -18,7 +18,7 @@
*
* @FlagType(
* id = "flagtype_comment",
- * title = @Translation("Flag Type Comment")
+ * title = @Translation("Comment")
* )
*/
class CommentFlagType extends EntityFlagType {
diff --git a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
index adb473c..a0d15c8 100644
--- a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
@@ -18,7 +18,7 @@
*
* @FlagType(
* id = "flagtype_node",
- * title = @Translation("Flag Type Node")
+ * title = @Translation("Content")
* )
*/
class NodeFlagType extends EntityFlagType {
diff --git a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
index 62f2ae7..8a6c354 100644
--- a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
@@ -16,7 +16,7 @@
*
* @FlagType(
* id = "flagtype_user",
- * title = @Translation("Flag Type User"),
+ * title = @Translation("User"),
* entity = "user"
* )
*/
From a6ca5848ea8a55db1bced25022edc94e49e8410a Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 8 Dec 2013 17:14:46 -0600
Subject: [PATCH 354/629] Changed namespace for BrokenFlagType and
FlagTypeBase.
---
lib/Drupal/flag/BrokenFlagType.php | 2 +-
lib/Drupal/flag/FlagTypeBase.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/Drupal/flag/BrokenFlagType.php b/lib/Drupal/flag/BrokenFlagType.php
index d220e59..86cbba9 100644
--- a/lib/Drupal/flag/BrokenFlagType.php
+++ b/lib/Drupal/flag/BrokenFlagType.php
@@ -6,7 +6,7 @@
* Time: 8:34 PM
*/
-namespace Drupal\flag\Plugin\Flag;
+namespace Drupal\flag;
use Drupal\flag\Plugin\Flag\FlagTypeBase;
diff --git a/lib/Drupal/flag/FlagTypeBase.php b/lib/Drupal/flag/FlagTypeBase.php
index 46851c4..ac41efd 100644
--- a/lib/Drupal/flag/FlagTypeBase.php
+++ b/lib/Drupal/flag/FlagTypeBase.php
@@ -6,7 +6,7 @@
* Time: 12:56 PM
*/
-namespace Drupal\flag\Plugin\Flag;
+namespace Drupal\flag;
use Drupal\Component\Plugin\PluginBase;
From 16a45210987a2dbb7bfd8ff3d65901114a9b62ba Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 8 Dec 2013 22:34:13 -0600
Subject: [PATCH 355/629] Add form improvements, started using TempStore API.
---
lib/Drupal/flag/Form/FlagAddForm.php | 38 +++++-------------------
lib/Drupal/flag/Form/FlagAddPageForm.php | 36 +++++++++++-----------
2 files changed, 24 insertions(+), 50 deletions(-)
diff --git a/lib/Drupal/flag/Form/FlagAddForm.php b/lib/Drupal/flag/Form/FlagAddForm.php
index 4d59a15..75394b9 100644
--- a/lib/Drupal/flag/Form/FlagAddForm.php
+++ b/lib/Drupal/flag/Form/FlagAddForm.php
@@ -17,6 +17,9 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
//@todo Check all non-form_* params with check_plain().
$form = parent::buildForm($form, $form_state);
+ $tempstore = \Drupal::service('user.tempstore')->get('flag');
+ $step1_form = $tempstore->get('FlagAddPage');
+
$flag = $this->entity; //\Drupal\flag\Handlers\AbstractFlag::factory_by_entity_type($entity_type);
// Mark the flag as new.
@@ -31,7 +34,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
- '#default_value' => $flag->label(),
+ '#default_value' => $step1_form['label'],
'#description' => t('A short, descriptive title for this flag. It will be used in administrative interfaces to refer to this flag, and in page titles and menu items of some views this module provides (theses are customizable, though). Some examples could be Bookmarks, Favorites, or Offensive.', array('@insite-views-url' => url('admin/structure/views'))),
'#maxlength' => 255,
'#required' => TRUE,
@@ -41,7 +44,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
$form['id'] = array(
'#type' => 'machine_name',
'#title' => t('Machine name'),
- '#default_value' => $flag->id(),
+ '#default_value' => $step1_form['id'],
'#description' => t('The machine-name for this flag. It may be up to 32 characters long and may only contain lowercase letters, underscores, and numbers. It will be used in URLs and in all API calls.'),
'#weight' => -2,
'#machine_name' => array(
@@ -57,15 +60,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'#description' => t('If checked, flag is considered "global" and each entity is either flagged or not. If unchecked, each user has individual flags on entities.'),
'#weight' => -1,
);
- // Don't allow the 'global' checkbox to be changed when flaggings exist:
- // there are too many unpleasant consequences in either direction.
- // @todo: Allow this, but with a confirmation form, assuming anyone actually
- // needs this feature.
-/* if (!empty($flag->id) && flag_get_flag_counts($flag->id)) {
- $form['global']['#disabled'] = TRUE;
- $form['global']['#description'] .= '
' . t('This setting cannot be changed when flaggings exist for this flag.');
- }
-*/
+
$form['messages'] = array(
'#type' => 'fieldset',
'#title' => t('Messages'),
@@ -114,26 +109,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'#default_value' => $flag->unflag_message,
'#description' => t('Message displayed after content has been unflagged. If JavaScript is enabled, it will be displayed below the link. If not, it will be displayed in the message area.'),
);
-/*
- $form['messages']['tokens_help'] = array(
- '#title' => t('Token replacement'),
- '#type' => 'fieldset',
- '#description' =>
- '' . t('The above six texts may contain any of the tokens listed below. For example, "Flag link text" could be entered as:') . '
' .
- theme('item_list', array(
- 'items' => array(
- t('Add <em>[node:title]</em> to your favorites'),
- t('Add this [node:type] to your favorites'),
- t('Vote for this proposal ([node:flag-vote-count] people have already done so)'),
- ),
- 'attributes' => array('class' => 'token-examples'),
- )) .
- '' . t('These tokens will be replaced with the appropriate fields from the node (or user, or comment).') . '
' .
- theme('flag_tokens_browser', array('types' => $flag->get_labels_token_types())),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
-*/
+
$form['access'] = array(
'#type' => 'fieldset',
'#title' => t('Flag access'),
diff --git a/lib/Drupal/flag/Form/FlagAddPageForm.php b/lib/Drupal/flag/Form/FlagAddPageForm.php
index 8aea581..3a5a897 100644
--- a/lib/Drupal/flag/Form/FlagAddPageForm.php
+++ b/lib/Drupal/flag/Form/FlagAddPageForm.php
@@ -67,29 +67,23 @@ public function buildForm(array $form, array &$form_state) {
'#options' => \Drupal::service('plugin.manager.flag.linktype')->getAllLinkTypes(),
);
+ $role_options = array(0 => 'All users');
+ foreach (user_roles() as $rid => $role_info) {
+ $role_options[$rid] = $role_info->label;
+ }
+
+ $form['flag_type_info']['flag_role'] = array(
+ '#type' => 'select',
+ '#title' => t('for'),
+ '#options' => $role_options,
+ '#default' => 0,
+ );
+
$types = array();
// @todo Use \Drupal::service() to get a list of FlagType plugins.
$plugins = \Drupal::service('plugin.manager.flag.flagtype')->getDefinitions();
-// print_r($plugins);
-/*
- foreach ($plugins as $type => $plugin) {
- $class = $plugin['class'];
- foreach ($class::entityTypes() as $entityID => $info) {
- $types[$entityID] = $info['title'] . '' . $info['description'] . '
';
- }
- }
-
- $form['type'] = array(
- '#type' => 'radios',
- '#title' => t('Flag type'),
- '#default_value' => 'node',
- '#description' => t('The type of object this flag will affect. This cannot be changed once the flag is created.'),
- '#required' => TRUE,
- '#options' => $types,
- );
-*/
$form['actions'] = array(
'#type' => 'actions',
);
@@ -110,6 +104,10 @@ public function validateForm(array &$form, array &$form_state) {
}
public function submitForm(array &$form, array &$form_state) {
- $form_state['redirect'] = FLAG_ADMIN_PATH . '/add/' . $form_state['values']['type'];
+ $form_state['redirect'] = FLAG_ADMIN_PATH . '/add/' .
+ $form_state['values']['flag_entity_type'];
+
+ $tempstore = \Drupal::service('user.tempstore')->get('flag');
+ $tempstore->set('FlagAddPage', $form_state['values']);
}
}
\ No newline at end of file
From 34252809d85e0f8722e3a22a89de50fe25ddd55f Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 15 Dec 2013 23:21:53 -0600
Subject: [PATCH 356/629] Fixed a lot of issues with the plugins and add forms.
---
lib/Drupal/flag/ActionLinkTypeBase.php | 60 +++++++++++++--
.../flag/ActionLinkTypePluginInterface.php | 4 +
lib/Drupal/flag/Annotation/FlagType.php | 7 ++
lib/Drupal/flag/BrokenFlagType.php | 5 --
lib/Drupal/flag/FlagTypeBase.php | 74 +++++++++++++------
lib/Drupal/flag/FlagTypePluginInterface.php | 20 +++++
lib/Drupal/flag/Form/FlagAddForm.php | 48 +++++++++---
lib/Drupal/flag/Form/FlagAddPageForm.php | 2 +
lib/Drupal/flag/Plugin/ActionLink/Reload.php | 5 ++
.../flag/Plugin/Derivative/EntityFlagType.php | 2 +-
.../flag/Plugin/Flag/CommentFlagType.php | 22 ++----
.../flag/Plugin/Flag/EntityFlagType.php | 38 ++--------
lib/Drupal/flag/Plugin/Flag/NodeFlagType.php | 26 +++----
lib/Drupal/flag/Plugin/Flag/UserFlagType.php | 21 ++----
14 files changed, 215 insertions(+), 119 deletions(-)
create mode 100644 lib/Drupal/flag/FlagTypePluginInterface.php
diff --git a/lib/Drupal/flag/ActionLinkTypeBase.php b/lib/Drupal/flag/ActionLinkTypeBase.php
index 4bde528..e9ff196 100644
--- a/lib/Drupal/flag/ActionLinkTypeBase.php
+++ b/lib/Drupal/flag/ActionLinkTypeBase.php
@@ -8,10 +8,14 @@
namespace Drupal\flag;
-use Drupal\core\Plugin\PluginBase;
-use Drupal\action_link\ActionLinkTypePluginInterface;
+use Drupal\Component\Plugin\PluginBase;
+use Drupal\flag\ActionLinkTypePluginInterface;
-class ActionLinkTypeBase extends PluginBase implements ActionLinkTypePluginInterface {
+/**
+ * Class ActionLinkTypeBase
+ * @package Drupal\flag
+ */
+abstract class ActionLinkTypeBase extends PluginBase implements ActionLinkTypePluginInterface {
/**
* @param array $configuration
@@ -24,30 +28,74 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
$this->setConfiguration($configuration);
}
+ /**
+ * @return string
+ */
public function buildLink() {
return "";
}
+ /**
+ * Provides a form array for the action link plugin's settings form.
+ * Derived classes will want to override this method.
+ *
+ * @param array $form
+ * @param array $form_state
+ * @return array
+ * The configuration form array.
+ */
public function buildConfigurationForm(array $form, array &$form_state) {
return $form;
}
+ /**
+ * Processes the action link setting form submit. Derived classes will want to
+ * override this method.
+ *
+ * @param array $form
+ * @param array $form_state
+ */
public function submitConfigurationForm(array &$form, array &$form_state) {
-
+ // Override this.
}
+ /**
+ * Validates the action link setting form. Derived classes will want to override
+ * this method.
+ *
+ * @param array $form
+ * @param array $form_state
+ */
public function validateConfigurationForm(array &$form, array &$form_state) {
-
+ // Override this.
}
+ /**
+ * Provides the action link plugin's default configuration. Derived classes
+ * will want to override this method.
+ *
+ * @return array
+ * The plugin configuration array.
+ */
public function defaultConfiguration() {
return array();
}
+ /**
+ * Provides the action link plugin's current configuraiton array.
+ *
+ * @return array
+ * An array containing the plugin's currnt configuration.
+ */
public function getConfiguration() {
- return $configuration;
+ return $this->configuration;
}
+ /**
+ * Replaces the plugin's current configuration with that given in the parameter.
+ * @param array $configuration
+ * An array containing the plugin's configuration.
+ */
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
diff --git a/lib/Drupal/flag/ActionLinkTypePluginInterface.php b/lib/Drupal/flag/ActionLinkTypePluginInterface.php
index e0d746f..ae95739 100644
--- a/lib/Drupal/flag/ActionLinkTypePluginInterface.php
+++ b/lib/Drupal/flag/ActionLinkTypePluginInterface.php
@@ -11,6 +11,10 @@
use Drupal\Core\Plugin\PluginFormInterface;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
+/**
+ * Interface ActionLinkTypePluginInterface
+ * @package Drupal\flag
+ */
interface ActionLinkTypePluginInterface extends PluginFormInterface, ConfigurablePluginInterface {
public function buildLink();
diff --git a/lib/Drupal/flag/Annotation/FlagType.php b/lib/Drupal/flag/Annotation/FlagType.php
index a1cba41..8bc9a8e 100644
--- a/lib/Drupal/flag/Annotation/FlagType.php
+++ b/lib/Drupal/flag/Annotation/FlagType.php
@@ -34,4 +34,11 @@ class FlagType extends Plugin {
*/
public $title;
+ /**
+ * The entity type the flag type supports.
+ *
+ * @var string
+ */
+ public $entity_type;
+
}
diff --git a/lib/Drupal/flag/BrokenFlagType.php b/lib/Drupal/flag/BrokenFlagType.php
index 86cbba9..fa991bf 100644
--- a/lib/Drupal/flag/BrokenFlagType.php
+++ b/lib/Drupal/flag/BrokenFlagType.php
@@ -15,11 +15,6 @@
* @package Drupal\flag\Plugin\Flag
*
* A dummy Flag Type to be used where the real implementation can't be found.
- *
- * @FlagType(
- * id = "flagtype_broken",
- * title = @Translation("Flag Type Broken")
- * )
*/
class BrokenFlagType extends FlagTypeBase {
diff --git a/lib/Drupal/flag/FlagTypeBase.php b/lib/Drupal/flag/FlagTypeBase.php
index ac41efd..2bf5473 100644
--- a/lib/Drupal/flag/FlagTypeBase.php
+++ b/lib/Drupal/flag/FlagTypeBase.php
@@ -8,59 +8,87 @@
namespace Drupal\flag;
+use Drupal\flag\FlagTypePluginInterface;
use Drupal\Component\Plugin\PluginBase;
+use Drupal\Core\Plugin\PluginFormInterface;
/**
* Class FlagTypeBase
* @package Drupal\flag\Plugin\Flag
- *
- * @FlagType(
- * id = "flagtype_base",
- * title = @Translation("Flag Type Base")
- * )
*/
-abstract class FlagTypeBase extends PluginBase {
+abstract class FlagTypeBase extends PluginBase implements FlagTypePluginInterface{
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
- $configuration += $this->options();
+ $configuration += $this->defaultConfiguration();
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
- public static function entityTypes() {
+ /**
+ * Provides the default configuration values for the flag type.
+ *
+ * @return array
+ */
+ public function defaultConfiguration() {
return array();
}
/**
- * Declares the options this flag supports, and their default values.
+ * Returns this flag type plugin's configuration array.
*
- * Derived classes should want to override this.
+ * @return array
+ */
+ public function getConfiguration() {
+ return $this->configuration;
+ }
+
+ /**
+ * Replaces the plugin's configurations with those given in the parameter.
*
- * @todo Rename to defaultConfiguration()?
+ * @param array $configuration
*/
- public function options() {
- return array();
+ public function setConfiguration(array $configuration) {
+ $this->configuration = $configuration;
}
/**
- * Provides a form for setting options.
+ * Provides a form for this action link plugin settings.
*
- * Derived classes should want to override this.
+ * The form provided by this method is displayed by the FlagAddForm when creating
+ * or editing the Flag. Derived classes should want to override this.
+ *
+ * @param array $form
+ * @param array $form_state
+ * @return array
+ * The form array
+ * @see \Drupal\flag\Form\FlagAddForm
*/
public function buildConfigurationForm(array $form, array &$form_state) {
return $form;
}
-/**
- * Handles the form submit for this plugin.
- *
- * @param array $form
- * @param array $form_state
- */
-public function submitConfigurationForm(array &$form, array &$form_state) {
- // Override this
+ /**
+ * Handles the form submit for this action link plugin.
+ *
+ * Derived classes will want to override this.
+ *
+ * @param array $form
+ * @param array $form_state
+ */
+ public function submitConfigurationForm(array &$form, array &$form_state) {
+ // Override this.
+ }
+
+ /**
+ * Handles the validation for the action link plugin settings form.
+ *
+ * @param array $form
+ * @param array $form_state
+ */
+ public function validateConfigurationForm(array &$form, array &$form_state) {
+ // Override this.
}
/**
diff --git a/lib/Drupal/flag/FlagTypePluginInterface.php b/lib/Drupal/flag/FlagTypePluginInterface.php
new file mode 100644
index 0000000..2436386
--- /dev/null
+++ b/lib/Drupal/flag/FlagTypePluginInterface.php
@@ -0,0 +1,20 @@
+ 10,
);
- $bundles = entity_get_bundles($entity_type);
+ $flag_type_plugin = \Drupal::service('plugin.manager.flag.flagtype')->createInstance($step1_form['flag_entity_type']);
+ $flag_type_def = $flag_type_plugin->getPluginDefinition();
+
+ $bundles = entity_get_bundles($flag_type_def['entity_type']);
$entity_bundles = array();
foreach ($bundles as $bundle_id => $bundle_row) {
$entity_bundles[$bundle_id] = $bundle_row['label'];
@@ -156,7 +159,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'unflag' => array(DRUPAL_AUTHENTICATED_RID),
);
}
-*/
+
$form['access']['roles'] = array(
'#title' => t('Roles that may use this flag'),
'#description' => t('Users may only unflag content if they have access to flag the content initially. Checking authenticated user will allow access for all logged-in users.'),
@@ -174,20 +177,37 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
else {
$form['access']['roles']['#description'] .= ' ' . t('Anonymous users may flag content if the Session API module is installed.');
}
+*/
+ foreach (user_roles() as $rid => $role_info) {
+ $access_roles_default_value = array();
+ if ($rid == $step1_form['flag_role'] || $step1_form['flag_role'] == '0') {
+ $access_roles_default_value = array('flag', 'unflag');
+ }
+ $form['access']['roles'][$rid] = array(
+ '#type' => 'checkboxes',
+ '#options' => array('flag' => t('Flag'), 'unflag' => t('Unflag')),
+ '#attributes' => array(
+ 'class' => array('container-inline'),
+ ),
+ '#title' => $role_info->label,
+ '#default_value' => $access_roles_default_value,
+ );
+ }
+/*
$form['access']['roles']['flag'] = array(
'#type' => 'checkboxes',
- '#options' => user_roles(!module_exists('session_api')),
+ '#options' => $role_options,
// '#default_value' => $flag->roles['flag'],
'#parents' => array('roles', 'flag'),
);
$form['access']['roles']['unflag'] = array(
'#type' => 'checkboxes',
- '#options' => user_roles(!module_exists('session_api')),
+ '#options' => $role_options,
// '#default_value' => $flag->roles['unflag'],
'#parents' => array('roles', 'unflag'),
);
-
+*/
$form['access']['unflag_denied_text'] = array(
'#type' => 'textfield',
'#title' => t('Unflag not allowed text'),
@@ -206,13 +226,14 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
// '#after_build' => array('flag_link_type_options_states'),
);
+ $form = $flag_type_plugin->buildConfigurationForm($form, $form_state);
+
$form['display']['link_type'] = array(
'#type' => 'radios',
'#title' => t('Link type'),
- '#options' => _flag_link_type_options(),
- // @todo: Move flag_check_link_types into controller?
+ '#options' => \Drupal::service('plugin.manager.flag.linktype')->getAllLinkTypes(),
// '#after_build' => array('flag_check_link_types'),
- '#default_value' => $flag->link_type,
+ '#default_value' => $step1_form['flag_link_type'],
// Give this a high weight so additions by the flag classes for entity-
// specific options go above.
'#weight' => 18,
@@ -225,10 +246,13 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
);
// Add the descriptions to each ratio button element. These attach to the
// elements when FormAPI expands them.
- foreach (_flag_link_type_descriptions() as $key => $description) {
- $form['display']['link_type'][$key]['#description'] = $description;
+ $action_link_plugin_defs = \Drupal::service('plugin.manager.flag.linktype')->getDefinitions();
+ foreach ($action_link_plugin_defs as $key => $info) {
+ $form['display']['link_type'][$key]['#description'] = $info['description'];
}
+
+/*
$form['display']['link_options_intro'] = array(
// This is a hack to allow a markup element to use FormAPI states.
// @see http://www.bywombats.com/blog/06-25-2011/using-containers-states-enabled-markup-form-elements
@@ -269,6 +293,10 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
// Allow the flag handler to make additions and changes to the form.
// Note that the flag_broken handler will completely empty the form array!
// $flag->options_form($form);
+*/
+ $action_link_plugin = \Drupal::service('plugin.manager.flag.linktype')->createInstance($step1_form['flag_link_type']);
+
+ $form = $action_link_plugin->buildConfigurationForm($form, $form_state);
return $form;
}
diff --git a/lib/Drupal/flag/Form/FlagAddPageForm.php b/lib/Drupal/flag/Form/FlagAddPageForm.php
index 3a5a897..cd9876a 100644
--- a/lib/Drupal/flag/Form/FlagAddPageForm.php
+++ b/lib/Drupal/flag/Form/FlagAddPageForm.php
@@ -97,10 +97,12 @@ public function buildForm(array $form, array &$form_state) {
}
public function validateForm(array &$form, array &$form_state) {
+ /*
$flag = AbstractFlag::factory_by_entity_type($form_state['values']['type']);
if (get_class($flag) == 'BrokenFlag') {
form_set_error('type', t("This flag type, %type, isn't valid.", array('%type' => $form_state['values']['type'])));
}
+ */
}
public function submitForm(array &$form, array &$form_state) {
diff --git a/lib/Drupal/flag/Plugin/ActionLink/Reload.php b/lib/Drupal/flag/Plugin/ActionLink/Reload.php
index bb9619e..1ab3889 100644
--- a/lib/Drupal/flag/Plugin/ActionLink/Reload.php
+++ b/lib/Drupal/flag/Plugin/ActionLink/Reload.php
@@ -6,6 +6,8 @@
* Time: 8:21 PM
*/
+namespace Drupal\flag\Plugin\ActionLink;
+
use Drupal\flag\ActionLinkTypeBase;
/**
@@ -19,6 +21,9 @@
*/
class Reload extends ActionLinkTypeBase {
+ /**
+ * @return string
+ */
public function buildLink() {
return "/flag/";
}
diff --git a/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php b/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
index e5d4679..d1d196b 100644
--- a/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
+++ b/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
@@ -22,7 +22,7 @@ public function getDerivativeDefinitions(array $base_plugin_def) {
foreach (entity_get_info() as $entity_id => $entity_info) {
$derivatives[$entity_id] = array(
'title' => $entity_id,
- 'entity' => $entity_id,
+ 'entity_type' => $entity_id,
) + $base_plugin_def;
}
diff --git a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
index 5e4ee65..5cbfc83 100644
--- a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
@@ -18,24 +18,16 @@
*
* @FlagType(
* id = "flagtype_comment",
- * title = @Translation("Comment")
+ * title = @Translation("Comment"),
+ * entity_type = "comment"
* )
*/
class CommentFlagType extends EntityFlagType {
public $access_author;
- public static function entityTypes() {
- return array(
- 'comment' => array(
- 'title' => t('Comments'),
- 'description' => t('Comments are responses to node content.'),
- ),
- );
- }
-
- public function options() {
- $options = parent::options();
+ public function defaultConfiguration() {
+ $options = parent::defaultConfiguration();
$options += array(
'access_author' => '',
);
@@ -45,8 +37,8 @@ public function options() {
/**
* Options form extras for comment flags.
*/
- public function options_form(&$form) {
- parent::options_form($form);
+ public function buildConfigurationForm(array $form, array &$form_state) {
+ parent::buildConfigurationForm($form, $form_state);
$form['access']['access_author'] = array(
'#type' => 'radios',
@@ -61,6 +53,8 @@ public function options_form(&$form) {
'#default_value' => $this->access_author,
'#description' => t("Restrict access to this flag based on the user's ownership of the content. Users must also have access to the flag through the role settings."),
);
+
+ return $form;
}
public function type_access_multiple($entity_ids, $account) {
diff --git a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
index 633efea..28d40e7 100644
--- a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
@@ -8,7 +8,7 @@
namespace Drupal\flag\Plugin\Flag;
-use Drupal\flag\Plugin\Flag\FlagTypeBase;
+use Drupal\flag\FlagTypeBase;
/**
* Class EntityFlagType
@@ -35,24 +35,12 @@ class EntityFlagType extends FlagTypeBase {
public $show_contextual_link;
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
- array_push($this->types, $plugin_definition['entity']);
+ array_push($this->types, $plugin_definition['entity_type']);
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
- public static function entityTypes() {
- $entity_types = array();
- foreach (entity_get_info() as $entity_id => $entity_info) {
- $entity_types[$entity_id] = array(
- 'title' => $entity_info['label'],
- 'description' => t('@entity-type entity', array('@entity-type' => $entity_info['label'])),
- );
- }
-
- return $entity_types;
- }
-
- function options() {
- $options = parent::options();
+ public function defaultConfiguration() {
+ $options = parent::defaultConfiguration();
$options += array(
// Output the flag in the entity links.
// This is empty for now and will get overriden for different
@@ -73,20 +61,8 @@ function options() {
/**
* Options form extras for the generic entity flag.
*/
- function options_form(&$form) {
- $bundles = array();
- $bundle_info = entity_get_bundles($this->entity_type);
- foreach ($bundle_info as $bundle_key => $info) {
- $bundles[$bundle_key] = $info['label'];
- }
- $form['access']['types'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Bundles'),
- '#options' => $bundles,
- '#description' => t('Select the bundles that this flag may be used on. Leave blank to allow on all bundles for the entity type.'),
- '#default_value' => $this->types,
- );
-
+ public function buildConfigurationForm(array $form, array &$form_state) {
+ /*
// Add checkboxes to show flag link on each entity view mode.
$options = array();
$defaults = array();
@@ -138,6 +114,8 @@ function options_form(&$form) {
'#access' => module_exists('contextual'),
'#weight' => 10,
);
+ */
+ return $form;
}
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
index a0d15c8..0de1699 100644
--- a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
@@ -18,24 +18,16 @@
*
* @FlagType(
* id = "flagtype_node",
- * title = @Translation("Content")
+ * title = @Translation("Content"),
+ * entity_type = "node"
* )
*/
class NodeFlagType extends EntityFlagType {
public $access_author;
- public static function entityTypes() {
- return array(
- 'node' => array(
- 'title' => t('Nodes'),
- 'description' => t("Nodes are a Drupal site's primary content."),
- ),
- );
- }
-
- public function options() {
- $options = parent::options();
+ public function defaultConfiguration() {
+ $options = parent::defaultConfiguration();
// Use own display settings in the meanwhile.
$options += array(
'i18n' => 0,
@@ -46,8 +38,8 @@ public function options() {
/**
* Options form extras for node flags.
*/
- public function options_form(&$form) {
- parent::options_form($form);
+ public function buildConfigurationForm(array $form, array &$form_state) {
+ parent::buildConfigurationForm($form, $form_state);
$form['access']['access_author'] = array(
'#type' => 'radios',
@@ -69,7 +61,7 @@ public function options_form(&$form) {
'1' => t('Flag translations of content as a group'),
'0' => t('Flag each translation of content separately'),
),
- '#default_value' => $this->i18n,
+ //'#default_value' => $this->i18n,
'#description' => t('Flagging translations as a group effectively allows users to flag the original piece of content regardless of the translation they are viewing. Changing this setting will not update content that has been flagged already.'),
'#access' => module_exists('translation_helpers'),
'#weight' => 5,
@@ -79,7 +71,9 @@ public function options_form(&$form) {
$form['display']['show_on_form'] = array(
'#title' => t('Display checkbox on node edit form'),
'#description' => t('If you elect to have a checkbox on the node edit form, you may specify its initial state in the settings form for each content type.', array('@content-types-url' => url('admin/structure/types'))),
- ) + $form['display']['show_on_form'];
+ );// + $form['display']['show_on_form'];
+
+ return $form;
}
function type_access_multiple($entity_ids, $account) {
diff --git a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
index 8a6c354..62979d4 100644
--- a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
@@ -17,7 +17,7 @@
* @FlagType(
* id = "flagtype_user",
* title = @Translation("User"),
- * entity = "user"
+ * entity_type = "user"
* )
*/
class UserFlagType extends FlagTypeBase {
@@ -26,17 +26,8 @@ class UserFlagType extends FlagTypeBase {
public $show_on_profile;
- public static function entityTypes() {
- return array(
- 'user' => array(
- 'title' => t('Users'),
- 'description' => t('Users who have created accounts on your site.'),
- ),
- );
- }
-
- function options() {
- $options = parent::options();
+ public function defaultConfiguration() {
+ $options = parent::defaultConfiguration();
$options += array(
'show_on_profile' => TRUE,
'access_uid' => '',
@@ -47,8 +38,8 @@ function options() {
/**
* Options form extras for user flags.
*/
- function options_form(&$form) {
- parent::options_form($form);
+ public function buildConfigurationForm(array $form, array &$form_state) {
+ parent::buildConfigurationForm($form, $form_state);
$form['access']['types'] = array(
// A user flag doesn't support node types.
// TODO: Maybe support roles instead of node types.
@@ -69,6 +60,8 @@ function options_form(&$form) {
// Put this above 'show on entity'.
'#weight' => -1,
);
+
+ return $form;
}
function type_access_multiple($entity_ids, $account) {
From fbe65b5e9f258b5a040a505a3d16aa93bdd7f7a6 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 22 Dec 2013 13:05:24 -0600
Subject: [PATCH 357/629] Flag entity and FlagAddForm now save the flag type
and link type plugins.
---
lib/Drupal/flag/Entity/Flag.php | 85 ++++++++++++++++++++++++++--
lib/Drupal/flag/FlagTypeBase.php | 2 +-
lib/Drupal/flag/Form/FlagAddForm.php | 8 +--
3 files changed, 86 insertions(+), 9 deletions(-)
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 8fb2f93..782fa6f 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -9,6 +9,7 @@
namespace Drupal\flag\Entity;
use Drupal\Component\Plugin\DefaultSinglePluginBag;
+use Drupal\Compontent\Plugin\ConfigurablePluginInterface;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Entity\Annotation\EntityType;
@@ -149,12 +150,27 @@ class Flag extends ConfigEntityBase implements FlagInterface {
*/
public $unflag_denied_text = '';
+ /**
+ * The plugin ID of the flag type.
+ *
+ * @var string
+ */
+ protected $flag_type;
+
+ protected $flagTypeBag;
+
+ protected $flagTypeConfig = array();
+
/**
* The link type used by the flag, as defined in hook_flag_link_type_info().
*
* @var string
*/
- public $link_type = 'toggle'; //@todo Convert to plugin
+ protected $link_type;
+
+ protected $linkTypeBag;
+
+ protected $linkTypeConfig = array();
/**
* The weight of the flag.
@@ -163,15 +179,17 @@ class Flag extends ConfigEntityBase implements FlagInterface {
*/
public $weight = 0;
- protected $typesBag;
-
/**
* Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::__construct();
*/
public function __construct(array $values, $entity_type) {
parent::__construct($values, $entity_type);
- $this->typesBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.flagtype'), $this->types, array());
+ $this->flagTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.flagtype'),
+ $this->flag_type, $this->flagTypeConfig);
+
+ $this->linkTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.linktype'),
+ $this->link_type, $this->linkTypeConfig);
}
public function enable() {
@@ -198,4 +216,63 @@ public function isFlagged(AccountInterface $account = NULL) {
}
}
+ /**
+ * Get the flag type plugin for this flag.
+ *
+ * @return FlagTypePluginInterface
+ */
+ public function getFlagTypePlugin() {
+ return $this->flagTypeBag->get($this->flag_type);
+ }
+
+ /**
+ * Set the flag type plugin.
+ *
+ * @param string $pluginID
+ * A string containing the flag type plugin ID.
+ */
+ public function setFlagTypePlugin($pluginID) {
+ $this->flag_type = $pluginID;
+ $this->flagTypeBag->addInstanceId($pluginID);
+ }
+
+ /**
+ * Get the link type plugin for this flag.
+ *
+ * @return LinkTypePluginInterface
+ */
+ public function getLinkTypePlugin() {
+ return $this->linkTypeBag->get($this->link_type);
+ }
+
+ /**
+ * Set the link type plugin.
+ *
+ * @param string $pluginID
+ * A string containing the link type plugin ID.
+ */
+ public function setlinkTypePlugin($pluginID) {
+ $this->link_type = $pluginID;
+ $this->linkTypeBag->addInstanceId($pluginID);
+ }
+
+ /**
+ * @param EntityStorageControllerInterface $storage_controller
+ */
+ public function preSave(EntityStorageControllerInterface $storage_controller) {
+ parent::preSave($storage_controller);
+
+ // Save the Flag Type configuration.
+ $flagTypePlugin = $this->getFlagTypePlugin();
+ if ($flagTypePlugin instanceof ConfigurablePluginInterface) {
+ $this->set('flagTypeConfig', $flagTypePlugin->getConfiguration());
+ }
+
+ // Save the Link Type configuration.
+ $linkTypePlugin = $this->getLinkTypePlugin();
+ if ($linkTypePlugin instanceof ConfigurablePluginInterface) {
+ $this->set('linkTypeConfig', $linkTypePlugin->getConfiguration());
+ }
+ }
+
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/FlagTypeBase.php b/lib/Drupal/flag/FlagTypeBase.php
index 2bf5473..ec2412d 100644
--- a/lib/Drupal/flag/FlagTypeBase.php
+++ b/lib/Drupal/flag/FlagTypeBase.php
@@ -22,8 +22,8 @@ abstract class FlagTypeBase extends PluginBase implements FlagTypePluginInterfac
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
- $configuration += $this->defaultConfiguration();
parent::__construct($configuration, $plugin_id, $plugin_definition);
+ $this->configuration += $this->defaultConfiguration();
}
/**
diff --git a/lib/Drupal/flag/Form/FlagAddForm.php b/lib/Drupal/flag/Form/FlagAddForm.php
index a2d8a19..293028d 100644
--- a/lib/Drupal/flag/Form/FlagAddForm.php
+++ b/lib/Drupal/flag/Form/FlagAddForm.php
@@ -20,13 +20,13 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
$tempstore = \Drupal::service('user.tempstore')->get('flag');
$step1_form = $tempstore->get('FlagAddPage');
- $flag = $this->entity; //\Drupal\flag\Handlers\AbstractFlag::factory_by_entity_type($entity_type);
+ $flag = $this->entity;
+ $flag->setFlagTypePlugin($step1_form['flag_entity_type']);
+ $flag->setLinkTypePlugin($step1_form['flag_link_type']);
// Mark the flag as new.
$flag->is_new = TRUE;
$type_info = flag_fetch_definition($entity_type);
- // drupal_set_title(t('Add new @type flag', array('@type' => $type_info['title'])));
-
$form['#flag'] = $flag;
$form['#flag_name'] = $flag->id;
@@ -117,7 +117,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'#weight' => 10,
);
- $flag_type_plugin = \Drupal::service('plugin.manager.flag.flagtype')->createInstance($step1_form['flag_entity_type']);
+ $flag_type_plugin = $flag->getFlagTypePlugin();
$flag_type_def = $flag_type_plugin->getPluginDefinition();
$bundles = entity_get_bundles($flag_type_def['entity_type']);
From 5b4ef1ce8ff988ba9ab03638751562d86e2d570a Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 29 Dec 2013 16:20:14 -0600
Subject: [PATCH 358/629] Flag plugin form settings now save to entity.
---
flag.module | 2 +-
.../flag/Controller/FlagListController.php | 21 ++++++-
lib/Drupal/flag/Entity/Flag.php | 62 ++++++++++++++++++-
lib/Drupal/flag/FlagInterface.php | 11 +++-
lib/Drupal/flag/Form/FlagAddForm.php | 45 ++++++++++----
.../flag/Plugin/Flag/CommentFlagType.php | 8 ++-
lib/Drupal/flag/Plugin/Flag/NodeFlagType.php | 10 ++-
lib/Drupal/flag/Plugin/Flag/UserFlagType.php | 15 ++---
8 files changed, 143 insertions(+), 31 deletions(-)
diff --git a/flag.module b/flag.module
index 17136f5..6820cba 100644
--- a/flag.module
+++ b/flag.module
@@ -435,7 +435,7 @@ function flag_permission() {
$flags = flag_get_flags();
// Provide flag and unflag permissions for each flag.
foreach ($flags as $flag_name => $flag) {
- $permissions += $flag->get_permissions();
+ // $permissions += $flag->get_permissions();
}
return $permissions;
diff --git a/lib/Drupal/flag/Controller/FlagListController.php b/lib/Drupal/flag/Controller/FlagListController.php
index a71b70d..814b994 100644
--- a/lib/Drupal/flag/Controller/FlagListController.php
+++ b/lib/Drupal/flag/Controller/FlagListController.php
@@ -25,15 +25,32 @@ public function buildHeader() {
return $header + parent::buildHeader();
}
+ protected function getFlagRoles(FlagInterface $flag) {
+ $allRoles = user_roles();
+ $out = '';
+
+ foreach ($flag->getPermissions() as $rid => $perms) {
+ $out .= $allRoles[$rid]->label;
+ $out .= ', ';
+ }
+
+ if (empty($out)) {
+ return 'None';
+ }
+
+ return rtrim($out, ', ');
+ }
+
/**
* Overrides Drupal\Core\Entity\EntityListController::buildRow().
*/
public function buildRow(EntityInterface $entity) {
+
$row['label'] = $this->getLabel($entity);
- $row['roles'] = ' ';
+ $row['roles'] = $this->getFlagRoles($entity);
- $row['is_global'] = $entity->is_global ? t('Yes') : t('No');
+ $row['is_global'] = $entity->isGlobal() ? t('Yes') : t('No');
return $row + parent::buildRow($entity);
}
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 782fa6f..10b4c2f 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -83,14 +83,14 @@ class Flag extends ConfigEntityBase implements FlagInterface {
*
* @var bool
*/
- public $is_global = FALSE;
+ protected $is_global = FALSE;
/**
* Whether this flag is enabled.
*
* @var bool
*/
- public $enabled = TRUE;
+ protected $enabled = TRUE;
/**
* The sub-types, AKA bundles, this flag applies to.
@@ -179,6 +179,8 @@ class Flag extends ConfigEntityBase implements FlagInterface {
*/
public $weight = 0;
+ protected $roles = array();
+
/**
* Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::__construct();
*/
@@ -256,6 +258,62 @@ public function setlinkTypePlugin($pluginID) {
$this->linkTypeBag->addInstanceId($pluginID);
}
+ /**
+ * @return array
+ */
+ public function getPermissions() {
+ return $this->roles;
+ }
+
+ /**
+ * @param $roleID
+ * @param $canFlag
+ * @param $canUnflag
+ */
+ public function setPermission($roleID, $canFlag, $canUnflag) {
+ if (!$canFlag && !$canUnflag) {
+ unset($this->roles[$roleID]);
+ }
+ else {
+ $this->roles[$roleID] = array(
+ 'flag' => $canFlag ? TRUE : FALSE,
+ 'unflag' => $canUnflag ? TRUE : FALSE,
+ );
+ }
+ }
+
+ /**
+ * @param array $flagPermssions
+ */
+ public function setPermissions(array $flagRoles, array $unflagRoles) {
+ $this->roles = array();
+
+ foreach ($flagRoles as $roleID => $value) {
+ if (!empty($value)) {
+ $this->roles[$roleID]['flag'] = TRUE;
+ }
+ }
+
+ foreach ($unflagRoles as $roleID => $value) {
+ if (!empty($value)) {
+ $this->roles[$roleID]['unflag'] = TRUE;
+ }
+ }
+ }
+
+ public function isGlobal() {
+ return $this->is_global;
+ }
+
+ public function setGlobal($isGlobal = TRUE) {
+ if ($isGlobal) {
+ $this->is_global = TRUE;
+ }
+ else {
+ $this->is_global = FALSE;
+ }
+ }
+
/**
* @param EntityStorageControllerInterface $storage_controller
*/
diff --git a/lib/Drupal/flag/FlagInterface.php b/lib/Drupal/flag/FlagInterface.php
index 0113880..d97b766 100644
--- a/lib/Drupal/flag/FlagInterface.php
+++ b/lib/Drupal/flag/FlagInterface.php
@@ -18,4 +18,13 @@ public function enable();
public function disable();
-}
\ No newline at end of file
+ public function getPermissions();
+
+ public function setPermission($roleID, $canFlag, $canUnflag);
+
+ public function setPermissions(array $flagRoles, array $unflagRoles);
+
+ public function isGlobal();
+
+ public function setGlobal($isGlobal);
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Form/FlagAddForm.php b/lib/Drupal/flag/Form/FlagAddForm.php
index 293028d..2f4513d 100644
--- a/lib/Drupal/flag/Form/FlagAddForm.php
+++ b/lib/Drupal/flag/Form/FlagAddForm.php
@@ -13,6 +13,24 @@
class FlagAddForm extends EntityFormController {
+ protected function getRoleOptions() {
+ $role_options = array();
+
+ foreach (user_roles() as $rid => $role_info) {
+ $role_options[$rid] = $role_info->label;
+ }
+
+ return $role_options;
+ }
+
+ protected function getRoleDefault($selction) {
+ if ($selction == 0) {
+ return array_keys(user_roles());
+ }
+
+ return array($selection);
+ }
+
public function buildForm(array $form, array &$form_state, $entity_type = NULL) {
//@todo Check all non-form_* params with check_plain().
$form = parent::buildForm($form, $form_state);
@@ -53,10 +71,10 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'#disabled' => !$flag->isNew(),
);
- $form['global'] = array(
+ $form['is_global'] = array(
'#type' => 'checkbox',
'#title' => t('Global flag'),
- '#default_value' => $flag->is_global,
+ '#default_value' => $flag->isGlobal(),
'#description' => t('If checked, flag is considered "global" and each entity is either flagged or not. If unchecked, each user has individual flags on entities.'),
'#weight' => -1,
);
@@ -159,7 +177,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'unflag' => array(DRUPAL_AUTHENTICATED_RID),
);
}
-
+*/
$form['access']['roles'] = array(
'#title' => t('Roles that may use this flag'),
'#description' => t('Users may only unflag content if they have access to flag the content initially. Checking authenticated user will allow access for all logged-in users.'),
@@ -171,13 +189,13 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'css' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.css'),
),
);
- if (module_exists('session_api')) {
+/* if (module_exists('session_api')) {
$form['access']['roles']['#description'] .= ' ' . t('Support for anonymous users is being provided by Session API.');
}
else {
$form['access']['roles']['#description'] .= ' ' . t('Anonymous users may flag content if the Session API module is installed.');
}
-*/
+*//*
foreach (user_roles() as $rid => $role_info) {
$access_roles_default_value = array();
if ($rid == $step1_form['flag_role'] || $step1_form['flag_role'] == '0') {
@@ -194,20 +212,22 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'#default_value' => $access_roles_default_value,
);
}
-/*
+*/
$form['access']['roles']['flag'] = array(
'#type' => 'checkboxes',
- '#options' => $role_options,
-// '#default_value' => $flag->roles['flag'],
+ '#title' => 'Roles that may flag',
+ '#options' => $this->getRoleOptions(),
+ '#default_value' => $this->getRoleDefault($step1_form['flag_role']),
'#parents' => array('roles', 'flag'),
);
$form['access']['roles']['unflag'] = array(
'#type' => 'checkboxes',
- '#options' => $role_options,
-// '#default_value' => $flag->roles['unflag'],
+ '#title' => 'Roles that may unflag',
+ '#options' => $this->getRoleOptions(),
+ '#default_value' => $this->getRoleDefault($step1_form['flag_role']),
'#parents' => array('roles', 'unflag'),
);
-*/
+
$form['access']['unflag_denied_text'] = array(
'#type' => 'textfield',
'#title' => t('Unflag not allowed text'),
@@ -337,7 +357,8 @@ public function validate(array $form, array &$form_state) {
public function save(array $form, array &$form_state) {
$flag = $this->entity;
- $form_state['values']['label'] = trim($form_state['values']['label']);
+ $flag->getFlagTypePlugin()->submitConfigurationForm($form, $form_state);
+ $flag->getLinkTypePlugin()->submitConfigurationForm($form, $form_state);
$flag->enable();
$status = $flag->save();
diff --git a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
index 5cbfc83..b909b71 100644
--- a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
@@ -24,8 +24,6 @@
*/
class CommentFlagType extends EntityFlagType {
- public $access_author;
-
public function defaultConfiguration() {
$options = parent::defaultConfiguration();
$options += array(
@@ -50,13 +48,17 @@ public function buildConfigurationForm(array $form, array &$form_state) {
'node_own' => t('Users may only flag comments of nodes they own'),
'node_others' => t('Users may only flag comments of nodes by others'),
),
- '#default_value' => $this->access_author,
+ '#default_value' => $this->configuration['access_author'],
'#description' => t("Restrict access to this flag based on the user's ownership of the content. Users must also have access to the flag through the role settings."),
);
return $form;
}
+ public function submitConfigurationForm(array &$form, array &$form_state) {
+ $this->configuration['access_author'] = $form_state['value']['access']['access_author'];
+ }
+
public function type_access_multiple($entity_ids, $account) {
$access = array();
diff --git a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
index 0de1699..4ac3c74 100644
--- a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
@@ -24,8 +24,6 @@
*/
class NodeFlagType extends EntityFlagType {
- public $access_author;
-
public function defaultConfiguration() {
$options = parent::defaultConfiguration();
// Use own display settings in the meanwhile.
@@ -49,7 +47,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
'own' => t('Users may only flag content they own'),
'others' => t('Users may only flag content of others'),
),
- '#default_value' => $this->access_author,
+ '#default_value' => $this->configuration['access_author'],
'#description' => t("Restrict access to this flag based on the user's ownership of the content. Users must also have access to the flag through the role settings."),
);
@@ -76,6 +74,12 @@ public function buildConfigurationForm(array $form, array &$form_state) {
return $form;
}
+ public function submitConfigurationForm(array &$form, array &$form_state) {
+ $this->configuration['access_author'] = $form_state['values']['access']['access_author'];
+ $this->configuration['i18n'] = $form_state['values']['i18n'];
+ $this->configuration['show_on_form'] = $form_state['values']['display']['show_on_form'];
+ }
+
function type_access_multiple($entity_ids, $account) {
$access = array();
diff --git a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
index 62979d4..bbe1f29 100644
--- a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
@@ -8,7 +8,7 @@
namespace Drupal\flag\Plugin\Flag;
-use Drupal\flag\Plugin\Flag\FlagTypeBase;
+use Drupal\flag\FlagTypeBase;
/**
* Class UserFlagType
@@ -22,10 +22,6 @@
*/
class UserFlagType extends FlagTypeBase {
- public $access_uid;
-
- public $show_on_profile;
-
public function defaultConfiguration() {
$options = parent::defaultConfiguration();
$options += array(
@@ -50,13 +46,13 @@ public function buildConfigurationForm(array $form, array &$form_state) {
'#type' => 'checkbox',
'#title' => t('Users may flag themselves'),
'#description' => t('Disabling this option may be useful when setting up a "friend" flag, when a user flagging themself does not make sense.'),
- '#default_value' => $this->access_uid ? 0 : 1,
+ '#default_value' => $this->configuration['access_uid'] ? 0 : 1,
);
$form['display']['show_on_profile'] = array(
'#type' => 'checkbox',
'#title' => t('Display link on user profile page'),
'#description' => t('Show the link formatted as a user profile element.'),
- '#default_value' => $this->show_on_profile,
+ '#default_value' => $this->configuration['show_on_profile'],
// Put this above 'show on entity'.
'#weight' => -1,
);
@@ -64,6 +60,11 @@ public function buildConfigurationForm(array $form, array &$form_state) {
return $form;
}
+ public function submitConfigurationForm(array &$form, array &$form_state) {
+ $this->configuration['access_uid'] = $form_state['values']['access']['access_uid'];
+ $this->configuration['show_on_profile'] = $form_state['values']['display']['show_on_profile'];
+ }
+
function type_access_multiple($entity_ids, $account) {
$access = array();
From bf058029d5aab9e90c7722e6ae590059ab46f90f Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sat, 4 Jan 2014 00:44:10 -0600
Subject: [PATCH 359/629] Split Flag Add form into base, add, and edit forms.
---
lib/Drupal/flag/Entity/Flag.php | 24 +-
lib/Drupal/flag/Form/FlagAddForm.php | 380 +-------------------------
lib/Drupal/flag/Form/FlagEditForm.php | 21 ++
lib/Drupal/flag/Form/FlagFormBase.php | 307 +++++++++++++++++++++
4 files changed, 346 insertions(+), 386 deletions(-)
create mode 100644 lib/Drupal/flag/Form/FlagEditForm.php
create mode 100644 lib/Drupal/flag/Form/FlagFormBase.php
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 10b4c2f..758eb2a 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -29,7 +29,7 @@
* "list" = "Drupal\flag\Controller\FlagListController",
* "form" = {
* "add" = "Drupal\flag\Form\FlagAddForm",
- * "edit" = "Drupal\flag\Form\FlagAddForm",
+ * "edit" = "Drupal\flag\Form\FlagEditForm",
* "delete" = "Drupal\flag\Form\FlagAddForm"
* }
* },
@@ -179,7 +179,10 @@ class Flag extends ConfigEntityBase implements FlagInterface {
*/
public $weight = 0;
- protected $roles = array();
+ protected $roles = array(
+ 'flag' => array(),
+ 'unflag' => array(),
+ );
/**
* Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::__construct();
@@ -286,19 +289,10 @@ public function setPermission($roleID, $canFlag, $canUnflag) {
* @param array $flagPermssions
*/
public function setPermissions(array $flagRoles, array $unflagRoles) {
- $this->roles = array();
-
- foreach ($flagRoles as $roleID => $value) {
- if (!empty($value)) {
- $this->roles[$roleID]['flag'] = TRUE;
- }
- }
-
- foreach ($unflagRoles as $roleID => $value) {
- if (!empty($value)) {
- $this->roles[$roleID]['unflag'] = TRUE;
- }
- }
+ $this->roles = array(
+ 'flag' => $flagRoles,
+ 'unflag' => $unflagRoles,
+ );
}
public function isGlobal() {
diff --git a/lib/Drupal/flag/Form/FlagAddForm.php b/lib/Drupal/flag/Form/FlagAddForm.php
index 2f4513d..a0a7cd3 100644
--- a/lib/Drupal/flag/Form/FlagAddForm.php
+++ b/lib/Drupal/flag/Form/FlagAddForm.php
@@ -8,20 +8,9 @@
namespace Drupal\flag\Form;
-use Drupal\Core\Entity\EntityFormController;
-use Drupal\flag\Handlers\AbstractFlag;
+use Drupal\flag\Form\FlagFormBase;
-class FlagAddForm extends EntityFormController {
-
- protected function getRoleOptions() {
- $role_options = array();
-
- foreach (user_roles() as $rid => $role_info) {
- $role_options[$rid] = $role_info->label;
- }
-
- return $role_options;
- }
+class FlagAddForm extends FlagFormBase {
protected function getRoleDefault($selction) {
if ($selction == 0) {
@@ -33,382 +22,31 @@ protected function getRoleDefault($selction) {
public function buildForm(array $form, array &$form_state, $entity_type = NULL) {
//@todo Check all non-form_* params with check_plain().
- $form = parent::buildForm($form, $form_state);
$tempstore = \Drupal::service('user.tempstore')->get('flag');
$step1_form = $tempstore->get('FlagAddPage');
$flag = $this->entity;
+ $flag->label = $step1_form['label'];
+ $flag->id = $step1_form['id'];
+
$flag->setFlagTypePlugin($step1_form['flag_entity_type']);
$flag->setLinkTypePlugin($step1_form['flag_link_type']);
// Mark the flag as new.
$flag->is_new = TRUE;
- $type_info = flag_fetch_definition($entity_type);
-
- $form['#flag'] = $flag;
- $form['#flag_name'] = $flag->id;
-
- $form['label'] = array(
- '#type' => 'textfield',
- '#title' => t('Label'),
- '#default_value' => $step1_form['label'],
- '#description' => t('A short, descriptive title for this flag. It will be used in administrative interfaces to refer to this flag, and in page titles and menu items of some views this module provides (theses are customizable, though). Some examples could be Bookmarks, Favorites, or Offensive.', array('@insite-views-url' => url('admin/structure/views'))),
- '#maxlength' => 255,
- '#required' => TRUE,
- '#weight' => -3,
- );
-
- $form['id'] = array(
- '#type' => 'machine_name',
- '#title' => t('Machine name'),
- '#default_value' => $step1_form['id'],
- '#description' => t('The machine-name for this flag. It may be up to 32 characters long and may only contain lowercase letters, underscores, and numbers. It will be used in URLs and in all API calls.'),
- '#weight' => -2,
- '#machine_name' => array(
- 'exists' => 'flag_load_by_id',
- ),
- '#disabled' => !$flag->isNew(),
- );
-
- $form['is_global'] = array(
- '#type' => 'checkbox',
- '#title' => t('Global flag'),
- '#default_value' => $flag->isGlobal(),
- '#description' => t('If checked, flag is considered "global" and each entity is either flagged or not. If unchecked, each user has individual flags on entities.'),
- '#weight' => -1,
- );
-
- $form['messages'] = array(
- '#type' => 'fieldset',
- '#title' => t('Messages'),
- );
-
- $form['messages']['flag_short'] = array(
- '#type' => 'textfield',
- '#title' => t('Flag link text'),
- '#default_value' => !empty($flag->flag_short) ? $flag->flag_short : t('Flag this item'),
- '#description' => t('The text for the "flag this" link for this flag.'),
- '#required' => TRUE,
- );
-
- $form['messages']['flag_long'] = array(
- '#type' => 'textfield',
- '#title' => t('Flag link description'),
- '#default_value' => $flag->flag_long,
- '#description' => t('The description of the "flag this" link. Usually displayed on mouseover.'),
- );
-
- $form['messages']['flag_message'] = array(
- '#type' => 'textfield',
- '#title' => t('Flagged message'),
- '#default_value' => $flag->flag_message,
- '#description' => t('Message displayed after flagging content. If JavaScript is enabled, it will be displayed below the link. If not, it will be displayed in the message area.'),
- );
-
- $form['messages']['unflag_short'] = array(
- '#type' => 'textfield',
- '#title' => t('Unflag link text'),
- '#default_value' => !empty($flag->unflag_short) ? $flag->unflag_short : t('Unflag this item'),
- '#description' => t('The text for the "unflag this" link for this flag.'),
- '#required' => TRUE,
- );
-
- $form['messages']['unflag_long'] = array(
- '#type' => 'textfield',
- '#title' => t('Unflag link description'),
- '#default_value' => $flag->unflag_long,
- '#description' => t('The description of the "unflag this" link. Usually displayed on mouseover.'),
- );
-
- $form['messages']['unflag_message'] = array(
- '#type' => 'textfield',
- '#title' => t('Unflagged message'),
- '#default_value' => $flag->unflag_message,
- '#description' => t('Message displayed after content has been unflagged. If JavaScript is enabled, it will be displayed below the link. If not, it will be displayed in the message area.'),
- );
-
- $form['access'] = array(
- '#type' => 'fieldset',
- '#title' => t('Flag access'),
- '#tree' => FALSE,
- '#weight' => 10,
- );
-
- $flag_type_plugin = $flag->getFlagTypePlugin();
- $flag_type_def = $flag_type_plugin->getPluginDefinition();
-
- $bundles = entity_get_bundles($flag_type_def['entity_type']);
- $entity_bundles = array();
- foreach ($bundles as $bundle_id => $bundle_row) {
- $entity_bundles[$bundle_id] = $bundle_row['label'];
- }
-
- // Flag classes will want to override this form element.
- $form['access']['types'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Flaggable types'),
- '#options' => $entity_bundles,
- '#default_value' => $flag->types,
- '#description' => t('Check any sub-types that this flag may be used on.'),
- '#required' => TRUE,
- '#weight' => 10,
- );
-/*
- // Disabled access breaks checkboxes unless #value is hard coded.
- if (!empty($flag->locked['types'])) {
- $form['access']['types']['#value'] = $flag->types;
- }
-
- // Load the user permissions into the flag.
- if (isset($flag->id)) {
- $flag->fetch_roles();
- }
- elseif (isset($flag->import_roles)) {
- // Convert the roles data from old API 2 flags that have been run through
- // the update system.
- // @see FlagUpdate_2::update()
- $flag->roles = $flag->import_roles;
- }
- else {
- // For new flags, provide a reasonable default value.
- $flag->roles = array(
- 'flag' => array(DRUPAL_AUTHENTICATED_RID),
- 'unflag' => array(DRUPAL_AUTHENTICATED_RID),
- );
- }
-*/
- $form['access']['roles'] = array(
- '#title' => t('Roles that may use this flag'),
- '#description' => t('Users may only unflag content if they have access to flag the content initially. Checking authenticated user will allow access for all logged-in users.'),
- '#theme' => 'flag_form_roles',
- '#theme_wrappers' => array('form_element'),
- '#weight' => -2,
- '#attached' => array(
- 'js' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.js'),
- 'css' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.css'),
- ),
- );
-/* if (module_exists('session_api')) {
- $form['access']['roles']['#description'] .= ' ' . t('Support for anonymous users is being provided by Session API.');
- }
- else {
- $form['access']['roles']['#description'] .= ' ' . t('Anonymous users may flag content if the Session API module is installed.');
- }
-*//*
- foreach (user_roles() as $rid => $role_info) {
- $access_roles_default_value = array();
- if ($rid == $step1_form['flag_role'] || $step1_form['flag_role'] == '0') {
- $access_roles_default_value = array('flag', 'unflag');
- }
-
- $form['access']['roles'][$rid] = array(
- '#type' => 'checkboxes',
- '#options' => array('flag' => t('Flag'), 'unflag' => t('Unflag')),
- '#attributes' => array(
- 'class' => array('container-inline'),
- ),
- '#title' => $role_info->label,
- '#default_value' => $access_roles_default_value,
- );
- }
-*/
- $form['access']['roles']['flag'] = array(
- '#type' => 'checkboxes',
- '#title' => 'Roles that may flag',
- '#options' => $this->getRoleOptions(),
- '#default_value' => $this->getRoleDefault($step1_form['flag_role']),
- '#parents' => array('roles', 'flag'),
- );
- $form['access']['roles']['unflag'] = array(
- '#type' => 'checkboxes',
- '#title' => 'Roles that may unflag',
- '#options' => $this->getRoleOptions(),
- '#default_value' => $this->getRoleDefault($step1_form['flag_role']),
- '#parents' => array('roles', 'unflag'),
- );
-
- $form['access']['unflag_denied_text'] = array(
- '#type' => 'textfield',
- '#title' => t('Unflag not allowed text'),
- '#default_value' => $flag->unflag_denied_text,
- '#description' => t('If a user is allowed to flag but not unflag, this text will be displayed after flagging. Often this is the past-tense of the link text, such as "flagged".'),
- '#weight' => -1,
- );
- $form['display'] = array(
- '#type' => 'fieldset',
- '#title' => t('Display options'),
- '#description' => t('Flags are usually controlled through links that allow users to toggle their behavior. You can choose how users interact with flags by changing options here. It is legitimate to have none of the following checkboxes ticked, if, for some reason, you wish to place the the links on the page yourself.', array('@placement-url' => 'http://drupal.org/node/295383')),
- '#tree' => FALSE,
- '#weight' => 20,
- // @todo: Move flag_link_type_options_states() into controller?
-// '#after_build' => array('flag_link_type_options_states'),
- );
+ $flag->setPermissions($this->getRoleDefault($step1_form['flag_role']),
+ $this->getRoleDefault($step1_form['flag_role']));
- $form = $flag_type_plugin->buildConfigurationForm($form, $form_state);
-
- $form['display']['link_type'] = array(
- '#type' => 'radios',
- '#title' => t('Link type'),
- '#options' => \Drupal::service('plugin.manager.flag.linktype')->getAllLinkTypes(),
-// '#after_build' => array('flag_check_link_types'),
- '#default_value' => $step1_form['flag_link_type'],
- // Give this a high weight so additions by the flag classes for entity-
- // specific options go above.
- '#weight' => 18,
- '#attached' => array(
- 'js' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.js'),
- ),
- '#attributes' => array(
- 'class' => array('flag-link-options'),
- ),
- );
- // Add the descriptions to each ratio button element. These attach to the
- // elements when FormAPI expands them.
- $action_link_plugin_defs = \Drupal::service('plugin.manager.flag.linktype')->getDefinitions();
- foreach ($action_link_plugin_defs as $key => $info) {
- $form['display']['link_type'][$key]['#description'] = $info['description'];
- }
-
-
-/*
- $form['display']['link_options_intro'] = array(
- // This is a hack to allow a markup element to use FormAPI states.
- // @see http://www.bywombats.com/blog/06-25-2011/using-containers-states-enabled-markup-form-elements
- '#type' => 'container',
- '#children' => '' . t('The selected link type may require these additional settings:') . '
',
- '#weight' => 20,
- );
-
- $form['display']['link_options_confirm'] = array(
- '#type' => 'fieldset',
- '#title' => t('Options for the "Confirmation form" link type'),
- // Any "link type" provider module must put its settings fields inside
- // a fieldset whose HTML ID is link-options-LINKTYPE, where LINKTYPE is
- // the machine-name of the link type. This is necessary for the
- // radiobutton's JavaScript dependency feature to work.
- '#id' => 'link-options-confirm',
- '#weight' => 21,
- );
-
- $form['display']['link_options_confirm']['flag_confirmation'] = array(
- '#type' => 'textfield',
- '#title' => t('Flag confirmation message'),
- '#default_value' => isset($flag->flag_confirmation) ? $flag->flag_confirmation : '',
- '#description' => t('Message displayed if the user has clicked the "flag this" link and confirmation is required. Usually presented in the form of a question such as, "Are you sure you want to flag this content?"'),
- );
-
- $form['display']['link_options_confirm']['unflag_confirmation'] = array(
- '#type' => 'textfield',
- '#title' => t('Unflag confirmation message'),
- '#default_value' => isset($flag->unflag_confirmation) ? $flag->unflag_confirmation : '',
- '#description' => t('Message displayed if the user has clicked the "unflag this" link and confirmation is required. Usually presented in the form of a question such as, "Are you sure you want to unflag this content?"'),
- );
-
- // Add our process handler to disable access to locked properties.
- //@todo: Fix reference to flag_form_locked_process, or replace entirely.
-// $form['#process'][] = 'flag_form_locked_process';
-
- // Allow the flag handler to make additions and changes to the form.
- // Note that the flag_broken handler will completely empty the form array!
-// $flag->options_form($form);
-*/
- $action_link_plugin = \Drupal::service('plugin.manager.flag.linktype')->createInstance($step1_form['flag_link_type']);
-
- $form = $action_link_plugin->buildConfigurationForm($form, $form_state);
+ $form = parent::buildForm($form, $form_state);
return $form;
}
protected function actions(array $form, array &$form_state) {
$actions = parent::actions($form, $form_state);
- $actions['submit']['#value'] = t('Save Flag');
+ $actions['submit']['#value'] = t('Create Flag');
return $actions;
}
-
- /**
- * Overrides Drupal\Core\Entity\EntityFormController::validate().
- */
- public function validate(array $form, array &$form_state) {
- parent::validate($form, $form_state);
-
- $form_state['values']['label'] = trim($form_state['values']['label']);
- $form_values = $form_state['values'];
-
- if ($form_values['link_type'] == 'confirm') {
- if (empty($form_values['flag_confirmation'])) {
- form_set_error('flag_confirmation', t('A flag confirmation message is required when using the confirmation link type.'));
- }
- if (empty($form_values['unflag_confirmation'])) {
- form_set_error('unflag_confirmation', t('An unflag confirmation message is required when using the confirmation link type.'));
- }
- }
-/*
- if (!preg_match('/^[a-z_][a-z0-9_]*$/', $form_values['id'])) {
- form_set_error('label', t('The flag name may only contain lowercase letters, underscores, and numbers.'));
- }
-*/
- }
-
- /**
- * Overrides Drupal\Core\Entity\EntityFormController::save().
- */
- public function save(array $form, array &$form_state) {
- $flag = $this->entity;
-
- $flag->getFlagTypePlugin()->submitConfigurationForm($form, $form_state);
- $flag->getLinkTypePlugin()->submitConfigurationForm($form, $form_state);
-
- $flag->enable();
- $status = $flag->save();
- $uri = $flag->uri();
- if ($status == SAVED_UPDATED) {
- drupal_set_message(t('Flag %label has been updated.', array('%label' => $flag->label())));
- watchdog('flag', 'Flag %label has been updated.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'] . '/edit'));
- }
- else {
- drupal_set_message(t('Flag %label has been added.', array('%label' => $flag->label())));
- watchdog('flag', 'Flag %label has been added.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'] . '/edit'));
- }
-
- // We clear caches more vigorously if the flag was new.
-// _flag_clear_cache($flag->entity_type, !empty($flag->is_new));
-
- // Save permissions.
- // This needs to be done after the flag cache has been cleared, so that
- // the new permissions are picked up by hook_permission().
- // This may need to move to the flag class when we implement extra permissions
- // for different flag types: http://drupal.org/node/879988
-
- // If the flag machine name as changed, clean up all the obsolete permissions.
- if ($flag->id != $form['#flag_name']) {
- $old_name = $form['#flag_name'];
- $permissions = array("flag $old_name", "unflag $old_name");
- foreach (array_keys(user_roles()) as $rid) {
- user_role_revoke_permissions($rid, $permissions);
- }
- }
-/*
- foreach (array_keys(user_roles(!module_exists('session_api'))) as $rid) {
- // Create an array of permissions, based on the checkboxes element name.
- $permissions = array(
- "flag $flag->name" => $flag->roles['flag'][$rid],
- "unflag $flag->name" => $flag->roles['unflag'][$rid],
- );
- user_role_change_permissions($rid, $permissions);
- }
-*/
- // @todo: when we add database caching for flags we'll have to clear the
- // cache again here.
-
- $form_state['redirect'] = 'admin/structure/flags';
- }
-
- /**
- * Overrides Drupal\Core\Entity\EntityFormController::delete().
- */
- public function delete(array $form, array &$form_state) {
- $form_state['redirect'] = 'admin/structure/flag';
- }
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Form/FlagEditForm.php b/lib/Drupal/flag/Form/FlagEditForm.php
new file mode 100644
index 0000000..3831ccd
--- /dev/null
+++ b/lib/Drupal/flag/Form/FlagEditForm.php
@@ -0,0 +1,21 @@
+ $role_info) {
+ $role_options[$rid] = $role_info->label;
+ }
+
+ return $role_options;
+ }
+
+ public function buildForm(array $form, array &$form_state, $entity_type = NULL) {
+ $form = parent::buildForm($form, $form_state);
+
+ $flag = $this->entity;
+
+ // Mark the flag as new.
+ $flag->is_new = TRUE;
+ $type_info = flag_fetch_definition($entity_type);
+
+ $form['#flag'] = $flag;
+ $form['#flag_name'] = $flag->id;
+
+ $form['label'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Label'),
+ '#default_value' => $flag->label,
+ '#description' => t('A short, descriptive title for this flag. It will be used in administrative interfaces to refer to this flag, and in page titles and menu items of some views this module provides (theses are customizable, though). Some examples could be Bookmarks, Favorites, or Offensive.', array('@insite-views-url' => url('admin/structure/views'))),
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#weight' => -3,
+ );
+
+ $form['id'] = array(
+ '#type' => 'machine_name',
+ '#title' => t('Machine name'),
+ '#default_value' => $flag->id,
+ '#description' => t('The machine-name for this flag. It may be up to 32 characters long and may only contain lowercase letters, underscores, and numbers. It will be used in URLs and in all API calls.'),
+ '#weight' => -2,
+ '#machine_name' => array(
+ 'exists' => 'flag_load_by_id',
+ ),
+ '#disabled' => !$flag->isNew(),
+ );
+
+ $form['is_global'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Global flag'),
+ '#default_value' => $flag->isGlobal(),
+ '#description' => t('If checked, flag is considered "global" and each entity is either flagged or not. If unchecked, each user has individual flags on entities.'),
+ '#weight' => -1,
+ );
+
+ $form['messages'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Messages'),
+ );
+
+ $form['messages']['flag_short'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Flag link text'),
+ '#default_value' => !empty($flag->flag_short) ? $flag->flag_short : t('Flag this item'),
+ '#description' => t('The text for the "flag this" link for this flag.'),
+ '#required' => TRUE,
+ );
+
+ $form['messages']['flag_long'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Flag link description'),
+ '#default_value' => $flag->flag_long,
+ '#description' => t('The description of the "flag this" link. Usually displayed on mouseover.'),
+ );
+
+ $form['messages']['flag_message'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Flagged message'),
+ '#default_value' => $flag->flag_message,
+ '#description' => t('Message displayed after flagging content. If JavaScript is enabled, it will be displayed below the link. If not, it will be displayed in the message area.'),
+ );
+
+ $form['messages']['unflag_short'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Unflag link text'),
+ '#default_value' => !empty($flag->unflag_short) ? $flag->unflag_short : t('Unflag this item'),
+ '#description' => t('The text for the "unflag this" link for this flag.'),
+ '#required' => TRUE,
+ );
+
+ $form['messages']['unflag_long'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Unflag link description'),
+ '#default_value' => $flag->unflag_long,
+ '#description' => t('The description of the "unflag this" link. Usually displayed on mouseover.'),
+ );
+
+ $form['messages']['unflag_message'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Unflagged message'),
+ '#default_value' => $flag->unflag_message,
+ '#description' => t('Message displayed after content has been unflagged. If JavaScript is enabled, it will be displayed below the link. If not, it will be displayed in the message area.'),
+ );
+
+ $form['access'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Flag access'),
+ '#tree' => FALSE,
+ '#weight' => 10,
+ );
+
+ $flag_type_plugin = $flag->getFlagTypePlugin();
+ $flag_type_def = $flag_type_plugin->getPluginDefinition();
+
+ $bundles = entity_get_bundles($flag_type_def['entity_type']);
+ $entity_bundles = array();
+ foreach ($bundles as $bundle_id => $bundle_row) {
+ $entity_bundles[$bundle_id] = $bundle_row['label'];
+ }
+
+ // Flag classes will want to override this form element.
+ $form['access']['types'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Flaggable types'),
+ '#options' => $entity_bundles,
+ '#default_value' => $flag->types,
+ '#description' => t('Check any sub-types that this flag may be used on.'),
+ '#required' => TRUE,
+ '#weight' => 10,
+ );
+
+ $form['access']['roles'] = array(
+ '#title' => t('Roles that may use this flag'),
+ '#description' => t('Users may only unflag content if they have access to flag the content initially. Checking authenticated user will allow access for all logged-in users.'),
+ '#theme' => 'flag_form_roles',
+ '#theme_wrappers' => array('form_element'),
+ '#weight' => -2,
+ '#attached' => array(
+ 'js' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.js'),
+ 'css' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.css'),
+ ),
+ );
+
+ $flag_permissions = $flag->getPermissions();
+
+ $form['access']['roles']['flag'] = array(
+ '#type' => 'checkboxes',
+ '#title' => 'Roles that may flag',
+ '#options' => $this->getRoleOptions(),
+ '#default_value' => $flag_permissions['flag'],
+ '#parents' => array('roles', 'flag'),
+ );
+ $form['access']['roles']['unflag'] = array(
+ '#type' => 'checkboxes',
+ '#title' => 'Roles that may unflag',
+ '#options' => $this->getRoleOptions(),
+ '#default_value' => $flag_permissions['unflag'],
+ '#parents' => array('roles', 'unflag'),
+ );
+
+ $form['access']['unflag_denied_text'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Unflag not allowed text'),
+ '#default_value' => $flag->unflag_denied_text,
+ '#description' => t('If a user is allowed to flag but not unflag, this text will be displayed after flagging. Often this is the past-tense of the link text, such as "flagged".'),
+ '#weight' => -1,
+ );
+
+ $form['display'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Display options'),
+ '#description' => t('Flags are usually controlled through links that allow users to toggle their behavior. You can choose how users interact with flags by changing options here. It is legitimate to have none of the following checkboxes ticked, if, for some reason, you wish to place the the links on the page yourself.', array('@placement-url' => 'http://drupal.org/node/295383')),
+ '#tree' => FALSE,
+ '#weight' => 20,
+ // @todo: Move flag_link_type_options_states() into controller?
+// '#after_build' => array('flag_link_type_options_states'),
+ );
+
+ $form = $flag_type_plugin->buildConfigurationForm($form, $form_state);
+
+ $form['display']['link_type'] = array(
+ '#type' => 'radios',
+ '#title' => t('Link type'),
+ '#options' => \Drupal::service('plugin.manager.flag.linktype')->getAllLinkTypes(),
+// '#after_build' => array('flag_check_link_types'),
+ '#default_value' => $flag->getLinkTypePlugin()->getPluginId(),
+ // Give this a high weight so additions by the flag classes for entity-
+ // specific options go above.
+ '#weight' => 18,
+ '#attached' => array(
+ 'js' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.js'),
+ ),
+ '#attributes' => array(
+ 'class' => array('flag-link-options'),
+ ),
+ );
+ // Add the descriptions to each ratio button element. These attach to the
+ // elements when FormAPI expands them.
+ $action_link_plugin_defs = \Drupal::service('plugin.manager.flag.linktype')->getDefinitions();
+ foreach ($action_link_plugin_defs as $key => $info) {
+ $form['display']['link_type'][$key]['#description'] = $info['description'];
+ }
+
+ $action_link_plugin = $flag->getLinkTypePlugin();
+ $form = $action_link_plugin->buildConfigurationForm($form, $form_state);
+
+ return $form;
+ }
+
+ /**
+ * Overrides Drupal\Core\Entity\EntityFormController::validate().
+ */
+ public function validate(array $form, array &$form_state) {
+ parent::validate($form, $form_state);
+
+ $form_state['values']['label'] = trim($form_state['values']['label']);
+ $form_values = $form_state['values'];
+
+ if ($form_values['link_type'] == 'confirm') {
+ if (empty($form_values['flag_confirmation'])) {
+ form_set_error('flag_confirmation', t('A flag confirmation message is required when using the confirmation link type.'));
+ }
+ if (empty($form_values['unflag_confirmation'])) {
+ form_set_error('unflag_confirmation', t('An unflag confirmation message is required when using the confirmation link type.'));
+ }
+ }
+ /*
+ if (!preg_match('/^[a-z_][a-z0-9_]*$/', $form_values['id'])) {
+ form_set_error('label', t('The flag name may only contain lowercase letters, underscores, and numbers.'));
+ }
+ */
+ }
+
+ /**
+ * Overrides Drupal\Core\Entity\EntityFormController::save().
+ */
+ public function save(array $form, array &$form_state) {
+ $flag = $this->entity;
+
+ $flag->getFlagTypePlugin()->submitConfigurationForm($form, $form_state);
+ $flag->getLinkTypePlugin()->submitConfigurationForm($form, $form_state);
+
+ $flag->enable();
+ $status = $flag->save();
+ $uri = $flag->uri();
+ if ($status == SAVED_UPDATED) {
+ drupal_set_message(t('Flag %label has been updated.', array('%label' => $flag->label())));
+ watchdog('flag', 'Flag %label has been updated.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'] . '/edit'));
+ }
+ else {
+ drupal_set_message(t('Flag %label has been added.', array('%label' => $flag->label())));
+ watchdog('flag', 'Flag %label has been added.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'] . '/edit'));
+ }
+
+ // We clear caches more vigorously if the flag was new.
+// _flag_clear_cache($flag->entity_type, !empty($flag->is_new));
+
+ // Save permissions.
+ // This needs to be done after the flag cache has been cleared, so that
+ // the new permissions are picked up by hook_permission().
+ // This may need to move to the flag class when we implement extra permissions
+ // for different flag types: http://drupal.org/node/879988
+
+ // If the flag machine name as changed, clean up all the obsolete permissions.
+ if ($flag->id != $form['#flag_name']) {
+ $old_name = $form['#flag_name'];
+ $permissions = array("flag $old_name", "unflag $old_name");
+ foreach (array_keys(user_roles()) as $rid) {
+ user_role_revoke_permissions($rid, $permissions);
+ }
+ }
+ /*
+ foreach (array_keys(user_roles(!module_exists('session_api'))) as $rid) {
+ // Create an array of permissions, based on the checkboxes element name.
+ $permissions = array(
+ "flag $flag->name" => $flag->roles['flag'][$rid],
+ "unflag $flag->name" => $flag->roles['unflag'][$rid],
+ );
+ user_role_change_permissions($rid, $permissions);
+ }
+ */
+ // @todo: when we add database caching for flags we'll have to clear the
+ // cache again here.
+
+ $form_state['redirect'] = 'admin/structure/flags';
+ }
+
+ /**
+ * Overrides Drupal\Core\Entity\EntityFormController::delete().
+ */
+ public function delete(array $form, array &$form_state) {
+ $form_state['redirect'] = 'admin/structure/flag';
+ }
+
+}
\ No newline at end of file
From 9a4f27252b3cacaf2937e18f40d067e462db44fd Mon Sep 17 00:00:00 2001
From: socketwench
Date: Mon, 13 Jan 2014 23:57:31 -0600
Subject: [PATCH 360/629] Working Flag edit and delete forms.
---
flag.routing.yml | 18 ++++++++-
.../flag/Controller/FlagListController.php | 5 ++-
lib/Drupal/flag/Entity/Flag.php | 30 ++++++++++----
lib/Drupal/flag/Form/FlagDeleteForm.php | 40 +++++++++++++++++++
lib/Drupal/flag/Form/FlagFormBase.php | 4 +-
.../flag/Plugin/Flag/CommentFlagType.php | 2 +-
lib/Drupal/flag/Plugin/Flag/NodeFlagType.php | 4 +-
7 files changed, 85 insertions(+), 18 deletions(-)
create mode 100644 lib/Drupal/flag/Form/FlagDeleteForm.php
diff --git a/flag.routing.yml b/flag.routing.yml
index efda13c..bc999cf 100644
--- a/flag.routing.yml
+++ b/flag.routing.yml
@@ -2,6 +2,7 @@ flag_add_page:
path: '/admin/structure/flags/add'
defaults:
_form: '\Drupal\flag\Form\FlagAddPageForm'
+ _title: 'Add New Flag'
requirements:
_permission: 'administer flags'
@@ -9,6 +10,7 @@ flag.flag_list:
path: '/admin/structure/flags'
defaults:
_entity_list: 'flag_flag'
+ _title: 'Flags'
requirements:
_permission: 'administer flags'
@@ -16,20 +18,31 @@ flag_add:
path: '/admin/structure/flags/add/{entity_type}'
defaults:
_entity_form: flag_flag.add
+ _title: 'Add New Flag'
requirements:
_permission: 'administer flags'
flag_edit:
- path: '/admin/structure/flags/manage/{entity_type}'
+ path: '/admin/structure/flags/manage/{flag_flag}'
defaults:
_entity_form: flag_flag.edit
+ _title: 'Edit Flag'
requirements:
- _permission: 'administer flags'
+ _entity_access: 'flag_flag.update'
+
+flag_delete:
+ path: '/admin/structure/flags/manage/{flag_flag}/delete'
+ defaults:
+ _entity_form: flag_flag.delete
+ _title: 'Delete Flag'
+ requirements:
+ _entity_access: 'flag_flag.update'
flag_import:
path: '/admin/structure/flags/import'
defaults:
_form: '\Drupal\flag\Form\FlagImportForm'
+ _title: 'Import Flags'
requirements:
_permission: 'use flag import'
@@ -37,5 +50,6 @@ flag_export:
path: '/admin/structure/flags/export'
defaults:
_form: '\Drupal\flag\Form\FlagExportForm'
+ _title: 'Export Flags'
requirements:
_permission: 'use flag import'
diff --git a/lib/Drupal/flag/Controller/FlagListController.php b/lib/Drupal/flag/Controller/FlagListController.php
index 814b994..d19c2de 100644
--- a/lib/Drupal/flag/Controller/FlagListController.php
+++ b/lib/Drupal/flag/Controller/FlagListController.php
@@ -27,9 +27,10 @@ public function buildHeader() {
protected function getFlagRoles(FlagInterface $flag) {
$allRoles = user_roles();
+ $flagPermissions = $flag->getPermissions();
$out = '';
- foreach ($flag->getPermissions() as $rid => $perms) {
+ foreach ($flagPermissions['flag'] as $rid) {
$out .= $allRoles[$rid]->label;
$out .= ', ';
}
@@ -99,4 +100,4 @@ public function render() {
return $build;
}
-}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 758eb2a..26bbe71 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -24,13 +24,14 @@
* id = "flag_flag",
* label = @Translation("Flag"),
* module = "flag",
+ * admin_permission = "administer flags",
* controllers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigStorageController",
* "list" = "Drupal\flag\Controller\FlagListController",
* "form" = {
* "add" = "Drupal\flag\Form\FlagAddForm",
* "edit" = "Drupal\flag\Form\FlagEditForm",
- * "delete" = "Drupal\flag\Form\FlagAddForm"
+ * "delete" = "Drupal\flag\Form\FlagDeleteForm"
* }
* },
* bundle_of = "flagging",
@@ -41,7 +42,7 @@
* "uuid" = "uuid"
* },
* links = {
- * "edit-form" = "admin/structure/flags/manage/{flag_flag}"
+ * "edit-form" = "flag_edit"
* }
* )
*
@@ -316,15 +317,28 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
// Save the Flag Type configuration.
$flagTypePlugin = $this->getFlagTypePlugin();
- if ($flagTypePlugin instanceof ConfigurablePluginInterface) {
- $this->set('flagTypeConfig', $flagTypePlugin->getConfiguration());
- }
+ $this->set('flagTypeConfig', $flagTypePlugin->getConfiguration());
// Save the Link Type configuration.
$linkTypePlugin = $this->getLinkTypePlugin();
- if ($linkTypePlugin instanceof ConfigurablePluginInterface) {
- $this->set('linkTypeConfig', $linkTypePlugin->getConfiguration());
- }
+ $this->set('linkTypeConfig', $linkTypePlugin->getConfiguration());
+ }
+
+ public function getExportProperties() {
+ $properties = parent::getExportProperties();
+ $names = array(
+ 'roles',
+ 'flag_type',
+ 'link_type',
+ 'flagTypeConfig',
+ 'linkTypeConfig',
+ );
+
+ foreach ($names as $name) {
+ $properties[$name] = $this->get($name);
+ }
+
+ return $properties;
}
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Form/FlagDeleteForm.php b/lib/Drupal/flag/Form/FlagDeleteForm.php
new file mode 100644
index 0000000..3d755f6
--- /dev/null
+++ b/lib/Drupal/flag/Form/FlagDeleteForm.php
@@ -0,0 +1,40 @@
+ $this->entity->label()
+ ));
+ }
+
+ public function getConfirmText() {
+ return t('Delete');
+ }
+
+ public function getCancelRoute() {
+ return array(
+ 'route_name' => 'flag.flag_list',
+ );
+ }
+
+ public function submit(array $form, array &$form_state) {
+ $this->entity->delete();
+ drupal_set_message(t('Flag %label was deleted.', array(
+ '%label' => $this->entity->label(),
+ )));
+
+ $form_state['redirect_route']['route_name'] = 'flag.flag_list';
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Form/FlagFormBase.php b/lib/Drupal/flag/Form/FlagFormBase.php
index 657274d..7a7669a 100644
--- a/lib/Drupal/flag/Form/FlagFormBase.php
+++ b/lib/Drupal/flag/Form/FlagFormBase.php
@@ -28,8 +28,6 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
$flag = $this->entity;
- // Mark the flag as new.
- $flag->is_new = TRUE;
$type_info = flag_fetch_definition($entity_type);
$form['#flag'] = $flag;
@@ -301,7 +299,7 @@ public function save(array $form, array &$form_state) {
* Overrides Drupal\Core\Entity\EntityFormController::delete().
*/
public function delete(array $form, array &$form_state) {
- $form_state['redirect'] = 'admin/structure/flag';
+ $form_state['redirect'] = 'admin/structure/flags';
}
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
index b909b71..28ed0c5 100644
--- a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
@@ -56,7 +56,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
}
public function submitConfigurationForm(array &$form, array &$form_state) {
- $this->configuration['access_author'] = $form_state['value']['access']['access_author'];
+ $this->configuration['access_author'] = $form_state['values']['access_author'];
}
public function type_access_multiple($entity_ids, $account) {
diff --git a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
index 4ac3c74..5c1b4d7 100644
--- a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
@@ -75,9 +75,9 @@ public function buildConfigurationForm(array $form, array &$form_state) {
}
public function submitConfigurationForm(array &$form, array &$form_state) {
- $this->configuration['access_author'] = $form_state['values']['access']['access_author'];
+ $this->configuration['access_author'] = $form_state['values']['access_author'];
$this->configuration['i18n'] = $form_state['values']['i18n'];
- $this->configuration['show_on_form'] = $form_state['values']['display']['show_on_form'];
+ $this->configuration['show_on_form'] = $form_state['values']['show_on_form'];
}
function type_access_multiple($entity_ids, $account) {
From 0836f61c2d0d908556addfcbbf94c0eec032c5dd Mon Sep 17 00:00:00 2001
From: socketwench
Date: Mon, 20 Jan 2014 23:27:24 -0600
Subject: [PATCH 361/629] Implmented Drupal permissions for Flag entity.
---
flag.module | 20 ++---
flag.services.yml | 3 +
.../flag/Controller/FlagListController.php | 16 ++--
lib/Drupal/flag/Entity/Flag.php | 87 ++++++++++++++++---
lib/Drupal/flag/Flag.php | 66 +++++++++++++-
lib/Drupal/flag/Form/FlagFormBase.php | 2 +-
6 files changed, 158 insertions(+), 36 deletions(-)
diff --git a/flag.module b/flag.module
index 6820cba..b96707f 100644
--- a/flag.module
+++ b/flag.module
@@ -11,6 +11,7 @@ define('FLAG_ADMIN_PATH', 'admin/structure/flags');
define('FLAG_ADMIN_PATH_START', 3);
use Drupal\flag\Handlers\AbstractFlag;
+use Drupal\flag\Flag;
// @todo: Implement flagging_view(). Not extremely useful. I already have it.
@@ -432,10 +433,10 @@ function flag_permission() {
),
);
- $flags = flag_get_flags();
+ $flags = \Drupal::service('flag')->getFlags();
// Provide flag and unflag permissions for each flag.
foreach ($flags as $flag_name => $flag) {
- // $permissions += $flag->get_permissions();
+ $permissions += $flag->getPermissions();
}
return $permissions;
@@ -475,7 +476,7 @@ function flag_flag_link($flag, $action, $entity_id) {
function flag_field_extra_fields() {
$extra = array();
- $flags = flag_get_flags();
+ $flags = $flag_service->getFlags();
foreach ($flags as $name => $flag) {
// Skip flags that aren't on entities.
if (!($flag instanceof flag_entity)) {
@@ -763,7 +764,9 @@ function flag_contextual_links_view_alter(&$element, $items) {
*/
function flag_entity_view($entity, $type, $view_mode, $langcode) {
// Get all possible flags for this entity type.
- $flags = flag_get_flags($type);
+ $flag_service = \Drupal::service('flag');
+ $flags = $flag_service->getFlags($entity->entityType(),
+ $entity->bundle());
foreach ($flags as $flag) {
@@ -2330,15 +2333,6 @@ function flag_features_api() {
);
}
-/**
- * Implements hook_ctools_plugin_directory().
- */
-function flag_ctools_plugin_directory($module, $plugin) {
- if ($module == 'ctools' && !empty($plugin)) {
- return "plugins/$plugin";
- }
-}
-
// ---------------------------------------------------------------------------
// Entity Metadata callbacks
diff --git a/flag.services.yml b/flag.services.yml
index f144eed..8476cd3 100644
--- a/flag.services.yml
+++ b/flag.services.yml
@@ -5,3 +5,6 @@ services:
plugin.manager.flag.linktype:
class: Drupal\flag\ActionLinkPluginManager
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
+ flag:
+ class: Drupal\flag\Flag
+ arguments: ['@module_handler']
diff --git a/lib/Drupal/flag/Controller/FlagListController.php b/lib/Drupal/flag/Controller/FlagListController.php
index d19c2de..56219be 100644
--- a/lib/Drupal/flag/Controller/FlagListController.php
+++ b/lib/Drupal/flag/Controller/FlagListController.php
@@ -26,19 +26,19 @@ public function buildHeader() {
}
protected function getFlagRoles(FlagInterface $flag) {
- $allRoles = user_roles();
- $flagPermissions = $flag->getPermissions();
$out = '';
+ $allRoles = array();
- foreach ($flagPermissions['flag'] as $rid) {
- $out .= $allRoles[$rid]->label;
- $out .= ', ';
- }
+ foreach ($flag->getPermissions() as $perm => $pinfo) {
+ $roles = user_roles(FALSE, $perm);
- if (empty($out)) {
- return 'None';
+ foreach ($roles as $rid => $role) {
+ $allRoles[$rid] = $role->label;
+ }
}
+ $out = implode(', ', $allRoles);
+
return rtrim($out, ', ');
}
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 26bbe71..4774713 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -10,6 +10,7 @@
use Drupal\Component\Plugin\DefaultSinglePluginBag;
use Drupal\Compontent\Plugin\ConfigurablePluginInterface;
+use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Entity\Annotation\EntityType;
@@ -192,10 +193,10 @@ public function __construct(array $values, $entity_type) {
parent::__construct($values, $entity_type);
$this->flagTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.flagtype'),
- $this->flag_type, $this->flagTypeConfig);
+ array($this->flag_type), $this->flagTypeConfig);
$this->linkTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.linktype'),
- $this->link_type, $this->linkTypeConfig);
+ array($this->link_type), $this->linkTypeConfig);
}
public function enable() {
@@ -240,6 +241,11 @@ public function getFlagTypePlugin() {
public function setFlagTypePlugin($pluginID) {
$this->flag_type = $pluginID;
$this->flagTypeBag->addInstanceId($pluginID);
+
+ // Get the entity type from the plugin definition.
+ $plugin = $this->getFlagTypePlugin();
+ $pluginDef = $plugin->getPluginDefinition();
+ $this->entity_type = $pluginDef['entity_type'];
}
/**
@@ -265,10 +271,31 @@ public function setlinkTypePlugin($pluginID) {
/**
* @return array
*/
- public function getPermissions() {
+ public function getRoles() {
return $this->roles;
}
+ /**
+ * Provides permissions for this flag.
+ *
+ * @return
+ * An array of permissions for hook_permission().
+ */
+ function getPermissions() {
+ return array(
+ "flag $this->id" => array(
+ 'title' => t('Flag %flag_title', array(
+ '%flag_title' => $this->label,
+ )),
+ ),
+ "unflag $this->id" => array(
+ 'title' => t('Unflag %flag_title', array(
+ '%flag_title' => $this->label,
+ )),
+ ),
+ );
+ }
+
/**
* @param $roleID
* @param $canFlag
@@ -296,6 +323,22 @@ public function setPermissions(array $flagRoles, array $unflagRoles) {
);
}
+ public function canFlag(AccountInterface $account) {
+ if ($account->id() == 0) {
+ return TRUE;
+ }
+
+ if (in_array($account->getRoles(), $this->roles['flag'])) {
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+
+ public function canUnflag(AccountInterface $account) {
+ return TRUE;
+ }
+
public function isGlobal() {
return $this->is_global;
}
@@ -313,15 +356,39 @@ public function setGlobal($isGlobal = TRUE) {
* @param EntityStorageControllerInterface $storage_controller
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
- parent::preSave($storage_controller);
+ parent::preSave($storage_controller);
- // Save the Flag Type configuration.
- $flagTypePlugin = $this->getFlagTypePlugin();
- $this->set('flagTypeConfig', $flagTypePlugin->getConfiguration());
+ // Save the Flag Type configuration.
+ $flagTypePlugin = $this->getFlagTypePlugin();
+ $this->set('flagTypeConfig', $flagTypePlugin->getConfiguration());
- // Save the Link Type configuration.
- $linkTypePlugin = $this->getLinkTypePlugin();
- $this->set('linkTypeConfig', $linkTypePlugin->getConfiguration());
+ // Save the Link Type configuration.
+ $linkTypePlugin = $this->getLinkTypePlugin();
+ $this->set('linkTypeConfig', $linkTypePlugin->getConfiguration());
+
+ foreach ($this->roles['flag'] as $rid => $value) {
+
+ if (!empty($value)) {
+ user_role_change_permissions($rid, "flag $this->id");
+ }
+ }
+
+ foreach (user_roles() as $rid => $rinfo) {
+ $perms = array();
+
+ // Get the permissions from the $roles class variable.
+ foreach ($this->roles as $action => $roles) {
+ if (!empty($roles[$rid])) {
+ $perms["$action $this->id"] = TRUE;
+ }
+ else {
+ $perms["$action $this->id"] = FALSE;
+ }
+ }
+
+ // Assign the permissions.
+ user_role_change_permissions($rid, $perms);
+ }
}
public function getExportProperties() {
diff --git a/lib/Drupal/flag/Flag.php b/lib/Drupal/flag/Flag.php
index 9785935..cbf89ac 100644
--- a/lib/Drupal/flag/Flag.php
+++ b/lib/Drupal/flag/Flag.php
@@ -8,12 +8,24 @@
namespace Drupal\flag;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Session\AccountInterface;
+
/**
- * Static service container wrapper for Flag.
+ * Flag service.
*/
-class Flag {
+class Flag { //@todo Rename to FlagService?
- public static function flag($action, $flag_name, $entity_id, $account = NULL, $permissions_check = FALSE) {
+ /**
+ * Constructor.
+ *
+ * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+ */
+ public function __construct(ModuleHandlerInterface $module_handler) {
+ $this->moduleHandler = $module_handler;
+ }
+
+ public function flag($action, $flag_name, $entity_id, $account = NULL, $permissions_check = FALSE) {
}
@@ -29,7 +41,7 @@ public static function flag($action, $flag_name, $entity_id, $account = NULL, $p
*
* @see hook_flag_type_info()
*/
- public static function flag_fetch_definition($entity_type = NULL) {
+ public function fetchDefinition($entity_type = NULL) {
if(!empty($entity_type)){
return \Drupal::service('plugin.manager.flag.flagtype')->getDefinition($entity_type);
}
@@ -37,4 +49,50 @@ public static function flag_fetch_definition($entity_type = NULL) {
return \Drupal::service('plugin.manager.flag.flagtype')->getDefinitions();
}
+ /**
+ * List all flags available.
+ *
+ * If node type or account are entered, a list of all possible flags will be
+ * returned.
+ *
+ * @param $entity_type
+ * (optional) The type of entity for which to load the flags. Usually 'node'.
+ * @param $bundle
+ * (optional) The bundle for which to load the flags.
+ * @param $account
+ * (optional) The user account to filter available flags. If not set, all
+ * flags for the given entity and bundle will be returned.
+ *
+ * @return
+ * An array of the structure [fid] = flag_object.
+ */
+ public function getFlags($entity_type = NULL, $bundle = NULL, AccountInterface $account = NULL) {
+ $query = \Drupal::entityQuery('flag_flag');
+
+ if($entity_type != NULL) {
+ $query->condition('entity_type', $entity_type);
+ }
+
+ if ($bundle != NULL) {
+ $query->condition("types.$bundle", $bundle);
+ }
+
+ $result = $query->execute();
+
+ $flags = entity_load_multiple('flag_flag', $result);
+
+ if ($account == NULL) {
+ return $flags;
+ }
+
+ $filtered_flags = array();
+ foreach ($flags as $flag) {
+ if ($flag->canFlag($account) || $flag->canUnflag($account)) {
+ $filtered_flags[] = $flag;
+ }
+ }
+
+ return $filtered_flags;
+ }
+
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Form/FlagFormBase.php b/lib/Drupal/flag/Form/FlagFormBase.php
index 7a7669a..95249cd 100644
--- a/lib/Drupal/flag/Form/FlagFormBase.php
+++ b/lib/Drupal/flag/Form/FlagFormBase.php
@@ -151,7 +151,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
),
);
- $flag_permissions = $flag->getPermissions();
+ $flag_permissions = $flag->getRoles();
$form['access']['roles']['flag'] = array(
'#type' => 'checkboxes',
From 196b53f9c2b837d9589880cc01b7c0548b081895 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 16 Feb 2014 19:26:28 -0600
Subject: [PATCH 362/629] New FlaggingAccessController (untested), various
changes.
---
flag.module | 26 ++++----
.../flag/Controller/FlagListController.php | 1 +
lib/Drupal/flag/Entity/Flag.php | 2 +-
lib/Drupal/flag/Entity/Flagging.php | 60 +++++++++----------
lib/Drupal/flag/FlaggingAccessController.php | 46 ++++++++++++++
lib/Drupal/flag/Form/FlagFormBase.php | 9 +--
6 files changed, 95 insertions(+), 49 deletions(-)
create mode 100644 lib/Drupal/flag/FlaggingAccessController.php
diff --git a/flag.module b/flag.module
index b96707f..026dd70 100644
--- a/flag.module
+++ b/flag.module
@@ -77,17 +77,6 @@ function flag_query_flagging_flag_names_alter(QueryAlterableInterface $query) {
*/
function flag_menu() {
- $items[FLAG_ADMIN_PATH] = array(
- 'title' => 'Flags',
- // 'route_name' => 'flag_settings',
- 'description' => 'Configure flags for marking content with arbitrary information (such as offensive or bookmarked).',
-// );
-// $items[FLAG_ADMIN_PATH . '/list'] = array(
-// 'title' => 'List',
-// 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'route_name' => 'flag.flag_list',
- 'weight' => -10,
- );
$items[FLAG_ADMIN_PATH . '/add'] = array(
'route_name' => 'flag_add_page',
'type' => MENU_SIBLING_LOCAL_TASK,
@@ -181,6 +170,17 @@ function flag_menu() {
return $items;
}
+function flag_menu_link_defaults() {
+ $items['flag.admin.structure.flag'] = array(
+ 'link_title' => 'Flags',
+ 'parent' => 'system.admin.structure',
+ 'description' => 'Configure flags for marking content with arbitrary information (such as offensive or bookmarked).',
+ 'route_name' => 'flag.flag_list',
+ );
+
+ return $items;
+}
+
/**
* Implements hook_admin_menu_map().
*/
@@ -475,7 +475,7 @@ function flag_flag_link($flag, $action, $entity_id) {
*/
function flag_field_extra_fields() {
$extra = array();
-
+/*
$flags = $flag_service->getFlags();
foreach ($flags as $name => $flag) {
// Skip flags that aren't on entities.
@@ -506,7 +506,7 @@ function flag_field_extra_fields() {
}
}
}
-
+*/
return $extra;
}
diff --git a/lib/Drupal/flag/Controller/FlagListController.php b/lib/Drupal/flag/Controller/FlagListController.php
index 56219be..6b2db31 100644
--- a/lib/Drupal/flag/Controller/FlagListController.php
+++ b/lib/Drupal/flag/Controller/FlagListController.php
@@ -10,6 +10,7 @@
use Drupal\Core\Config\Entity\ConfigEntityListController;
use Drupal\Core\Entity\EntityInterface;
+use Drupal\flag\FlagInterface;
class FlagListController extends ConfigEntityListController {
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 4774713..fe91b63 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -369,7 +369,7 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
foreach ($this->roles['flag'] as $rid => $value) {
if (!empty($value)) {
- user_role_change_permissions($rid, "flag $this->id");
+ user_role_change_permissions($rid, array("flag $this->id"));
}
}
diff --git a/lib/Drupal/flag/Entity/Flagging.php b/lib/Drupal/flag/Entity/Flagging.php
index f81fc20..cc65e97 100644
--- a/lib/Drupal/flag/Entity/Flagging.php
+++ b/lib/Drupal/flag/Entity/Flagging.php
@@ -24,9 +24,11 @@
* module = "flag",
* controllers = {
* "storage" = "Drupal\Core\Entity\FieldableDatabaseStorageController",
+ * "access" = "Drupal\flag\FlaggingAccessController",
* },
* base_table = "flagging",
* fieldable = TRUE,
+ * bundle_entity_type = "flag",
* entity_keys = {
* "id" = "id",
* "bundle" = "type",
@@ -44,40 +46,36 @@ public function getFlag() {
}
public static function baseFieldDefinitions($entity_type) {
- $properties['id'] = array(
- 'label' => t('Flagging ID'),
- 'description' => t('The Flagging ID.'),
- 'type' => 'integer_field',
- 'read-only' => TRUE,
- );
- $properties['type'] = array(
- 'label' => t('Type'),
- 'description' => t('The flag type.'),
- 'type' => 'string_field',
- 'read-only' => TRUE,
- );
- $properties['uuid'] = array(
- 'label' => t('UUID'),
- 'description' => t('The node UUID.'),
- 'type' => 'uuid_field',
- 'read-only' => TRUE,
- );
- $properties['uid'] = array(
- 'label' => t('User ID'),
- 'description' => t('The ID of the flagging user.'),
- 'type' => 'entity_reference_field',
- 'settings' => array(
+ $fields['id'] = FieldDefinition::create('integer')
+ ->setLabel(t('Node ID'))
+ ->setDescription(t('The flagging ID.'))
+ ->setReadOnly(TRUE);
+
+ $fields['uuid'] = FieldDefinition::create('uuid')
+ ->setLabel(t('UUID'))
+ ->setDescription(t('The flagging UUID.'))
+ ->setReadOnly(TRUE);
+
+ $fields['type'] = FieldDefinition::create('entity_reference')
+ ->setLabel(t('Type'))
+ ->setDescription(t('The flag type.'))
+ ->setSetting('target_type', 'flag_flag')
+ ->setReadOnly(TRUE);
+
+ $fields['uid'] = FieldDefinition::create('entity_reference')
+ ->setLabel(t('User ID'))
+ ->setDescription(t('The user ID of the flagging user.'))
+ ->setSettings(array(
'target_type' => 'user',
'default_value' => 0,
- ),
- );
- $properties['created'] = array(
- 'label' => t('Created'),
- 'description' => t('The time that the flagging was created.'),
- 'type' => 'integer_field',
- );
+ ));
+
+ // @todo Convert to a "created" field in https://drupal.org/node/2145103.
+ $fields['created'] = FieldDefinition::create('integer')
+ ->setLabel(t('Created'))
+ ->setDescription(t('The time that the flagging was created.'));
- return $properties;
+ return $fields;
}
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/FlaggingAccessController.php b/lib/Drupal/flag/FlaggingAccessController.php
new file mode 100644
index 0000000..ce92935
--- /dev/null
+++ b/lib/Drupal/flag/FlaggingAccessController.php
@@ -0,0 +1,46 @@
+id(), $account);
+ break;
+
+ case 'delete':
+ case 'unflag':
+ return user_access('unflag' . $entity->id(), $account);
+ break;
+ }
+
+ return parent::checkAccess($entity, $operation, $langcode, $account);
+ }
+
+ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
+ return user_access('flag ' . $entity_bundle, $account);
+ }
+
+ public function getRoles() {
+ $roles = array();
+
+ $roles['flag'] = user_roles(FALSE, 'flag ' . $this->entityTypeId);
+ $roles['unflag'] = user_roles(FALSE, 'unflag ' . $this->entityTypeId);
+
+ return $roles;
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Form/FlagFormBase.php b/lib/Drupal/flag/Form/FlagFormBase.php
index 95249cd..fc7c6a9 100644
--- a/lib/Drupal/flag/Form/FlagFormBase.php
+++ b/lib/Drupal/flag/Form/FlagFormBase.php
@@ -151,6 +151,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
),
);
+ //@todo convert to Drupal::entityManager()->getAccessController('flagging');
$flag_permissions = $flag->getRoles();
$form['access']['roles']['flag'] = array(
@@ -252,16 +253,16 @@ public function save(array $form, array &$form_state) {
$flag->enable();
$status = $flag->save();
- $uri = $flag->uri();
+/* $url = $flag->url();
if ($status == SAVED_UPDATED) {
drupal_set_message(t('Flag %label has been updated.', array('%label' => $flag->label())));
- watchdog('flag', 'Flag %label has been updated.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'] . '/edit'));
+ watchdog('flag', 'Flag %label has been updated.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $url . '/edit'));
}
else {
drupal_set_message(t('Flag %label has been added.', array('%label' => $flag->label())));
- watchdog('flag', 'Flag %label has been added.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $uri['path'] . '/edit'));
+ watchdog('flag', 'Flag %label has been added.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $url . '/edit'));
}
-
+*/
// We clear caches more vigorously if the flag was new.
// _flag_clear_cache($flag->entity_type, !empty($flag->is_new));
From d8f9dd4c2b3fb1b731567f3a086f8b44c3c3314a Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 19 Feb 2014 18:34:39 -0600
Subject: [PATCH 363/629] Added use FieldDefinition to Flagging.php
---
lib/Drupal/flag/Entity/Flagging.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/Drupal/flag/Entity/Flagging.php b/lib/Drupal/flag/Entity/Flagging.php
index cc65e97..a30b8b3 100644
--- a/lib/Drupal/flag/Entity/Flagging.php
+++ b/lib/Drupal/flag/Entity/Flagging.php
@@ -12,6 +12,7 @@
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Session\AccountInterface;
+use Drupal\Core\Field\FieldDefinition;
use Drupal\flag\FlaggingInterface;
/**
@@ -36,6 +37,9 @@
* },
* bundle_keys = {
* "bundle" = "type"
+ * },
+ * links = {
+ * "admin-form" = "flag_edit"
* }
* )
*/
From 61a164fcf6923b68b3da2780a86eb4d325f5532d Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 19 Feb 2014 20:35:29 -0600
Subject: [PATCH 364/629] Removed custom Flag permissions UI.
---
.../flag/Controller/FlagListController.php | 2 +-
lib/Drupal/flag/Entity/Flag.php | 79 -------------------
lib/Drupal/flag/FlagInterface.php | 4 -
lib/Drupal/flag/Form/FlagFormBase.php | 43 +---------
4 files changed, 3 insertions(+), 125 deletions(-)
diff --git a/lib/Drupal/flag/Controller/FlagListController.php b/lib/Drupal/flag/Controller/FlagListController.php
index 6b2db31..c6b3481 100644
--- a/lib/Drupal/flag/Controller/FlagListController.php
+++ b/lib/Drupal/flag/Controller/FlagListController.php
@@ -29,7 +29,7 @@ public function buildHeader() {
protected function getFlagRoles(FlagInterface $flag) {
$out = '';
$allRoles = array();
-
+
foreach ($flag->getPermissions() as $perm => $pinfo) {
$roles = user_roles(FALSE, $perm);
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index fe91b63..d8112ad 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -181,11 +181,6 @@ class Flag extends ConfigEntityBase implements FlagInterface {
*/
public $weight = 0;
- protected $roles = array(
- 'flag' => array(),
- 'unflag' => array(),
- );
-
/**
* Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::__construct();
*/
@@ -268,13 +263,6 @@ public function setlinkTypePlugin($pluginID) {
$this->linkTypeBag->addInstanceId($pluginID);
}
- /**
- * @return array
- */
- public function getRoles() {
- return $this->roles;
- }
-
/**
* Provides permissions for this flag.
*
@@ -296,49 +284,6 @@ function getPermissions() {
);
}
- /**
- * @param $roleID
- * @param $canFlag
- * @param $canUnflag
- */
- public function setPermission($roleID, $canFlag, $canUnflag) {
- if (!$canFlag && !$canUnflag) {
- unset($this->roles[$roleID]);
- }
- else {
- $this->roles[$roleID] = array(
- 'flag' => $canFlag ? TRUE : FALSE,
- 'unflag' => $canUnflag ? TRUE : FALSE,
- );
- }
- }
-
- /**
- * @param array $flagPermssions
- */
- public function setPermissions(array $flagRoles, array $unflagRoles) {
- $this->roles = array(
- 'flag' => $flagRoles,
- 'unflag' => $unflagRoles,
- );
- }
-
- public function canFlag(AccountInterface $account) {
- if ($account->id() == 0) {
- return TRUE;
- }
-
- if (in_array($account->getRoles(), $this->roles['flag'])) {
- return TRUE;
- }
-
- return FALSE;
- }
-
- public function canUnflag(AccountInterface $account) {
- return TRUE;
- }
-
public function isGlobal() {
return $this->is_global;
}
@@ -365,30 +310,6 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
// Save the Link Type configuration.
$linkTypePlugin = $this->getLinkTypePlugin();
$this->set('linkTypeConfig', $linkTypePlugin->getConfiguration());
-
- foreach ($this->roles['flag'] as $rid => $value) {
-
- if (!empty($value)) {
- user_role_change_permissions($rid, array("flag $this->id"));
- }
- }
-
- foreach (user_roles() as $rid => $rinfo) {
- $perms = array();
-
- // Get the permissions from the $roles class variable.
- foreach ($this->roles as $action => $roles) {
- if (!empty($roles[$rid])) {
- $perms["$action $this->id"] = TRUE;
- }
- else {
- $perms["$action $this->id"] = FALSE;
- }
- }
-
- // Assign the permissions.
- user_role_change_permissions($rid, $perms);
- }
}
public function getExportProperties() {
diff --git a/lib/Drupal/flag/FlagInterface.php b/lib/Drupal/flag/FlagInterface.php
index d97b766..a25b3ea 100644
--- a/lib/Drupal/flag/FlagInterface.php
+++ b/lib/Drupal/flag/FlagInterface.php
@@ -20,10 +20,6 @@ public function disable();
public function getPermissions();
- public function setPermission($roleID, $canFlag, $canUnflag);
-
- public function setPermissions(array $flagRoles, array $unflagRoles);
-
public function isGlobal();
public function setGlobal($isGlobal);
diff --git a/lib/Drupal/flag/Form/FlagFormBase.php b/lib/Drupal/flag/Form/FlagFormBase.php
index fc7c6a9..433869f 100644
--- a/lib/Drupal/flag/Form/FlagFormBase.php
+++ b/lib/Drupal/flag/Form/FlagFormBase.php
@@ -13,15 +13,6 @@
abstract class FlagFormBase extends EntityFormController {
- protected function getRoleOptions() {
- $role_options = array();
-
- foreach (user_roles() as $rid => $role_info) {
- $role_options[$rid] = $role_info->label;
- }
-
- return $role_options;
- }
public function buildForm(array $form, array &$form_state, $entity_type = NULL) {
$form = parent::buildForm($form, $form_state);
@@ -139,36 +130,6 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'#weight' => 10,
);
- $form['access']['roles'] = array(
- '#title' => t('Roles that may use this flag'),
- '#description' => t('Users may only unflag content if they have access to flag the content initially. Checking authenticated user will allow access for all logged-in users.'),
- '#theme' => 'flag_form_roles',
- '#theme_wrappers' => array('form_element'),
- '#weight' => -2,
- '#attached' => array(
- 'js' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.js'),
- 'css' => array(drupal_get_path('module', 'flag') . '/theme/flag-admin.css'),
- ),
- );
-
- //@todo convert to Drupal::entityManager()->getAccessController('flagging');
- $flag_permissions = $flag->getRoles();
-
- $form['access']['roles']['flag'] = array(
- '#type' => 'checkboxes',
- '#title' => 'Roles that may flag',
- '#options' => $this->getRoleOptions(),
- '#default_value' => $flag_permissions['flag'],
- '#parents' => array('roles', 'flag'),
- );
- $form['access']['roles']['unflag'] = array(
- '#type' => 'checkboxes',
- '#title' => 'Roles that may unflag',
- '#options' => $this->getRoleOptions(),
- '#default_value' => $flag_permissions['unflag'],
- '#parents' => array('roles', 'unflag'),
- );
-
$form['access']['unflag_denied_text'] = array(
'#type' => 'textfield',
'#title' => t('Unflag not allowed text'),
@@ -253,7 +214,7 @@ public function save(array $form, array &$form_state) {
$flag->enable();
$status = $flag->save();
-/* $url = $flag->url();
+ $url = $flag->url();
if ($status == SAVED_UPDATED) {
drupal_set_message(t('Flag %label has been updated.', array('%label' => $flag->label())));
watchdog('flag', 'Flag %label has been updated.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $url . '/edit'));
@@ -262,7 +223,7 @@ public function save(array $form, array &$form_state) {
drupal_set_message(t('Flag %label has been added.', array('%label' => $flag->label())));
watchdog('flag', 'Flag %label has been added.', array('%label' => $flag->label()), WATCHDOG_NOTICE, l(t('Edit'), $url . '/edit'));
}
-*/
+
// We clear caches more vigorously if the flag was new.
// _flag_clear_cache($flag->entity_type, !empty($flag->is_new));
From 0445fddf9a55a9a47f88f4df39e70f8d129311c3 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 19 Feb 2014 20:42:54 -0600
Subject: [PATCH 365/629] Removed Flag import export stuff. Migrate path
planned instead.
---
flag.module | 15 -----
.../flag/Controller/FlagListController.php | 2 +-
lib/Drupal/flag/Export/FlagUpdate_2.php | 40 -------------
lib/Drupal/flag/Export/FlagUpdate_3.php | 58 -------------------
4 files changed, 1 insertion(+), 114 deletions(-)
delete mode 100644 lib/Drupal/flag/Export/FlagUpdate_2.php
delete mode 100644 lib/Drupal/flag/Export/FlagUpdate_3.php
diff --git a/flag.module b/flag.module
index 026dd70..aa0277a 100644
--- a/flag.module
+++ b/flag.module
@@ -87,21 +87,6 @@ function flag_menu() {
'route_name' => 'flag_add',
'type' => MENU_CALLBACK,
);
- $items[FLAG_ADMIN_PATH . '/import'] = array(
- 'title' => 'Import',
- 'route_name' => 'flag_import',
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 2,
- );
- $items[FLAG_ADMIN_PATH . '/export'] = array(
- 'title' => 'Export',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('flag_export_form'),
- 'access arguments' => array('administer flags'),
- 'file' => 'includes/flag.export.inc',
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 3,
- );
/*
$items[FLAG_ADMIN_PATH . '/manage/%flag'] = array(
'load arguments' => array(TRUE), // Allow for disabled flags.
diff --git a/lib/Drupal/flag/Controller/FlagListController.php b/lib/Drupal/flag/Controller/FlagListController.php
index c6b3481..6b2db31 100644
--- a/lib/Drupal/flag/Controller/FlagListController.php
+++ b/lib/Drupal/flag/Controller/FlagListController.php
@@ -29,7 +29,7 @@ public function buildHeader() {
protected function getFlagRoles(FlagInterface $flag) {
$out = '';
$allRoles = array();
-
+
foreach ($flag->getPermissions() as $perm => $pinfo) {
$roles = user_roles(FALSE, $perm);
diff --git a/lib/Drupal/flag/Export/FlagUpdate_2.php b/lib/Drupal/flag/Export/FlagUpdate_2.php
deleted file mode 100644
index 39dd989..0000000
--- a/lib/Drupal/flag/Export/FlagUpdate_2.php
+++ /dev/null
@@ -1,40 +0,0 @@
- API 2.
- *
- * The class name after the prefix is immaterial, though we follow the Drupal
- * system update convention whereby the number here is what we update to.
- */
-class FlagUpdate_2 {
-
- /**
- * The API version this class updates a flag from.
- *
- * @todo: Change this to a class constant when we drop support for PHP 5.2.
- */
- public $old_api_version = 1;
-
- /**
- * The API version this class updates a flag to.
- */
- public $new_api_version = 2;
-
- /**
- * The update function for the flag.
- */
- static function update(&$flag) {
- if (isset($flag->roles) && !isset($flag->roles['flag'])) {
- $flag->roles = array(
- 'flag' => $flag->roles,
- 'unflag' => $flag->roles,
- );
- }
- }
-}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Export/FlagUpdate_3.php b/lib/Drupal/flag/Export/FlagUpdate_3.php
deleted file mode 100644
index 4951c70..0000000
--- a/lib/Drupal/flag/Export/FlagUpdate_3.php
+++ /dev/null
@@ -1,58 +0,0 @@
- API 3.
- */
-class FlagUpdate_3 {
-
- public $old_api_version = 2;
- public $new_api_version = 3;
-
- static function update(&$flag) {
- // Change the content_type property to entity_type.
- if (isset($flag->content_type)) {
- $flag->entity_type = $flag->content_type;
- unset($flag->content_type);
- }
-
- // We can't convert the flag roles data to user permissions at this point
- // because the flag is disabled and hence hook_permission() doesn't see it
- // to define its permissions.
- // Instead, we copy it to import_roles, which the flag add form will handle
- // on new flags (which this flag will behave as when it is re-enabled).
- // @see flag_form()
- if (isset($flag->roles)) {
- $flag->import_roles = $flag->roles;
- }
-
- // Update show_on_teaser property to use new view mode settings.
- if (!empty($flag->show_on_teaser)) {
- $flag->show_in_links['teaser'] = TRUE;
- unset($flag->show_on_teaser);
- }
-
- // Update show_on_page property to use new view mode settings.
- if (!empty($flag->show_on_page)) {
- $flag->show_in_links['full'] = TRUE;
- unset($flag->show_on_page);
- }
-
- // Update show_on_comment and show_on_entity properties to use new view
- // mode settings. Since the old logic was to show on all view modes, do that.
- if (!empty($flag->show_on_entity) || !empty($flag->show_on_comment)) {
- if ($entity_info = entity_get_info($flag->entity_type)) {
- foreach ($entity_info['view modes'] as $view_mode => $value) {
- $flag->show_in_links[$view_mode] = TRUE;
- }
- }
-
- unset($flag->show_on_entity, $flag->show_on_comment);
- }
- }
-}
\ No newline at end of file
From fb27e5562c448613c5347a251e4ba93a628c6759 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 19 Feb 2014 20:56:34 -0600
Subject: [PATCH 366/629] Removed more flag permissions stuff.
---
lib/Drupal/flag/Controller/FlagListController.php | 4 ++++
lib/Drupal/flag/Form/FlagAddForm.php | 3 ---
lib/Drupal/flag/Form/FlagAddPageForm.php | 12 ------------
lib/Drupal/flag/Plugin/Flag/NodeFlagType.php | 6 +++---
4 files changed, 7 insertions(+), 18 deletions(-)
diff --git a/lib/Drupal/flag/Controller/FlagListController.php b/lib/Drupal/flag/Controller/FlagListController.php
index 6b2db31..d4fe8dc 100644
--- a/lib/Drupal/flag/Controller/FlagListController.php
+++ b/lib/Drupal/flag/Controller/FlagListController.php
@@ -40,6 +40,10 @@ protected function getFlagRoles(FlagInterface $flag) {
$out = implode(', ', $allRoles);
+ if (empty($out)) {
+ return 'None';
+ }
+
return rtrim($out, ', ');
}
diff --git a/lib/Drupal/flag/Form/FlagAddForm.php b/lib/Drupal/flag/Form/FlagAddForm.php
index a0a7cd3..fccc532 100644
--- a/lib/Drupal/flag/Form/FlagAddForm.php
+++ b/lib/Drupal/flag/Form/FlagAddForm.php
@@ -36,9 +36,6 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
// Mark the flag as new.
$flag->is_new = TRUE;
- $flag->setPermissions($this->getRoleDefault($step1_form['flag_role']),
- $this->getRoleDefault($step1_form['flag_role']));
-
$form = parent::buildForm($form, $form_state);
return $form;
diff --git a/lib/Drupal/flag/Form/FlagAddPageForm.php b/lib/Drupal/flag/Form/FlagAddPageForm.php
index cd9876a..ed37b98 100644
--- a/lib/Drupal/flag/Form/FlagAddPageForm.php
+++ b/lib/Drupal/flag/Form/FlagAddPageForm.php
@@ -67,18 +67,6 @@ public function buildForm(array $form, array &$form_state) {
'#options' => \Drupal::service('plugin.manager.flag.linktype')->getAllLinkTypes(),
);
- $role_options = array(0 => 'All users');
- foreach (user_roles() as $rid => $role_info) {
- $role_options[$rid] = $role_info->label;
- }
-
- $form['flag_type_info']['flag_role'] = array(
- '#type' => 'select',
- '#title' => t('for'),
- '#options' => $role_options,
- '#default' => 0,
- );
-
$types = array();
// @todo Use \Drupal::service() to get a list of FlagType plugins.
diff --git a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
index 5c1b4d7..023ddae 100644
--- a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
@@ -66,18 +66,18 @@ public function buildConfigurationForm(array $form, array &$form_state) {
);
// Override the UI texts for nodes.
- $form['display']['show_on_form'] = array(
+ /* $form['display']['show_on_form'] = array(
'#title' => t('Display checkbox on node edit form'),
'#description' => t('If you elect to have a checkbox on the node edit form, you may specify its initial state in the settings form for each content type.', array('@content-types-url' => url('admin/structure/types'))),
);// + $form['display']['show_on_form'];
-
+*/
return $form;
}
public function submitConfigurationForm(array &$form, array &$form_state) {
$this->configuration['access_author'] = $form_state['values']['access_author'];
$this->configuration['i18n'] = $form_state['values']['i18n'];
- $this->configuration['show_on_form'] = $form_state['values']['show_on_form'];
+// $this->configuration['show_on_form'] = $form_state['values']['show_on_form'];
}
function type_access_multiple($entity_ids, $account) {
From cd0f1221cf4d66fee8bc25137e917370060b69b6 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 19 Feb 2014 22:17:45 -0600
Subject: [PATCH 367/629] Fixed broken Entity::getEntityTypeID() API.
---
flag.module | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flag.module b/flag.module
index aa0277a..b53249a 100644
--- a/flag.module
+++ b/flag.module
@@ -750,7 +750,7 @@ function flag_contextual_links_view_alter(&$element, $items) {
function flag_entity_view($entity, $type, $view_mode, $langcode) {
// Get all possible flags for this entity type.
$flag_service = \Drupal::service('flag');
- $flags = $flag_service->getFlags($entity->entityType(),
+ $flags = $flag_service->getFlags($entity->getEntityTypeID(),
$entity->bundle());
foreach ($flags as $flag) {
From 71d90cf1dbfc7e0fc62a14a3dbee556cbf06f494 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sat, 22 Feb 2014 21:30:28 -0600
Subject: [PATCH 368/629] Renamed flag\Flag to flag\FlagService. Fixed flag
type plugin form build and submit.
---
flag.module | 24 ++++++++---
flag.services.yml | 2 +-
lib/Drupal/flag/{Flag.php => FlagService.php} | 2 +-
.../flag/Plugin/Flag/CommentFlagType.php | 7 ++-
.../flag/Plugin/Flag/EntityFlagType.php | 43 ++++++++++++-------
lib/Drupal/flag/Plugin/Flag/NodeFlagType.php | 18 ++++----
lib/Drupal/flag/Plugin/Flag/UserFlagType.php | 10 ++++-
7 files changed, 72 insertions(+), 34 deletions(-)
rename lib/Drupal/flag/{Flag.php => FlagService.php} (98%)
diff --git a/flag.module b/flag.module
index b53249a..39ae014 100644
--- a/flag.module
+++ b/flag.module
@@ -460,16 +460,18 @@ function flag_flag_link($flag, $action, $entity_id) {
*/
function flag_field_extra_fields() {
$extra = array();
-/*
+
+ $flag_service = \Drupal::service('flag');
$flags = $flag_service->getFlags();
- foreach ($flags as $name => $flag) {
+ foreach ($flags as $flag) {
// Skip flags that aren't on entities.
- if (!($flag instanceof flag_entity)) {
+ $flagTypePlugin = $flag->getFlagTypePlugin();
+ if (!($flagTypePlugin instanceof \Drupal\flag\Plugin\Flag\EntityFlagType)) {
continue;
}
foreach ($flag->types as $bundle_name) {
- if ($flag->show_on_form) {
+ if ($flagTypePlugin->showOnForm()) {
$extra[$flag->entity_type][$bundle_name]['form']['flag'] = array(
'label' => t('Flags'),
'description' => t('Checkboxes for toggling flags'),
@@ -477,13 +479,13 @@ function flag_field_extra_fields() {
);
}
- if ($flag->show_as_field) {
+ if ($flagTypePlugin->showAsField()) {
$extra[$flag->entity_type][$bundle_name]['display']['flag_' . $name] = array(
// It would be nicer to use % as the placeholder, but the label is
// run through check_plain() by field_ui_display_overview_form()
// (arguably incorrectly; see http://drupal.org/node/1991292).
'label' => t('Flag: @title', array(
- '@title' => $flag->title,
+ '@title' => $flag->label,
)),
'description' => t('Individual flag link'),
'weight' => 10,
@@ -491,7 +493,7 @@ function flag_field_extra_fields() {
}
}
}
-*/
+
return $extra;
}
@@ -533,6 +535,10 @@ function flag_form_node_type_form_alter(&$form, &$form_state, $form_id) {
}
}
+function flag_node_links_alter(array &$links, NodeInterface $entity, array &$context) {
+ //@todo: Define this for handling the showOnLinks() flag mode.
+}
+
/**
* Implements hook_field_attach_form().
*
@@ -748,6 +754,10 @@ function flag_contextual_links_view_alter(&$element, $items) {
* Note this is broken for taxonomy terms for version of Drupal core < 7.17.
*/
function flag_entity_view($entity, $type, $view_mode, $langcode) {
+
+ //@todo Check $type->getComponent('flag_whateverHookFieldExtraFieldsIS').
+ // if not NULL, display it.
+
// Get all possible flags for this entity type.
$flag_service = \Drupal::service('flag');
$flags = $flag_service->getFlags($entity->getEntityTypeID(),
diff --git a/flag.services.yml b/flag.services.yml
index 8476cd3..25b20ef 100644
--- a/flag.services.yml
+++ b/flag.services.yml
@@ -6,5 +6,5 @@ services:
class: Drupal\flag\ActionLinkPluginManager
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
flag:
- class: Drupal\flag\Flag
+ class: Drupal\flag\FlagService
arguments: ['@module_handler']
diff --git a/lib/Drupal/flag/Flag.php b/lib/Drupal/flag/FlagService.php
similarity index 98%
rename from lib/Drupal/flag/Flag.php
rename to lib/Drupal/flag/FlagService.php
index cbf89ac..256fd46 100644
--- a/lib/Drupal/flag/Flag.php
+++ b/lib/Drupal/flag/FlagService.php
@@ -14,7 +14,7 @@
/**
* Flag service.
*/
-class Flag { //@todo Rename to FlagService?
+class FlagService {
/**
* Constructor.
diff --git a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
index 28ed0c5..e8115f3 100644
--- a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
@@ -36,7 +36,7 @@ public function defaultConfiguration() {
* Options form extras for comment flags.
*/
public function buildConfigurationForm(array $form, array &$form_state) {
- parent::buildConfigurationForm($form, $form_state);
+ $form = parent::buildConfigurationForm($form, $form_state);
$form['access']['access_author'] = array(
'#type' => 'radios',
@@ -56,6 +56,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
}
public function submitConfigurationForm(array &$form, array &$form_state) {
+ parent::submitConfigurationForm($form, $form_state);
$this->configuration['access_author'] = $form_state['values']['access_author'];
}
@@ -82,4 +83,8 @@ public function type_access_multiple($entity_ids, $account) {
return $access;
}
+
+ function getAccessAuthorSetting() {
+ return $this->configuration['access_author'];
+ }
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
index 28d40e7..3a3cc73 100644
--- a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
@@ -24,18 +24,10 @@
*/
class EntityFlagType extends FlagTypeBase {
- public $types = array();
-
- public $show_in_links = array();
-
- public $show_as_field;
-
- public $show_on_form;
-
- public $show_contextual_link;
+ public $entity_type = '';
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
- array_push($this->types, $plugin_definition['entity_type']);
+ $this->entity_type = $plugin_definition['entity_type'];
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
@@ -52,7 +44,6 @@ public function defaultConfiguration() {
// Add a checkbox for the flag in the entity form.
// @see hook_field_attach_form().
'show_on_form' => FALSE,
- 'access_author' => '',
'show_contextual_link' => FALSE,
);
return $options;
@@ -62,7 +53,7 @@ public function defaultConfiguration() {
* Options form extras for the generic entity flag.
*/
public function buildConfigurationForm(array $form, array &$form_state) {
- /*
+
// Add checkboxes to show flag link on each entity view mode.
$options = array();
$defaults = array();
@@ -94,7 +85,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
$form['display']['show_on_form'] = array(
'#type' => 'checkbox',
'#title' => t('Display checkbox on entity edit form'),
- '#default_value' => $this->show_on_form,
+ '#default_value' => $this->showOnForm(),
'#weight' => 5,
);
@@ -109,13 +100,35 @@ public function buildConfigurationForm(array $form, array &$form_state) {
$form['display']['show_contextual_link'] = array(
'#type' => 'checkbox',
'#title' => t('Display in contextual links'),
- '#default_value' => $this->show_contextual_link,
+ '#default_value' => $this->showContextualLink(),
'#description' => t('Note that not all entity types support contextual links.'),
'#access' => module_exists('contextual'),
'#weight' => 10,
);
- */
+
return $form;
}
+ public function submitConfigurationForm(array &$form, array &$form_state) {
+ parent::submitConfigurationForm($form, $form_state);
+ $this->configuration['show_in_links'] = $form_state['values']['show_in_links'];
+ $this->configuration['show_on_form'] = $form_state['values']['show_on_form'];
+ $this->configuration['show_contextual_link'] = $form_state['values']['show_contextual_link'];
+ }
+
+ public function showInLinks() {
+ return $this->configuration['show_in_links'];
+ }
+
+ public function showAsField() {
+ return $this->configuration['show_as_field'];
+ }
+
+ public function showOnForm() {
+ return $this->configuration['show_on_form'];
+ }
+
+ public function showContextualLink() {
+ return $this->configuration['show_contextual_link'];
+ }
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
index 023ddae..3bd0ddd 100644
--- a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
@@ -37,7 +37,7 @@ public function defaultConfiguration() {
* Options form extras for node flags.
*/
public function buildConfigurationForm(array $form, array &$form_state) {
- parent::buildConfigurationForm($form, $form_state);
+ $form = parent::buildConfigurationForm($form, $form_state);
$form['access']['access_author'] = array(
'#type' => 'radios',
@@ -65,19 +65,13 @@ public function buildConfigurationForm(array $form, array &$form_state) {
'#weight' => 5,
);
- // Override the UI texts for nodes.
- /* $form['display']['show_on_form'] = array(
- '#title' => t('Display checkbox on node edit form'),
- '#description' => t('If you elect to have a checkbox on the node edit form, you may specify its initial state in the settings form for each content type.', array('@content-types-url' => url('admin/structure/types'))),
- );// + $form['display']['show_on_form'];
-*/
return $form;
}
public function submitConfigurationForm(array &$form, array &$form_state) {
+ parent::submitConfigurationForm($form, $form_state);
$this->configuration['access_author'] = $form_state['values']['access_author'];
$this->configuration['i18n'] = $form_state['values']['i18n'];
-// $this->configuration['show_on_form'] = $form_state['values']['show_on_form'];
}
function type_access_multiple($entity_ids, $account) {
@@ -100,4 +94,12 @@ function type_access_multiple($entity_ids, $account) {
return $access;
}
+
+ function getAccessAuthorSetting() {
+ return $this->configuration['access_author'];
+ }
+
+ function getInternationalizationSetting() {
+ $this->configuration['i18n'];
+ }
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
index bbe1f29..014ef7d 100644
--- a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/UserFlagType.php
@@ -35,7 +35,7 @@ public function defaultConfiguration() {
* Options form extras for user flags.
*/
public function buildConfigurationForm(array $form, array &$form_state) {
- parent::buildConfigurationForm($form, $form_state);
+ $form = parent::buildConfigurationForm($form, $form_state);
$form['access']['types'] = array(
// A user flag doesn't support node types.
// TODO: Maybe support roles instead of node types.
@@ -61,6 +61,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
}
public function submitConfigurationForm(array &$form, array &$form_state) {
+ parent::submitConfigurationForm($form, $form_state);
$this->configuration['access_uid'] = $form_state['values']['access']['access_uid'];
$this->configuration['show_on_profile'] = $form_state['values']['display']['show_on_profile'];
}
@@ -81,4 +82,11 @@ function type_access_multiple($entity_ids, $account) {
return $access;
}
+ public function getAccessUidSetting() {
+ return $this->configuration['access_uid'];
+ }
+
+ public function showOnProfile() {
+ return this->configuration['show_on_profile'];
+ }
}
\ No newline at end of file
From 22b96d15c3b076013039d7aefc033cc959eeb7c7 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sat, 22 Feb 2014 23:21:30 -0600
Subject: [PATCH 369/629] Working psudofields.
---
flag.module | 2 +-
lib/Drupal/flag/Plugin/Flag/EntityFlagType.php | 9 +++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/flag.module b/flag.module
index 39ae014..84844e7 100644
--- a/flag.module
+++ b/flag.module
@@ -480,7 +480,7 @@ function flag_field_extra_fields() {
}
if ($flagTypePlugin->showAsField()) {
- $extra[$flag->entity_type][$bundle_name]['display']['flag_' . $name] = array(
+ $extra[$flag->entity_type][$bundle_name]['display']['flag_' . $flag->label()] = array(
// It would be nicer to use % as the placeholder, but the label is
// run through check_plain() by field_ui_display_overview_form()
// (arguably incorrectly; see http://drupal.org/node/1991292).
diff --git a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
index 3a3cc73..98c862f 100644
--- a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
@@ -77,11 +77,11 @@ public function buildConfigurationForm(array $form, array &$form_state) {
'#description' => t('Show the flag link as a pseudofield, which can be ordered among other entity elements in the "Manage display" settings for the entity type.'),
'#default_value' => isset($this->show_as_field) ? $this->show_as_field : TRUE,
);
- if (empty($entity_info['fieldable'])) {
+ /* if (empty($entity_info['fieldable'])) {
$form['display']['show_as_field']['#disabled'] = TRUE;
$form['display']['show_as_field']['#description'] = t("This entity type is not fieldable.");
}
-
+*/
$form['display']['show_on_form'] = array(
'#type' => 'checkbox',
'#title' => t('Display checkbox on entity edit form'),
@@ -93,11 +93,11 @@ public function buildConfigurationForm(array $form, array &$form_state) {
// require the entity to be fielable. Since this is a potential DX
// headscratcher for a developer wondering where this option has gone,
// we disable it and explain why.
- if (empty($entity_info['fieldable'])) {
+ /* if (empty($entity_info['fieldable'])) {
$form['display']['show_on_form']['#disabled'] = TRUE;
$form['display']['show_on_form']['#description'] = t('This is only possible on entities which are fieldable.');
}
- $form['display']['show_contextual_link'] = array(
+*/ $form['display']['show_contextual_link'] = array(
'#type' => 'checkbox',
'#title' => t('Display in contextual links'),
'#default_value' => $this->showContextualLink(),
@@ -112,6 +112,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
public function submitConfigurationForm(array &$form, array &$form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['show_in_links'] = $form_state['values']['show_in_links'];
+ $this->configuration['show_as_field'] = $form_state['values']['show_as_field'];
$this->configuration['show_on_form'] = $form_state['values']['show_on_form'];
$this->configuration['show_contextual_link'] = $form_state['values']['show_contextual_link'];
}
From 3868837282f892eee49f588f37fd351f1a3b14a0 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Tue, 11 Mar 2014 23:32:34 -0500
Subject: [PATCH 370/629] New link render chain using link type plugins.
---
flag.module | 33 +++----
flag.routing.yml | 11 +++
lib/Drupal/flag/ActionLinkTypeBase.php | 49 +++++++++-
.../flag/ActionLinkTypePluginInterface.php | 12 ++-
.../flag/Controller/ReloadLinkController.php | 26 ++++++
lib/Drupal/flag/Entity/Flag.php | 12 +--
lib/Drupal/flag/FlagInterface.php | 4 +
lib/Drupal/flag/FlagService.php | 16 +++-
lib/Drupal/flag/Form/FlagAddPageForm.php | 2 +
lib/Drupal/flag/Form/FlaggingConfirmForm.php | 65 ++++++++++++++
.../flag/Plugin/ActionLink/ConfirmForm.php | 90 +++++++++++++++++++
lib/Drupal/flag/Plugin/ActionLink/Reload.php | 4 +-
12 files changed, 288 insertions(+), 36 deletions(-)
create mode 100644 lib/Drupal/flag/Controller/ReloadLinkController.php
create mode 100644 lib/Drupal/flag/Form/FlaggingConfirmForm.php
create mode 100644 lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php
diff --git a/flag.module b/flag.module
index 84844e7..0f4492c 100644
--- a/flag.module
+++ b/flag.module
@@ -12,6 +12,7 @@ define('FLAG_ADMIN_PATH_START', 3);
use Drupal\flag\Handlers\AbstractFlag;
use Drupal\flag\Flag;
+use Drupal\node\NodeInterface;
// @todo: Implement flagging_view(). Not extremely useful. I already have it.
@@ -435,7 +436,7 @@ function flag_permission() {
*/
function flag_form_user_admin_permissions_alter(&$form, &$form_state, $form_id) {
if (!module_exists('session_api')) {
- $flags = flag_get_flags();
+ $flags = \Drupal::service('flag')->getFlags();
// Disable flag and unflag permission checkboxes for anonymous users.
foreach ($flags as $flag_name => $flag) {
$form['checkboxes'][DRUPAL_ANONYMOUS_RID]["flag $flag_name"]['#disabled'] = TRUE;
@@ -502,7 +503,7 @@ function flag_field_extra_fields() {
*/
function flag_form_node_type_form_alter(&$form, &$form_state, $form_id) {
global $user;
- $flags = flag_get_flags('node', $form['#node_type']->type, $user);
+ $flags = \Drupal::service('flag')->getFlags('node', $form['#node_type']->type, $user);
foreach ($flags as $flag) {
if ($flag->show_on_form) {
// To be able to process node tokens in flag labels, we create a fake
@@ -558,7 +559,7 @@ function flag_field_attach_form($entity_type, $entity, &$form, &$form_state, $la
}
// Get all possible flags for this entity type.
- $flags = flag_get_flags($entity_type);
+ $flags = \Drupal::service('flag')->getFlags($entity_type);
// Filter out flags which need to be included on the node form.
$flags_in_form = 0;
@@ -753,7 +754,7 @@ function flag_contextual_links_view_alter(&$element, $items) {
*
* Note this is broken for taxonomy terms for version of Drupal core < 7.17.
*/
-function flag_entity_view($entity, $type, $view_mode, $langcode) {
+function flag_entity_view($entity, $display, $view_mode, $langcode) {
//@todo Check $type->getComponent('flag_whateverHookFieldExtraFieldsIS').
// if not NULL, display it.
@@ -764,27 +765,15 @@ function flag_entity_view($entity, $type, $view_mode, $langcode) {
$entity->bundle());
foreach ($flags as $flag) {
+ $linkTypePlugin = $flag->getLinkTypePlugin();
+ $action = 'flag';
- if($flag->isFlagged()) {
- $action_link_url = "/unflag";
- }
- else {
- $action_link_url = "/flag";
+ if ($flag->isFlagged($entity)) {
+ $action = 'unflag';
}
- $action_link_url .= "/" . $flag->id . "/" . $entity->id();
-
- $entity->content['flag_' . $flag->id] = array(
- '#markup' => '' . l($flag->flag_short, $action_link_url) . '
',
- '#weight' => 10,
- );
-/*
- $links = array(
- '#prefix' => '',
- '#markup' => l($flag->flag_short, $action_link_url),
- '#suffix' => '
',
- );
-*/
+ $link = $linkTypePlugin->renderLink($action, $flag, $entity);
+ $entity->content['flag_' . $flag->id] = $link;
}
/**
diff --git a/flag.routing.yml b/flag.routing.yml
index bc999cf..c2e6011 100644
--- a/flag.routing.yml
+++ b/flag.routing.yml
@@ -53,3 +53,14 @@ flag_export:
_title: 'Export Flags'
requirements:
_permission: 'use flag import'
+
+flag_link:
+ path: '/flag/{action}/{flag}/{entity}'
+ defaults:
+ _controller: '\Drupal\flag\Controller\ReloadLinkController::flag'
+
+flag_confirm_form:
+ path: '/flag/confirm/{action}/{flag}/{entity}'
+ defaults:
+ _form: '\Drupal\flag\Form\FlaggingConfirmForm'
+ _title: 'Flag Content'
diff --git a/lib/Drupal/flag/ActionLinkTypeBase.php b/lib/Drupal/flag/ActionLinkTypeBase.php
index e9ff196..7283cbd 100644
--- a/lib/Drupal/flag/ActionLinkTypeBase.php
+++ b/lib/Drupal/flag/ActionLinkTypeBase.php
@@ -8,8 +8,13 @@
namespace Drupal\flag;
+use Drupal\Core\URL;
+use Drupal\Core\Entity\EntityInterface;
+use \Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Component\Plugin\PluginBase;
+use Drupal\flag\FlagInterface;
use Drupal\flag\ActionLinkTypePluginInterface;
+use Drupal\flag\FlagService;
/**
* Class ActionLinkTypeBase
@@ -28,11 +33,51 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
$this->setConfiguration($configuration);
}
+ // @todo Add display, langcode, and view mode to buildLink()?
+ public function link(FlagInterface $flag, EntityInterface $entity,
+ EntityViewDisplayInterface $diplay, $view_mode, $langcode) {
+
+ if($flag->isFlagged()) {
+ $action_link_url = "/unflag";
+ }
+ else {
+ $action_link_url = "/flag";
+ }
+
+ $action_link_url .= "/" . $flag->id . "/" . $entity->id();
+
+ return l($flag->flag_short, $action_link_url);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ abstract public function routeName();
+
/**
* @return string
*/
- public function buildLink() {
- return "";
+ public function buildLink($action, FlagInterface $flag, EntityInterface $entity) {
+ $options = array(
+ 'action' => $action,
+ 'flag' => $flag->id(),
+ 'entity' => $entity->id(),
+ );
+
+ return new URL($this->routeName(), $options);
+ }
+
+ public function renderLink($action, FlagInterface $flag, EntityInterface $entity) {
+ $url = $this->buildLink($action, $flag, $entity);
+
+ $url->setOption('destination', \Drupal::request()->attributes->get('_system_path'));
+ $url->setOption('alt', $flag->flag_long);
+
+ $render = $url->toRenderArray();
+ $render['#type'] = 'link';
+ $render['#title'] = $flag->flag_short;
+
+ return $render;
}
/**
diff --git a/lib/Drupal/flag/ActionLinkTypePluginInterface.php b/lib/Drupal/flag/ActionLinkTypePluginInterface.php
index ae95739..498b70d 100644
--- a/lib/Drupal/flag/ActionLinkTypePluginInterface.php
+++ b/lib/Drupal/flag/ActionLinkTypePluginInterface.php
@@ -8,6 +8,8 @@
namespace Drupal\flag;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\flag\FlagInterface;
use Drupal\Core\Plugin\PluginFormInterface;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
@@ -17,6 +19,14 @@
*/
interface ActionLinkTypePluginInterface extends PluginFormInterface, ConfigurablePluginInterface {
- public function buildLink();
+ public function buildLink($action, FlagInterface $flag, EntityInterface $entity);
+
+ public function renderLink($action, FlagInterface $flag, EntityInterface $entity);
+
+ /**
+ * @return string
+ * A string containing the route name.
+ */
+ public function routeName();
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Controller/ReloadLinkController.php b/lib/Drupal/flag/Controller/ReloadLinkController.php
new file mode 100644
index 0000000..66972a8
--- /dev/null
+++ b/lib/Drupal/flag/Controller/ReloadLinkController.php
@@ -0,0 +1,26 @@
+flag($flag, $entity);
+ }
+ else if ($action == 'unflag') {
+ \Drupal::service('flag')->unflag($flag, $entity);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index d8112ad..e857c1c 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -10,6 +10,7 @@
use Drupal\Component\Plugin\DefaultSinglePluginBag;
use Drupal\Compontent\Plugin\ConfigurablePluginInterface;
+use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageControllerInterface;
@@ -202,16 +203,17 @@ public function disable() {
$this->enabled = FALSE;
}
- public function isFlagged(AccountInterface $account = NULL) {
+ public function isFlagged(EntityInterface $entity, AccountInterface $account = NULL) {
if($account == NULL) {
global $user;
$account = $user;
}
- $query = \Drupal::entityQuery('flagging');
- $query->condition('uid', $account->id());
-
- $result = $query->execute();
+ $result = \Drupal::entityQuery('flagging')
+ ->condition('uid', $account->id())
+ ->condition('fid', $this->id())
+ ->condition('entity_id', $entity->id())
+ ->execute();
if (isset($result['node'])) {
$flagging_ids = array_keys($result['flagging']);
diff --git a/lib/Drupal/flag/FlagInterface.php b/lib/Drupal/flag/FlagInterface.php
index a25b3ea..43fcdad 100644
--- a/lib/Drupal/flag/FlagInterface.php
+++ b/lib/Drupal/flag/FlagInterface.php
@@ -9,6 +9,8 @@
namespace Drupal\flag;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Session\AccountInterface;
interface FlagInterface extends ConfigEntityInterface {
@@ -18,6 +20,8 @@ public function enable();
public function disable();
+ public function isFlagged(EntityInterface $entity, AccountInterface $account = NULL);
+
public function getPermissions();
public function isGlobal();
diff --git a/lib/Drupal/flag/FlagService.php b/lib/Drupal/flag/FlagService.php
index 256fd46..7ad2d5b 100644
--- a/lib/Drupal/flag/FlagService.php
+++ b/lib/Drupal/flag/FlagService.php
@@ -25,10 +25,6 @@ public function __construct(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
- public function flag($action, $flag_name, $entity_id, $account = NULL, $permissions_check = FALSE) {
-
- }
-
/**
* Get a flag type definition.
*
@@ -95,4 +91,16 @@ public function getFlags($entity_type = NULL, $bundle = NULL, AccountInterface $
return $filtered_flags;
}
+ public function getFlaggings(EntityInterface $entity, FlagInterface $flag, AccountInterface $account = NULL) {
+
+ }
+
+ public function flag(EntityInterface $entity, FlagInterface $flag, AccountInterface $account = NULL) {
+
+ }
+
+ public function unflag(FlaggingInterface $flagging) {
+
+ }
+
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Form/FlagAddPageForm.php b/lib/Drupal/flag/Form/FlagAddPageForm.php
index ed37b98..4a18772 100644
--- a/lib/Drupal/flag/Form/FlagAddPageForm.php
+++ b/lib/Drupal/flag/Form/FlagAddPageForm.php
@@ -59,12 +59,14 @@ public function buildForm(array $form, array &$form_state) {
'#type' => 'select',
'#title' => t('Flag'),
'#options' => \Drupal::service('plugin.manager.flag.flagtype')->getAllFlagTypes(),
+ '#default_value' => 'flagtype_node',
);
$form['flag_type_info']['flag_link_type'] = array(
'#type' => 'select',
'#title' => t('using'),
'#options' => \Drupal::service('plugin.manager.flag.linktype')->getAllLinkTypes(),
+ '#default_value' => 'reload',
);
$types = array();
diff --git a/lib/Drupal/flag/Form/FlaggingConfirmForm.php b/lib/Drupal/flag/Form/FlaggingConfirmForm.php
new file mode 100644
index 0000000..11e8d59
--- /dev/null
+++ b/lib/Drupal/flag/Form/FlaggingConfirmForm.php
@@ -0,0 +1,65 @@
+action = $action;
+ $this->flag = $flag;
+ $this->entity = $entity;
+ }
+
+ public function getFormID() {
+ return 'flag_flagging_confirm_form';
+ }
+
+ public function getQuestion() {
+ $linkType = $this->flag->getLinkTypePlugin();
+
+ if ($action == 'unflag') {
+ return $linkType->getUnflagQuestion();
+ }
+ else {
+ return $linkType->getFlagQuestion();
+ }
+
+ }
+
+ public function getCancelRoute() {
+ return $this->entity->urlInfo();
+ }
+
+ public function getDescription() {
+ return $this->t('');
+ }
+
+ public function getConfirmText() {
+ return $this->t('Flag');
+ }
+
+ public function submitForm(array &$form, array &$form_state) {
+
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php b/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php
new file mode 100644
index 0000000..c2ff2e9
--- /dev/null
+++ b/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php
@@ -0,0 +1,90 @@
+ '',
+ 'unflag_confirmation' => '',
+ );
+
+ return $options;
+ }
+
+ public function buildConfigurationForm(array $form, array &$form_state) {
+ $form = parent::buildConfigurationForm($form, $form_state);
+
+
+ $form['display']['link_options_confirm'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Options for the "Confirmation form" link type'),
+ // Any "link type" provider module must put its settings fields inside
+ // a fieldset whose HTML ID is link-options-LINKTYPE, where LINKTYPE is
+ // the machine-name of the link type. This is necessary for the
+ // radiobutton's JavaScript dependency feature to work.
+ '#id' => 'link-options-confirm',
+ '#weight' => 21,
+ );
+
+ $form['display']['link_options_confirm']['flag_confirmation'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Flag confirmation message'),
+ '#default_value' => $this->configuration['flag_confirmation'],
+ '#description' => t('Message displayed if the user has clicked the "flag this" link and confirmation is required. Usually presented in the form of a question such as, "Are you sure you want to flag this content?"'),
+ // This will get changed to a state by flag_link_type_options_states().
+ '#required' => TRUE,
+ );
+
+ $form['display']['link_options_confirm']['unflag_confirmation'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Unflag confirmation message'),
+ '#default_value' => $this->configuration['unflag_confirmation'],
+ '#description' => t('Message displayed if the user has clicked the "unflag this" link and confirmation is required. Usually presented in the form of a question such as, "Are you sure you want to unflag this content?"'),
+ // This will get changed to a state by flag_link_type_options_states().
+ '#required' => TRUE,
+ );
+
+ return $form;
+ }
+
+ public function submitConfigurationForm(array &$form, array &$form_state) {
+ parent::submitConfigurationForm($form, $form_state);
+ $this->configuration['flag_confirmation'] = $form_state['values']['flag_confirmation'];
+ $this->configuration['unflag_confirmation'] = $form_state['values']['unflag_confirmation'];
+ }
+
+ public function getFlagQuestion() {
+ return $this->configuration['flag_confirmation'];
+ }
+
+ public function getUnflagQuestion() {
+ return $this->configuration['unflag_confirmation'];
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/ActionLink/Reload.php b/lib/Drupal/flag/Plugin/ActionLink/Reload.php
index 1ab3889..0075cad 100644
--- a/lib/Drupal/flag/Plugin/ActionLink/Reload.php
+++ b/lib/Drupal/flag/Plugin/ActionLink/Reload.php
@@ -24,8 +24,8 @@ class Reload extends ActionLinkTypeBase {
/**
* @return string
*/
- public function buildLink() {
- return "/flag/";
+ public function routeName() {
+ return 'flag_link';
}
}
\ No newline at end of file
From b05a159b00cd24fbb1d522b4398406e81fd25c1f Mon Sep 17 00:00:00 2001
From: socketwench
Date: Tue, 25 Mar 2014 22:58:41 -0500
Subject: [PATCH 371/629] Multiple updates due to changes in core.
---
flag.local_actions.yml | 2 +-
flag.module | 14 +++++++-------
flag.routing.yml | 2 +-
lib/Drupal/flag/ActionLinkPluginManager.php | 6 +++---
lib/Drupal/flag/ActionLinkTypeBase.php | 16 ----------------
.../flag/Controller/FlagListController.php | 4 ++--
lib/Drupal/flag/Entity/Flag.php | 17 +++++++----------
lib/Drupal/flag/Entity/Flagging.php | 3 ++-
lib/Drupal/flag/FlagTypePluginManager.php | 4 ++--
lib/Drupal/flag/Form/FlagAddForm.php | 4 ++++
.../flag/Plugin/Derivative/EntityFlagType.php | 4 ++--
lib/Drupal/flag/Plugin/Flag/NodeFlagType.php | 1 +
12 files changed, 32 insertions(+), 45 deletions(-)
diff --git a/flag.local_actions.yml b/flag.local_actions.yml
index b9b57dc..9b9f593 100644
--- a/flag.local_actions.yml
+++ b/flag.local_actions.yml
@@ -2,4 +2,4 @@ flag_add_page_action:
route_name: flag_add_page
title: 'Add New Flag'
appears_on:
- - flag.flag_list
\ No newline at end of file
+ - flag_list
\ No newline at end of file
diff --git a/flag.module b/flag.module
index 0f4492c..92bb34d 100644
--- a/flag.module
+++ b/flag.module
@@ -159,9 +159,9 @@ function flag_menu() {
function flag_menu_link_defaults() {
$items['flag.admin.structure.flag'] = array(
'link_title' => 'Flags',
- 'parent' => 'system.admin.structure',
+ 'parent' => 'system.admin_structure',
'description' => 'Configure flags for marking content with arbitrary information (such as offensive or bookmarked).',
- 'route_name' => 'flag.flag_list',
+ 'route_name' => 'flag_list',
);
return $items;
@@ -341,14 +341,14 @@ function flag_help($path, $arg) {
function flag_fetch_definition($entity_type = NULL) {
$definitions = &drupal_static(__FUNCTION__);
if (!isset($definitions)) {
- if ($cache = cache()->get('flag_type_info')) {
+ if ($cache = \Drupal::cache()->get('flag_type_info')) {
$definitions = $cache->data;
}
else {
$definitions = module_invoke_all('flag_type_info');
drupal_alter('flag_type_info', $definitions);
- cache()->set('flag_type_info', $definitions);
+ \Drupal::cache()->set('flag_type_info', $definitions);
}
}
@@ -2101,10 +2101,10 @@ function flag_get_link_types() {
$link_types = &drupal_static(__FUNCTION__);
if (!isset($link_types)) {
- if ($cache = cache()->get('flag_link_type_info')) {
+ if ($cache = \Drupal::cache()->get('flag_link_type_info')) {
$link_types = $cache->data;
}
- // In some rare edge cases cache()->get() can return an empty result. If it
+ // In some rare edge cases \Drupal::cache()->get() can return an empty result. If it
// does, we make sure to fetch the link types again.
if (empty($link_types)) {
$link_types = array();
@@ -2125,7 +2125,7 @@ function flag_get_link_types() {
}
drupal_alter('flag_link_type_info', $link_types);
- cache()->set('flag_link_type_info', $link_types);
+ \Drupal::cache()->set('flag_link_type_info', $link_types);
}
}
diff --git a/flag.routing.yml b/flag.routing.yml
index c2e6011..5247a8b 100644
--- a/flag.routing.yml
+++ b/flag.routing.yml
@@ -6,7 +6,7 @@ flag_add_page:
requirements:
_permission: 'administer flags'
-flag.flag_list:
+flag_list:
path: '/admin/structure/flags'
defaults:
_entity_list: 'flag_flag'
diff --git a/lib/Drupal/flag/ActionLinkPluginManager.php b/lib/Drupal/flag/ActionLinkPluginManager.php
index 1841988..89ad00d 100644
--- a/lib/Drupal/flag/ActionLinkPluginManager.php
+++ b/lib/Drupal/flag/ActionLinkPluginManager.php
@@ -21,9 +21,9 @@ class ActionLinkPluginManager extends DefaultPluginManager {
* {@inheritdoc}
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
- parent::__construct('Plugin/ActionLink', $namespaces, 'Drupal\flag\Annotation\ActionLinkType');
- $this->alterInfo($module_handler, 'flag_link_type_info');
- $this->setCacheBackend($cache_backend, $language_manager, 'flag_link_type_info');
+ parent::__construct('Plugin/ActionLink', $namespaces, $module_handler, 'Drupal\flag\Annotation\ActionLinkType');
+ $this->alterInfo('flag_link_type_info');
+ $this->setCacheBackend($cache_backend, $language_manager, 'flag_link_type_plugins');
}
public function getAllLinkTypes() {
diff --git a/lib/Drupal/flag/ActionLinkTypeBase.php b/lib/Drupal/flag/ActionLinkTypeBase.php
index 7283cbd..9eec7ae 100644
--- a/lib/Drupal/flag/ActionLinkTypeBase.php
+++ b/lib/Drupal/flag/ActionLinkTypeBase.php
@@ -33,22 +33,6 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
$this->setConfiguration($configuration);
}
- // @todo Add display, langcode, and view mode to buildLink()?
- public function link(FlagInterface $flag, EntityInterface $entity,
- EntityViewDisplayInterface $diplay, $view_mode, $langcode) {
-
- if($flag->isFlagged()) {
- $action_link_url = "/unflag";
- }
- else {
- $action_link_url = "/flag";
- }
-
- $action_link_url .= "/" . $flag->id . "/" . $entity->id();
-
- return l($flag->flag_short, $action_link_url);
- }
-
/**
* @inheritDoc
*/
diff --git a/lib/Drupal/flag/Controller/FlagListController.php b/lib/Drupal/flag/Controller/FlagListController.php
index d4fe8dc..44aaede 100644
--- a/lib/Drupal/flag/Controller/FlagListController.php
+++ b/lib/Drupal/flag/Controller/FlagListController.php
@@ -8,11 +8,11 @@
namespace Drupal\flag\Controller;
-use Drupal\Core\Config\Entity\ConfigEntityListController;
+use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\flag\FlagInterface;
-class FlagListController extends ConfigEntityListController {
+class FlagListController extends ConfigEntityListBuilder {
/**
* Overrides Drupal\Core\Entity\EntityListController::buildHeader().
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index e857c1c..8b2ae1a 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -8,7 +8,7 @@
namespace Drupal\flag\Entity;
-use Drupal\Component\Plugin\DefaultSinglePluginBag;
+use Drupal\Core\Plugin\DefaultSinglePluginBag;
use Drupal\Compontent\Plugin\ConfigurablePluginInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
@@ -22,14 +22,12 @@
* Class Flag
* @package Drupal\flag\Entity
*
- * @EntityType(
+ * @ConfigEntityType(
* id = "flag_flag",
* label = @Translation("Flag"),
- * module = "flag",
* admin_permission = "administer flags",
* controllers = {
- * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController",
- * "list" = "Drupal\flag\Controller\FlagListController",
+ * "list_builder" = "Drupal\flag\Controller\FlagListController",
* "form" = {
* "add" = "Drupal\flag\Form\FlagAddForm",
* "edit" = "Drupal\flag\Form\FlagEditForm",
@@ -37,14 +35,13 @@
* }
* },
* bundle_of = "flagging",
- * config_prefix = "flag.flag",
* entity_keys = {
* "id" = "id",
* "label" = "label",
- * "uuid" = "uuid"
* },
* links = {
- * "edit-form" = "flag_edit"
+ * "edit-form" = "flag_edit",
+ * "delete-form" = "flag_delete"
* }
* )
*
@@ -189,10 +186,10 @@ public function __construct(array $values, $entity_type) {
parent::__construct($values, $entity_type);
$this->flagTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.flagtype'),
- array($this->flag_type), $this->flagTypeConfig);
+ $this->flag_type, $this->flagTypeConfig);
$this->linkTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.linktype'),
- array($this->link_type), $this->linkTypeConfig);
+ $this->link_type, $this->linkTypeConfig);
}
public function enable() {
diff --git a/lib/Drupal/flag/Entity/Flagging.php b/lib/Drupal/flag/Entity/Flagging.php
index a30b8b3..c1e133b 100644
--- a/lib/Drupal/flag/Entity/Flagging.php
+++ b/lib/Drupal/flag/Entity/Flagging.php
@@ -8,6 +8,7 @@
namespace Drupal\flag\Entity;
+use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Language\Language;
@@ -49,7 +50,7 @@ public function getFlag() {
return $this->bundle;
}
- public static function baseFieldDefinitions($entity_type) {
+ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = FieldDefinition::create('integer')
->setLabel(t('Node ID'))
->setDescription(t('The flagging ID.'))
diff --git a/lib/Drupal/flag/FlagTypePluginManager.php b/lib/Drupal/flag/FlagTypePluginManager.php
index ed5c650..2f5cf8d 100644
--- a/lib/Drupal/flag/FlagTypePluginManager.php
+++ b/lib/Drupal/flag/FlagTypePluginManager.php
@@ -29,9 +29,9 @@ class FlagTypePluginManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
- parent::__construct('Plugin/Flag', $namespaces, 'Drupal\flag\Annotation\FlagType');
+ parent::__construct('Plugin/Flag', $namespaces, $module_handler, 'Drupal\flag\Annotation\FlagType');
-// $this->alterInfo($module_handler, 'flag_type_info');
+ $this->alterInfo('flag_type_info');
$this->setCacheBackend($cache_backend, $language_manager, 'flag');
}
diff --git a/lib/Drupal/flag/Form/FlagAddForm.php b/lib/Drupal/flag/Form/FlagAddForm.php
index fccc532..78de632 100644
--- a/lib/Drupal/flag/Form/FlagAddForm.php
+++ b/lib/Drupal/flag/Form/FlagAddForm.php
@@ -10,6 +10,10 @@
use Drupal\flag\Form\FlagFormBase;
+/**
+ * Class FlagAddForm
+ * @package Drupal\flag\Form
+ */
class FlagAddForm extends FlagFormBase {
protected function getRoleDefault($selction) {
diff --git a/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php b/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
index d1d196b..9fb25df 100644
--- a/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
+++ b/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
@@ -17,9 +17,9 @@ public function __construct($base_plugin_id, EntityStorageControllerInterface $s
}
*/
- public function getDerivativeDefinitions(array $base_plugin_def) {
+ public function getDerivativeDefinitions($base_plugin_def) {
$derivatives = array();
- foreach (entity_get_info() as $entity_id => $entity_info) {
+ foreach (\Drupal::entityManager()->getDefinitions() as $entity_id => $entity_info) {
$derivatives[$entity_id] = array(
'title' => $entity_id,
'entity_type' => $entity_id,
diff --git a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
index 3bd0ddd..2fbd1ac 100644
--- a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
@@ -29,6 +29,7 @@ public function defaultConfiguration() {
// Use own display settings in the meanwhile.
$options += array(
'i18n' => 0,
+ 'access_author' => '',
);
return $options;
}
From 795977018c06693fdcc19317f66da58cb2bf6d21 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Mon, 31 Mar 2014 23:41:14 -0500
Subject: [PATCH 372/629] Updates due to changes in core.
---
flag.module | 2 +-
lib/Drupal/flag/Entity/Flag.php | 12 ++++++++----
lib/Drupal/flag/Form/FlagDeleteForm.php | 4 ++--
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/flag.module b/flag.module
index 92bb34d..a7e1bc5 100644
--- a/flag.module
+++ b/flag.module
@@ -877,7 +877,7 @@ function flag_entity_delete($entity, $type) {
return;
}
- _flag_entity_delete($entity->entityType(), $entity->id());
+ _flag_entity_delete($entity->getEntityType(), $entity->id());
}
/**
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 8b2ae1a..1161e04 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -13,7 +13,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Config\Entity\ConfigEntityBase;
-use Drupal\Core\Entity\EntityStorageControllerInterface;
+use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\flag\FlagInterface;
@@ -296,10 +296,14 @@ public function setGlobal($isGlobal = TRUE) {
}
}
+ public function getEntityType() {
+ return $this->entity_type;
+ }
+
/**
* @param EntityStorageControllerInterface $storage_controller
*/
- public function preSave(EntityStorageControllerInterface $storage_controller) {
+ public function preSave(EntityStorageInterface $storage_controller) {
parent::preSave($storage_controller);
// Save the Flag Type configuration.
@@ -311,8 +315,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
$this->set('linkTypeConfig', $linkTypePlugin->getConfiguration());
}
- public function getExportProperties() {
- $properties = parent::getExportProperties();
+ public function toArray() {
+ $properties = parent::toArray();
$names = array(
'roles',
'flag_type',
diff --git a/lib/Drupal/flag/Form/FlagDeleteForm.php b/lib/Drupal/flag/Form/FlagDeleteForm.php
index 3d755f6..02cb518 100644
--- a/lib/Drupal/flag/Form/FlagDeleteForm.php
+++ b/lib/Drupal/flag/Form/FlagDeleteForm.php
@@ -24,7 +24,7 @@ public function getConfirmText() {
public function getCancelRoute() {
return array(
- 'route_name' => 'flag.flag_list',
+ 'route_name' => 'flag_list',
);
}
@@ -34,7 +34,7 @@ public function submit(array $form, array &$form_state) {
'%label' => $this->entity->label(),
)));
- $form_state['redirect_route']['route_name'] = 'flag.flag_list';
+ $form_state['redirect_route']['route_name'] = 'flag_list';
}
}
\ No newline at end of file
From 7fa02ebe908602d75ab000b859783dd03444e3d5 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Mon, 31 Mar 2014 23:50:27 -0500
Subject: [PATCH 373/629] Changed Flag::getEntityType() to
getFlaggableEntityType(), fixing mixtakenly overrode Entity::getEntityType().
---
flag.module | 2 +-
lib/Drupal/flag/Entity/Flag.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/flag.module b/flag.module
index a7e1bc5..da42bd3 100644
--- a/flag.module
+++ b/flag.module
@@ -877,7 +877,7 @@ function flag_entity_delete($entity, $type) {
return;
}
- _flag_entity_delete($entity->getEntityType(), $entity->id());
+ _flag_entity_delete($entity->getFlaggableEntityType(), $entity->id());
}
/**
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 1161e04..af10a85 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -296,7 +296,7 @@ public function setGlobal($isGlobal = TRUE) {
}
}
- public function getEntityType() {
+ public function getFlaggableEntityType() {
return $this->entity_type;
}
From 5c15eeebdf51a0f64b6b0a7ecd341cadbbad7fe1 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Tue, 1 Apr 2014 23:08:37 -0500
Subject: [PATCH 374/629] Fixed services entries due to
https://drupal.org/node/2221065, added flag.menu_links.yml due to
https://drupal.org/node/2228089
---
flag.menu_links.yml | 5 +++++
flag.module | 11 -----------
flag.services.yml | 4 ++--
lib/Drupal/flag/FlagTypePluginManager.php | 2 +-
4 files changed, 8 insertions(+), 14 deletions(-)
create mode 100644 flag.menu_links.yml
diff --git a/flag.menu_links.yml b/flag.menu_links.yml
new file mode 100644
index 0000000..4e8a2c7
--- /dev/null
+++ b/flag.menu_links.yml
@@ -0,0 +1,5 @@
+flag.admin.structure.flag:
+ title: 'Flags'
+ description: 'Configure flags for marking content with arbitrary information (such as offensive or bookmarked).'
+ parent: system.admin_structure
+ route_name: flag_list
\ No newline at end of file
diff --git a/flag.module b/flag.module
index da42bd3..67d435d 100644
--- a/flag.module
+++ b/flag.module
@@ -156,17 +156,6 @@ function flag_menu() {
return $items;
}
-function flag_menu_link_defaults() {
- $items['flag.admin.structure.flag'] = array(
- 'link_title' => 'Flags',
- 'parent' => 'system.admin_structure',
- 'description' => 'Configure flags for marking content with arbitrary information (such as offensive or bookmarked).',
- 'route_name' => 'flag_list',
- );
-
- return $items;
-}
-
/**
* Implements hook_admin_menu_map().
*/
diff --git a/flag.services.yml b/flag.services.yml
index 25b20ef..d637bef 100644
--- a/flag.services.yml
+++ b/flag.services.yml
@@ -1,10 +1,10 @@
services:
plugin.manager.flag.flagtype:
class: Drupal\flag\FlagTypePluginManager
- arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
+ arguments: ['@container.namespaces', '@cache.default', '@language_manager', '@module_handler']
plugin.manager.flag.linktype:
class: Drupal\flag\ActionLinkPluginManager
- arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
+ arguments: ['@container.namespaces', '@cache.default', '@language_manager', '@module_handler']
flag:
class: Drupal\flag\FlagService
arguments: ['@module_handler']
diff --git a/lib/Drupal/flag/FlagTypePluginManager.php b/lib/Drupal/flag/FlagTypePluginManager.php
index 2f5cf8d..35ccadf 100644
--- a/lib/Drupal/flag/FlagTypePluginManager.php
+++ b/lib/Drupal/flag/FlagTypePluginManager.php
@@ -31,7 +31,7 @@ class FlagTypePluginManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Flag', $namespaces, $module_handler, 'Drupal\flag\Annotation\FlagType');
- $this->alterInfo('flag_type_info');
+ //$this->alterInfo('flag_type_info');
$this->setCacheBackend($cache_backend, $language_manager, 'flag');
}
From 990c3bc64b4f150ef99a9367c9e01c57b59ea418 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 2 Apr 2014 22:37:19 -0500
Subject: [PATCH 375/629] Fixed hook_schema(), updated Flagging annontation.
---
flag.install | 455 ++--------------------------
lib/Drupal/flag/Entity/Flagging.php | 4 +-
2 files changed, 21 insertions(+), 438 deletions(-)
diff --git a/flag.install b/flag.install
index d7d20ba..36d3e86 100644
--- a/flag.install
+++ b/flag.install
@@ -10,7 +10,7 @@
*/
function flag_schema() {
$schema = array();
-
+/*
$schema['flag'] = array(
'description' => 'All available flags in the system.',
'fields' => array(
@@ -60,7 +60,7 @@ function flag_schema() {
'name' => array('name'),
),
);
-
+*/
$schema['flagging'] = array(
'description' => 'Objects that have been flagged.',
'fields' => array(
@@ -70,6 +70,12 @@ function flag_schema() {
'unsigned' => TRUE,
'not null' => TRUE,
),
+ 'uuid' => array(
+ 'description' => 'Unique Key: Universally unique identifier for this entity.',
+ 'type' => 'varchar',
+ 'length' => 128,
+ 'not null' => FALSE,
+ ),
'fid' => array(
'description' => 'The unique flag ID this object has been flagged with, from {flag}.',
'type' => 'int',
@@ -113,7 +119,14 @@ function flag_schema() {
'not null' => TRUE,
'default' => 0,
'disp-size' => 11,
- )
+ ),
+ 'type' => array(
+ 'description' => 'The type of this node.',
+ 'type' => 'varchar',
+ 'length' => 32,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
),
'primary key' => array('id'),
'unique keys' => array(
@@ -125,7 +138,7 @@ function flag_schema() {
'entity_id_fid' => array('entity_id', 'fid'),
),
);
-
+/*
$schema['flag_types'] = array(
'description' => 'The entity bundles that are affected by a flag.',
'fields' => array(
@@ -200,7 +213,7 @@ function flag_schema() {
'fid_last_updated' => array('fid', 'last_updated'),
),
);
-
+*/
return $schema;
}
@@ -208,6 +221,7 @@ function flag_schema() {
* Implements hook_uninstall().
*/
function flag_uninstall() {
+ /*
$result = db_select('variable', 'v')
->fields('v', array('name'))
->condition('name', 'flag_%', 'LIKE')
@@ -215,7 +229,7 @@ function flag_uninstall() {
foreach ($result as $row) {
variable_del($row->name);
}
-
+ */
drupal_set_message(t('Flag has been uninstalled.'));
}
@@ -255,432 +269,3 @@ function flag_requirements($phase) {
}
return $requirements;
}
-
-function flag_update_last_removed() {
- return 6004;
-}
-
-/**
- * Convert role access to have separate "flag" and "unflag" permissions.
- */
-function flag_update_6200() {
- if (db_field_exists('flags', 'roles')) {
- $result = db_select('flags', 'f')
- ->fields('f')
- ->execute();
- foreach ($result as $flag) {
- $roles = array_filter(explode(',', $flag->roles));
- $options = unserialize($flag->options);
- $options['roles'] = array(
- 'flag' => $roles,
- 'unflag' => $roles,
- );
- db_update('flags')
- ->fields(array(
- 'options' => serialize($options),
- ))
- ->condition('fid', $flag->fid)
- ->execute();
- }
- db_drop_field('flags', 'roles');
- }
-}
-
-/**
- * Refine the indexes.
- *
- * The content type inclusion actually slowed down on unique key. And a count
- * index would be helpful for sorting by counts.
- */
-function flag_update_6201() {
- // Remove "content type" from one key, see http://drupal.org/node/612602.
- db_drop_unique_key('flag_content', 'fid_content_type_content_id_uid');
- db_add_unique_key('flag_content', 'fid_content_id_uid', array('fid', 'content_id', 'uid'));
-
- // Add a count index, see http://drupal.org/node/489610.
- db_add_index('flag_counts', 'count', array('count'));
-}
-
-/**
- * Add the sid column and unique index on the flag_content table.
- */
-function flag_update_6202() {
- // Drop the keys affected by the addition of the SID column.
- db_drop_unique_key('flag_content', 'fid_content_id_uid');
- db_drop_index('flag_content', 'content_type_uid');
-
- // Add the column.
- db_add_field('flag_content', 'sid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
-
- // Re-add the removed keys.
- db_add_unique_key('flag_content', 'fid_content_id_uid_sid', array('fid', 'content_id', 'uid', 'sid'));
- db_add_index('flag_content', 'content_type_uid_sid', array('content_type', 'uid', 'sid'));
-}
-
-/**
- * Remove count = 0 rows from the count tables.
- */
-function flag_update_6203() {
- db_delete('flag_counts')
- ->condition('count', 0)
- ->execute();
-}
-
-/**
- * Remove "content type" from the flag_counts primary key.
- */
-function flag_update_6204() {
- db_drop_primary_key('flag_counts');
- db_add_primary_key('flag_counts', array('fid', 'content_id'));
-}
-
-/**
- * Provide a better index on the flag_content table including 'uid' and 'sid'.
- */
-function flag_update_6205() {
- // This update has been removed and corrected in flag_update_6206.
- // See http://drupal.org/node/1105490.
-}
-
-/**
- * Correction to flag_update_6205(). Convert unique key to an index.
- */
-function flag_update_6206() {
- // Remove the old index that did not include UID or SID.
- if (db_index_exists('flag_content', 'content_type_content_id')) {
- db_drop_index('flag_content', 'content_type_content_id');
- }
-
- // Remove the erroneous unique key that was added in flag_update_6205().
- if (db_index_exists('flag_content', 'content_type_content_id_uid_sid')) {
- db_drop_unique_key('flag_content', 'content_type_content_id_uid_sid');
- }
-
- db_add_index('flag_content', 'content_type_content_id_uid_sid', array('content_type', 'content_id', 'uid', 'sid'));
-}
-
-/**
- * Adds column last_updated to flag_counts table.
- */
-function flag_update_6207() {
- db_add_field('flag_counts', 'last_updated', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-size' => 11), array('indexes' => array('last_updated' => array('last_updated'))));
-}
-
-/**
- * Convert flag_count indexes to include FID for more efficient indexing.
- */
-function flag_update_6208() {
- db_drop_index('flag_counts', 'count');
- db_drop_index('flag_counts', 'last_updated');
-
- db_add_index('flag_counts', 'fid_count', array('fid', 'count'));
- db_add_index('flag_counts', 'fid_last_updated', array('fid', 'last_updated'));
-}
-
-/**
- * Clear caches.
- */
-function flag_update_7201() {
- // Do nothing. Update.php is going to clear caches for us.
-}
-
-/**
- * Clean-up flag records for deleted nodes and comments.
- */
-function flag_update_7202() {
- // These queries can't use db_delete() because that doesn't support a
- // subquery: see http://drupal.org/node/1267508.
- // Clean-up for nodes.
- db_query("DELETE FROM {flag_content} WHERE content_type = 'node' AND NOT EXISTS (SELECT 1 FROM {node} n WHERE content_id = n.nid)");
- db_query("DELETE FROM {flag_counts} WHERE content_type = 'node' AND NOT EXISTS (SELECT 1 FROM {node} n WHERE content_id = n.nid)");
- // Clean-up for comments. Do not use module_exists() because comment module
- // could be disabled.
- if (db_table_exists('comment')) {
- db_query("DELETE FROM {flag_content} WHERE content_type = 'comment' AND NOT EXISTS (SELECT 1 FROM {comment} c WHERE content_id = c.cid)");
- db_query("DELETE FROM {flag_counts} WHERE content_type = 'comment' AND NOT EXISTS (SELECT 1 FROM {comment} c WHERE content_id = c.cid)");
- }
-}
-
-/**
- * Add an index to help with view's flag_handler_relationship when not required.
- */
-function flag_update_7203() {
- // Skip if this index was also added by the 6.x-2.x branch.
- if (!db_index_exists('flag_content', 'content_id_fid')) {
- db_add_index('flag_content', 'content_id_fid', array('content_id', 'fid'));
- }
-}
-
-/**
- * Rebuild the class registry due to classes moving files.
- */
-function flag_update_7300() {
- registry_rebuild();
-}
-
-/**
- * Rename {flag_content} table to {flagging} and {flags} table to {flag}.
- */
-function flag_update_7301() {
- db_rename_table('flag_content', 'flagging');
- db_rename_table('flags', 'flag');
- // A second cache clear appears to be required here...
- cache_clear_all();
- // ...which in fact isn't enough, as the schema cache appears to need explicit
- // clearing to prevent the next updates failing to get the schema for the new
- // table names.
- drupal_get_schema(NULL, TRUE);
-}
-
-/**
- * Rename database columns on the {flag} table.
- */
-function flag_update_7302() {
- // No keys or indexes are affected.
- // Change field 'content_type' to 'entity_type'.
- db_change_field('flag', 'content_type', 'entity_type',
- // Spec of the field. Identical to our current hook_schema(): we're not
- // changing anything except the name.
- array(
- 'description' => 'The flag type, such as one of "node", "comment", or "user".',
- 'type' => 'varchar',
- 'length' => '32',
- 'not null' => TRUE,
- 'default' => '',
- )
- // No keys to re-add.
- );
-}
-
-/**
- * Rename database columns on the {flagging} table.
- */
-function flag_update_7303() {
- // Drop affected keys and indexes.
- db_drop_unique_key('flagging', 'fid_content_id_uid_sid');
- db_drop_index('flagging', 'content_type_uid_sid');
- db_drop_index('flagging', 'content_type_content_id_uid_sid');
- db_drop_index('flagging', 'content_id_fid');
-
- // Change field 'content_type' to 'entity_type'.
- db_change_field('flagging', 'content_type', 'entity_type',
- // Spec of the field. Identical to our current hook_schema(): we're not
- // changing anything except the name.
- array(
- 'description' => 'The flag type, eg "node", "comment", "user".',
- 'type' => 'varchar',
- 'length' => '32',
- 'not null' => TRUE,
- 'default' => '',
- ),
- // Keys spec. Some are short-lived, as they are about to be dropped again
- // and have hybrid names that refer to 'content_id' still.
- array(
- 'unique keys' => array(
- 'fid_content_id_uid_sid' => array('fid', 'content_id', 'uid', 'sid'),
- ),
- 'indexes' => array(
- 'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
- 'entity_type_content_id_uid_sid' => array('entity_type', 'content_id', 'uid', 'sid'),
- 'content_id_fid' => array('content_id', 'fid'),
- ),
- )
- );
-
- // Now we have to drop keys and indexes all over again!
- db_drop_unique_key('flagging', 'fid_content_id_uid_sid');
- db_drop_index('flagging', 'entity_type_content_id_uid_sid');
- db_drop_index('flagging', 'content_id_fid');
-
- // Change field 'content_id' to 'entity_id'.
- db_change_field('flagging', 'content_id', 'entity_id',
- // Spec of the field. Identical to our current hook_schema(): we're not
- // changing anything except the name.
- array(
- 'description' => 'The unique ID of the content, such as either the {cid}, {uid}, or {nid}.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- // Keys spec. Identical to current hook_schema().
- array(
- 'unique keys' => array(
- 'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
- ),
- 'indexes' => array(
- 'entity_type_entity_id_uid_sid' => array('entity_type', 'entity_id', 'uid', 'sid'),
- 'entity_id_fid' => array('entity_id', 'fid'),
- ),
- )
- );
-
- // A serial field must be defined as a key, so make a temporary index on
- // 'fcid' so we can safely drop the primary key.
- // @see http://drupal.org/node/190027
- db_add_index('flagging', 'temp', array('fcid'));
- // Drop the primary key so we can rename the field.
- db_drop_primary_key('flagging');
-
- // Change field 'fcid' to 'flagging_id'.
- db_change_field('flagging', 'fcid', 'flagging_id',
- // Spec of the field. Identical to our current hook_schema(): we're not
- // changing anything except the name.
- array(
- 'description' => 'The unique ID for this particular tag.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- // Keys spec. Identical to current hook_schema().
- array(
- 'primary key' => array('flagging_id'),
- )
- );
- // Drop our temporary index.
- db_drop_index('flagging', 'temp');
-
- cache_clear_all();
-}
-
-/**
- * Rename database columns on the {flag_counts} table.
- */
-function flag_update_7304() {
- // Drop keys and indexes using 'content_type'.
- db_drop_index('flag_counts', 'fid_content_type');
- db_drop_index('flag_counts', 'content_type_content_id');
-
- // Change field 'content_type' to 'entity_type'.
- db_change_field('flag_counts', 'content_type', 'entity_type',
- // Spec of the field. Identical to our current hook_schema(): we're not
- // changing anything except the name.
- array(
- 'description' => 'The flag type, usually one of "node", "comment", "user".',
- 'type' => 'varchar',
- 'length' => '32',
- 'not null' => TRUE,
- 'default' => '',
- ),
- // Keys spec. Some are short-lived, as they are about to be dropped again.
- // Note the hybrid names refer to 'content_id' still.
- array(
- 'indexes' => array(
- 'fid_entity_type' => array('fid', 'entity_type'),
- 'entity_type_content_id' => array('entity_type', 'content_id'),
- )
- )
- );
-
- // Now drop keys and indexes using 'content_id'.
- db_drop_primary_key('flag_counts');
- db_drop_index('flag_counts', 'entity_type_content_id');
-
- // Change field 'content_id' to 'entity_id'.
- db_change_field('flag_counts', 'content_id', 'entity_id',
- // Spec of the field. Identical to our current hook_schema(): we're not
- // changing anything except the name.
- array(
- 'description' => 'The unique ID of the content, usually either the {cid}, {uid}, or {nid}.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'disp-width' => '10',
- ),
- // Keys spec. Identical to current hook_schema() now we're finished.
- array(
- 'primary key' => array('fid', 'entity_id'),
- 'indexes' => array(
- 'entity_type_entity_id' => array('entity_type', 'entity_id'),
- ),
- )
- );
-}
-
-/**
- * Convert flag roles to permissions.
- */
-function flag_update_7305() {
- // We can't use flag_get_flags() to get all flags to act on, because that
- // now looks for user permissions and we want the old roles array to convert.
- // Hence we need to get flags directly from the database.
- // Flags defined in code are saved in the database by flag_get_flags(), so
- // this will get them too, unless the module providing them was *only just*
- // installed before update.php was run. This edge case is not covered.
-
- $result = db_query("SELECT name, options FROM {flag}");
- $flag_data = $result->fetchAllKeyed();
-
- // Note we don't call hook_flag_alter() because we don't have a complete flag.
- // If your custom module does something to flag roles, it is your
- // responsibility to handle upgrading your extra role data.
-
- foreach ($flag_data as $flag_name => $flag_options) {
- $flag_options = unserialize($flag_options);
- $flag_roles = $flag_options['roles'];
-
- foreach ($flag_roles['flag'] as $rid) {
- $permission = "flag $flag_name";
- user_role_grant_permissions($rid, array($permission));
- }
- foreach ($flag_roles['unflag'] as $rid) {
- $permission = "unflag $flag_name";
- user_role_grant_permissions($rid, array($permission));
- }
-
- // Save the flag options with the roles array removed.
- unset($flag_options['roles']);
- db_update('flag')
- ->fields(array(
- 'options' => serialize($flag_options),
- ))
- ->condition('name', $flag_name)
- ->execute();
- }
-
- // Flags in code will now report as overridden because the roles option is no
- // longer output. Notify the user that they should update them.
- if (count(module_implements('flag_default_flags'))) {
- drupal_set_message(t('Flags which are defined in code with hook_flag_default_flags() or Features need to be re-exported.'));
- }
-
- // Direct the user to read the change notice, which has more details of how
- // access to flag objects has been affected.
- return t('Flag roles have been converted to user permissions. Permissions have been granted to each flag based on flag roles. You should review the consequences of this in the change record.', array(
- '!url' => 'http://drupal.org/node/1724256',
- ));
-}
-
-/**
- * Convert flag view modes settings.
- */
-function flag_update_7306() {
- foreach (flag_get_flags() as $flag) {
- // Update show_on_teaser property to use new view mode settings.
- if (!empty($flag->show_on_teaser)) {
- $flag->show_in_links['teaser'] = TRUE;
- unset($flag->show_on_teaser);
- }
-
- // Update show_on_page property to use new view mode settings.
- if (!empty($flag->show_on_page)) {
- $flag->show_in_links['full'] = TRUE;
- unset($flag->show_on_page);
- }
-
- // Update show_on_comment and show_on_entity properties to use new view
- // mode settings. Since the old logic was to show on all view modes, do that.
- if (!empty($flag->show_on_entity) || !empty($flag->show_on_comment)) {
- if ($entity_info = entity_get_info($flag->entity_type)) {
- foreach ($entity_info['view modes'] as $view_mode => $value) {
- $flag->show_in_links[$view_mode] = TRUE;
- }
- }
-
- unset($flag->show_on_entity, $flag->show_on_comment);
- }
-
- $flag->save();
- }
-}
diff --git a/lib/Drupal/flag/Entity/Flagging.php b/lib/Drupal/flag/Entity/Flagging.php
index c1e133b..21e984f 100644
--- a/lib/Drupal/flag/Entity/Flagging.php
+++ b/lib/Drupal/flag/Entity/Flagging.php
@@ -20,12 +20,10 @@
* Class Flagging
* @package Drupal\flag\Entity
*
- * @EntityType(
+ * @ContentEntityType(
* id = "flagging",
* label = @Translation("Flagging"),
- * module = "flag",
* controllers = {
- * "storage" = "Drupal\Core\Entity\FieldableDatabaseStorageController",
* "access" = "Drupal\flag\FlaggingAccessController",
* },
* base_table = "flagging",
From 2d44192ca825e5a8c06fb16a7b5820409199227b Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 6 Apr 2014 12:29:52 -0500
Subject: [PATCH 376/629] Working flaggings and flagging access controller.
---
flag.install | 11 +++----
flag.routing.yml | 15 +++++++--
lib/Drupal/flag/ActionLinkTypeBase.php | 32 +++++++++++++------
.../flag/Controller/ReloadLinkController.php | 28 ++++++++++++----
lib/Drupal/flag/Entity/Flag.php | 10 +++---
lib/Drupal/flag/Entity/Flagging.php | 24 ++++++++++++--
lib/Drupal/flag/FlagService.php | 14 ++++++--
lib/Drupal/flag/FlaggingAccessController.php | 9 ++++++
lib/Drupal/flag/Plugin/ActionLink/Reload.php | 8 +++--
9 files changed, 113 insertions(+), 38 deletions(-)
diff --git a/flag.install b/flag.install
index 36d3e86..364686b 100644
--- a/flag.install
+++ b/flag.install
@@ -78,18 +78,15 @@ function flag_schema() {
),
'fid' => array(
'description' => 'The unique flag ID this object has been flagged with, from {flag}.',
- 'type' => 'int',
- 'size' => 'small',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
+ 'type' => 'varchar',
+ 'length' => 32,
+ 'not null' => FALSE,
),
'entity_type' => array(
'description' => 'The flag type, eg "node", "comment", "user".',
'type' => 'varchar',
- 'length' => '128',
+ 'length' => 128,
'not null' => TRUE,
- 'default' => '',
),
'entity_id' => array(
'description' => 'The unique ID of the object, such as either the {cid}, {uid}, or {nid}.',
diff --git a/flag.routing.yml b/flag.routing.yml
index 5247a8b..7b780dd 100644
--- a/flag.routing.yml
+++ b/flag.routing.yml
@@ -54,13 +54,22 @@ flag_export:
requirements:
_permission: 'use flag import'
-flag_link:
- path: '/flag/{action}/{flag}/{entity}'
+flag_link_flag:
+ path: '/flag/flag/{flag_id}/{entity_id}'
defaults:
_controller: '\Drupal\flag\Controller\ReloadLinkController::flag'
+ requirements:
+ _entity_create_access: flagging
+
+flag_link_unflag:
+ path: '/flag/unflag/{flag_id}/{entity_id}'
+ defaults:
+ _controller: '\Drupal\flag\Controller\ReloadLinkController::unflag'
+ requirements:
+ _entity_access: flagging.delete
flag_confirm_form:
- path: '/flag/confirm/{action}/{flag}/{entity}'
+ path: '/flag/confirm/{action}/{flag_id}/{entity_id}'
defaults:
_form: '\Drupal\flag\Form\FlaggingConfirmForm'
_title: 'Flag Content'
diff --git a/lib/Drupal/flag/ActionLinkTypeBase.php b/lib/Drupal/flag/ActionLinkTypeBase.php
index 9eec7ae..82ac259 100644
--- a/lib/Drupal/flag/ActionLinkTypeBase.php
+++ b/lib/Drupal/flag/ActionLinkTypeBase.php
@@ -34,32 +34,44 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi
}
/**
- * @inheritDoc
+ * Returns a route name given an $action.
+ *
+ * @param $action
+ * A string containing the action name.
+ * @return string
+ * A string containing a route name.
*/
- abstract public function routeName();
+ abstract public function routeName($action = NULL);
/**
* @return string
*/
public function buildLink($action, FlagInterface $flag, EntityInterface $entity) {
- $options = array(
- 'action' => $action,
- 'flag' => $flag->id(),
- 'entity' => $entity->id(),
+ $parameters = array(
+ 'flag_id' => $flag->id(),
+ 'entity_id' => $entity->id(),
);
- return new URL($this->routeName(), $options);
+ return new URL($this->routeName($action), $parameters);
}
public function renderLink($action, FlagInterface $flag, EntityInterface $entity) {
$url = $this->buildLink($action, $flag, $entity);
- $url->setOption('destination', \Drupal::request()->attributes->get('_system_path'));
- $url->setOption('alt', $flag->flag_long);
+ $url->setRouteParameter('destination', \Drupal::request()->getRequestUri());
$render = $url->toRenderArray();
$render['#type'] = 'link';
- $render['#title'] = $flag->flag_short;
+
+ //@todo check if flagged, assign flag or unflag text.
+ if ($action === 'unflag') {
+ $render['#title'] = $flag->unflag_short;
+ $render['#alt'] = $flag->unflag_long;
+ }
+ else {
+ $render['#title'] = $flag->flag_short;
+ $render['#alt'] = $flag->flag_long;
+ }
return $render;
}
diff --git a/lib/Drupal/flag/Controller/ReloadLinkController.php b/lib/Drupal/flag/Controller/ReloadLinkController.php
index 66972a8..4a27840 100644
--- a/lib/Drupal/flag/Controller/ReloadLinkController.php
+++ b/lib/Drupal/flag/Controller/ReloadLinkController.php
@@ -11,16 +11,30 @@
use Drupal\Core\Controller\ControllerBase;
use Drupal\flag\FlagInterface;
use Drupal\Core\Entity\EntityInterface;
+use Symfony\Component\HttpFoundation\RedirectResponse;
class ReloadLinkController extends ControllerBase {
- public function flag($action, FlagInterface $flag, EntityInterface $entity) {
- if ($action == 'flag') {
- \Drupal::service('flag')->flag($flag, $entity);
- }
- else if ($action == 'unflag') {
- \Drupal::service('flag')->unflag($flag, $entity);
- }
+ public function flag($flag_id, $entity_id) {
+ $flag = entity_load('flag_flag', $flag_id);
+ $entity = entity_load($flag->getFlaggableEntityType(), $entity_id);
+ \Drupal::service('flag')->flag($flag, $entity);
+
+ $destination = \Drupal::request()->get('destination', $entity->url());
+
+ //@todo SECURITY HOLE. Please fix!
+ return new RedirectResponse($destination);
+ }
+
+ public function unflag($flag, $entity) {
+ $flag = entity_load('flag_flag', $flag_id);
+ $entity = entity_load($flag->getFlaggableEntityType(), $entity_id);
+ \Drupal::service('flag')->unflag($flag, $entity);
+
+ $destination = \Drupal::request()->get('destination', $entity->url());
+
+ //@todo SECURITY HOLE. Please fix!
+ return new RedirectResponse($destination);
}
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index af10a85..2515ae2 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -202,19 +202,21 @@ public function disable() {
public function isFlagged(EntityInterface $entity, AccountInterface $account = NULL) {
if($account == NULL) {
- global $user;
- $account = $user;
+ $account = \Drupal::currentUser();
}
$result = \Drupal::entityQuery('flagging')
->condition('uid', $account->id())
->condition('fid', $this->id())
+ ->condition('entity_type', $entity->getEntityTypeId())
->condition('entity_id', $entity->id())
->execute();
- if (isset($result['node'])) {
- $flagging_ids = array_keys($result['flagging']);
+ if (!empty($result)) {
+ return TRUE;
}
+
+ return FALSE;
}
/**
diff --git a/lib/Drupal/flag/Entity/Flagging.php b/lib/Drupal/flag/Entity/Flagging.php
index 21e984f..7d0fb1e 100644
--- a/lib/Drupal/flag/Entity/Flagging.php
+++ b/lib/Drupal/flag/Entity/Flagging.php
@@ -44,13 +44,19 @@
*/
class Flagging extends ContentEntityBase implements FlaggingInterface {
+ protected $entity_id;
+
+ protected $entity_type;
+
+ protected $fid;
+
public function getFlag() {
return $this->bundle;
}
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = FieldDefinition::create('integer')
- ->setLabel(t('Node ID'))
+ ->setLabel(t('Flagging ID'))
->setDescription(t('The flagging ID.'))
->setReadOnly(TRUE);
@@ -59,6 +65,19 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->setDescription(t('The flagging UUID.'))
->setReadOnly(TRUE);
+ $fields['fid'] = FieldDefinition::create('integer')
+ ->setLabel(t('Flag ID'))
+ ->setDescription(t('The Flag ID.'))
+ ->setReadOnly(TRUE);
+
+ $fields['entity_type'] = FieldDefinition::create('string')
+ ->setLabel(t('Entity Type'))
+ ->setDescription(t('The Entity Type.'));
+
+ $fields['entity_id'] = FieldDefinition::create('string')
+ ->setLabel(t('Entity ID'))
+ ->setDescription(t('The Entity ID.'));
+
$fields['type'] = FieldDefinition::create('entity_reference')
->setLabel(t('Type'))
->setDescription(t('The flag type.'))
@@ -73,8 +92,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
'default_value' => 0,
));
- // @todo Convert to a "created" field in https://drupal.org/node/2145103.
- $fields['created'] = FieldDefinition::create('integer')
+ $fields['created'] = FieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the flagging was created.'));
diff --git a/lib/Drupal/flag/FlagService.php b/lib/Drupal/flag/FlagService.php
index 7ad2d5b..71895ea 100644
--- a/lib/Drupal/flag/FlagService.php
+++ b/lib/Drupal/flag/FlagService.php
@@ -95,11 +95,21 @@ public function getFlaggings(EntityInterface $entity, FlagInterface $flag, Accou
}
- public function flag(EntityInterface $entity, FlagInterface $flag, AccountInterface $account = NULL) {
+ public function flag($flag, $entity, AccountInterface $account = NULL) {
+ if (empty($account)) {
+ $account = \Drupal::currentUser();
+ }
+ entity_create('flagging', array(
+ 'type' => 'flag_flag',
+ 'uid' => $account->id(),
+ 'fid' => $flag->id(),
+ 'entity_id' => $entity->id(),
+ 'entity_type' => $entity->getEntityTypeId(),
+ ))->save();
}
- public function unflag(FlaggingInterface $flagging) {
+ public function unflag($flagging) {
}
diff --git a/lib/Drupal/flag/FlaggingAccessController.php b/lib/Drupal/flag/FlaggingAccessController.php
index ce92935..906b0f8 100644
--- a/lib/Drupal/flag/FlaggingAccessController.php
+++ b/lib/Drupal/flag/FlaggingAccessController.php
@@ -15,6 +15,10 @@
class FlaggingAccessController extends EntityAccessController {
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
+ if ($account->id() == 1) {
+ return TRUE;
+ }
+
switch ($operation) {
case 'view':
case 'flag':
@@ -31,6 +35,11 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A
}
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
+ if ($account->id() == 1) {
+ return TRUE;
+ }
+
+ //@todo Figure out how to handle the NULL $entity_bundle case.
return user_access('flag ' . $entity_bundle, $account);
}
diff --git a/lib/Drupal/flag/Plugin/ActionLink/Reload.php b/lib/Drupal/flag/Plugin/ActionLink/Reload.php
index 0075cad..8683e90 100644
--- a/lib/Drupal/flag/Plugin/ActionLink/Reload.php
+++ b/lib/Drupal/flag/Plugin/ActionLink/Reload.php
@@ -24,8 +24,12 @@ class Reload extends ActionLinkTypeBase {
/**
* @return string
*/
- public function routeName() {
- return 'flag_link';
+ public function routeName($action = NULL) {
+ if ($action === 'unflag') {
+ return 'flag_link_unflag';
+ }
+
+ return 'flag_link_flag';
}
}
\ No newline at end of file
From 7dea70fd27401bbc944577588278f7d09d0eb313 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Mon, 7 Apr 2014 23:08:33 -0500
Subject: [PATCH 377/629] Refactored FlagService.
---
.../flag/Controller/ReloadLinkController.php | 30 ++++++--
lib/Drupal/flag/FlagService.php | 73 ++++++++++++++++++-
2 files changed, 92 insertions(+), 11 deletions(-)
diff --git a/lib/Drupal/flag/Controller/ReloadLinkController.php b/lib/Drupal/flag/Controller/ReloadLinkController.php
index 4a27840..f28dd56 100644
--- a/lib/Drupal/flag/Controller/ReloadLinkController.php
+++ b/lib/Drupal/flag/Controller/ReloadLinkController.php
@@ -16,20 +16,36 @@
class ReloadLinkController extends ControllerBase {
public function flag($flag_id, $entity_id) {
- $flag = entity_load('flag_flag', $flag_id);
- $entity = entity_load($flag->getFlaggableEntityType(), $entity_id);
- \Drupal::service('flag')->flag($flag, $entity);
+ // Get the Flag Service.
+ $flagService = \Drupal::service('flag');
+ // Get the Flag and Entity objects.
+ $flag = $flagService->getFlagById($flag_id);
+ $entity = $flagService->getFlaggableById($flag, $entity_id);
+
+ // While we could use FlagService::flag() here, we wouldn't have the URL
+ // to redirect Drupal afterward. So we flag by object instead.
+ $flagService->flagByObject($flag, $entity);
+
+ // Get the destination.
$destination = \Drupal::request()->get('destination', $entity->url());
//@todo SECURITY HOLE. Please fix!
return new RedirectResponse($destination);
}
- public function unflag($flag, $entity) {
- $flag = entity_load('flag_flag', $flag_id);
- $entity = entity_load($flag->getFlaggableEntityType(), $entity_id);
- \Drupal::service('flag')->unflag($flag, $entity);
+ public function unflag($flag_id, $entity_id) {
+ // Get the Flag Service.
+ $flagService = \Drupal::service('flag');
+
+ // Get the Flag and Entity objects.
+ $flag = $flagService->getFlagById($flag_id);
+ $entity = $flagService->getFlaggableById($flag, $entity_id);
+
+ $flaggings = \Drupal::service('flag')->getFlaggings($entity, $flag);
+ foreach ($flaggings as $flagging) {
+ \Drupal::service('flag')->unflagByObject($flagging);
+ }
$destination = \Drupal::request()->get('destination', $entity->url());
diff --git a/lib/Drupal/flag/FlagService.php b/lib/Drupal/flag/FlagService.php
index 71895ea..17bbcd1 100644
--- a/lib/Drupal/flag/FlagService.php
+++ b/lib/Drupal/flag/FlagService.php
@@ -10,6 +10,9 @@
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface;
+use Drupal\flag\FlagInterface;
+use Drupal\Core\Entity\EntityInterface;
+
/**
* Flag service.
@@ -92,25 +95,87 @@ public function getFlags($entity_type = NULL, $bundle = NULL, AccountInterface $
}
public function getFlaggings(EntityInterface $entity, FlagInterface $flag, AccountInterface $account = NULL) {
+ if($account == NULL) {
+ $account = \Drupal::currentUser();
+ }
+
+ $result = \Drupal::entityQuery('flagging')
+ ->condition('uid', $account->id())
+ ->condition('fid', $flag->id())
+ ->condition('entity_type', $entity->getEntityTypeId())
+ ->condition('entity_id', $entity->id())
+ ->execute();
+
+ $flaggings = array();
+ foreach ($result as $flagging_id) {
+ $flaggings[$flagging_id] = entity_load('flagging', $flagging_id);
+ }
+
+ return $flaggings;
+ }
+
+ public function getFlagById($flag_id) {
+ return entity_load('flag_flag', $flag_id);
+ }
+ public function getFlaggableById(FlagInterface $flag, $entity_id) {
+ return entity_load($flag->getFlaggableEntityType(), $entity_id);
}
- public function flag($flag, $entity, AccountInterface $account = NULL) {
+ public function flagByObject(FlagInterface $flag, EntityInterface $entity, AccountInterface $account = NULL) {
if (empty($account)) {
$account = \Drupal::currentUser();
}
- entity_create('flagging', array(
+ $flagging = entity_create('flagging', array(
'type' => 'flag_flag',
'uid' => $account->id(),
'fid' => $flag->id(),
'entity_id' => $entity->id(),
'entity_type' => $entity->getEntityTypeId(),
- ))->save();
+ ));
+
+ $flagging->save();
+
+ \Drupal::entityManager()
+ ->getViewBuilder($entity->getEntityTypeId())
+ ->resetCache(array(
+ $entity,
+ ));
+
+ return $flagging;
+ }
+
+ public function flag($flag_id, $entity_id, AccountInterface $account = NULL) {
+ if (empty($account)) {
+ $account = \Drupal::currentUser();
+ }
+
+ $flag = $this->getFlagById($flag_id);
+ $entity = $this->getFlaggableById($flag, $entity_id);
+
+ return $this->flagByObject($flag, $entity, $account);
+ }
+
+ public function unflagByObject(FlaggingInterface $flagging) {
+ $flagging->delete();
}
- public function unflag($flagging) {
+ public function unflag($flag_id, $entity_id, AccountInterface $account = NULL) {
+ if (empty($account)) {
+ $account = \Drupal::currentUser();
+ }
+
+ $flag = $this->getFlagById($flag_id);
+ $entity = $this->getFlaggableById($flag, $entity_id);
+
+ $out = array();
+ $flaggings = $this->getFlaggings($entity, $flag);
+ foreach ($flaggings as $flagging) {
+ $out[] = $this->unflagByObject($flagging);
+ }
+ return $out;
}
}
\ No newline at end of file
From cf8c684cf8c710f9aed10103d25e1fc9815bc6a4 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Tue, 8 Apr 2014 22:37:13 -0500
Subject: [PATCH 378/629] Augmented Flagging, simplified reload link
controller.
---
.../flag/Controller/ReloadLinkController.php | 13 +++----------
lib/Drupal/flag/Entity/Flagging.php | 16 +++++++++++-----
2 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/lib/Drupal/flag/Controller/ReloadLinkController.php b/lib/Drupal/flag/Controller/ReloadLinkController.php
index f28dd56..9928005 100644
--- a/lib/Drupal/flag/Controller/ReloadLinkController.php
+++ b/lib/Drupal/flag/Controller/ReloadLinkController.php
@@ -16,19 +16,12 @@
class ReloadLinkController extends ControllerBase {
public function flag($flag_id, $entity_id) {
- // Get the Flag Service.
- $flagService = \Drupal::service('flag');
- // Get the Flag and Entity objects.
- $flag = $flagService->getFlagById($flag_id);
- $entity = $flagService->getFlaggableById($flag, $entity_id);
-
- // While we could use FlagService::flag() here, we wouldn't have the URL
- // to redirect Drupal afterward. So we flag by object instead.
- $flagService->flagByObject($flag, $entity);
+ $flagging = \Drupal::service('flag')->flag($flag_id, $entity_id);
// Get the destination.
- $destination = \Drupal::request()->get('destination', $entity->url());
+ $destination = \Drupal::request()->get('destination',
+ $flagging->getFlaggable()->url());
//@todo SECURITY HOLE. Please fix!
return new RedirectResponse($destination);
diff --git a/lib/Drupal/flag/Entity/Flagging.php b/lib/Drupal/flag/Entity/Flagging.php
index 7d0fb1e..b1d37ad 100644
--- a/lib/Drupal/flag/Entity/Flagging.php
+++ b/lib/Drupal/flag/Entity/Flagging.php
@@ -44,14 +44,20 @@
*/
class Flagging extends ContentEntityBase implements FlaggingInterface {
- protected $entity_id;
+ public function getFlag() {
+ return $this->bundle;
+ }
- protected $entity_type;
+ public function getFlaggableType() {
+ return $this->get('entity_type')->value;
+ }
- protected $fid;
+ public function getFlaggableId() {
+ return $this->get('entity_id')->value;
+ }
- public function getFlag() {
- return $this->bundle;
+ public function getFlaggable() {
+ return entity_load($this->getFlaggableType(), $this->getFlaggableId());
}
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
From b0887ccfc2f71b496b753f7ad81442c47786b40d Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 9 Apr 2014 20:53:21 -0500
Subject: [PATCH 379/629] Removed old flag handlers, hook_menu(), etc.
---
flag.module | 173 +--
lib/Drupal/flag/Entity/Flag.php | 5 +
lib/Drupal/flag/Handlers/AbstractFlag.php | 1541 ---------------------
lib/Drupal/flag/Handlers/BrokenFlag.php | 19 -
lib/Drupal/flag/Handlers/CommentFlag.php | 103 --
lib/Drupal/flag/Handlers/Flag.php | 239 ----
lib/Drupal/flag/Handlers/NodeFlag.php | 122 --
lib/Drupal/flag/Handlers/UserFlag.php | 99 --
8 files changed, 9 insertions(+), 2292 deletions(-)
delete mode 100644 lib/Drupal/flag/Handlers/AbstractFlag.php
delete mode 100644 lib/Drupal/flag/Handlers/BrokenFlag.php
delete mode 100644 lib/Drupal/flag/Handlers/CommentFlag.php
delete mode 100644 lib/Drupal/flag/Handlers/Flag.php
delete mode 100644 lib/Drupal/flag/Handlers/NodeFlag.php
delete mode 100644 lib/Drupal/flag/Handlers/UserFlag.php
diff --git a/flag.module b/flag.module
index 67d435d..ed42a9e 100644
--- a/flag.module
+++ b/flag.module
@@ -43,7 +43,7 @@ use Drupal\node\NodeInterface;
* with query condition on [name] field in [flag] table.
*
* @see flag_query_flagging_flag_names_alter()
- */
+ *//*
function flag_entity_query_alter(EntityFieldQuery $query) {
$conditions = &$query->entityConditions;
@@ -56,13 +56,13 @@ function flag_entity_query_alter(EntityFieldQuery $query) {
$query->addMetaData('flag_name_operator', $conditions['bundle']['operator']);
unset($conditions['bundle']);
}
-}
+}*/
/**
* Implements hook_query_TAG_alter() for flagging_flag_names tag.
*
* @see flag_entity_query_alter()
- */
+ *//*
function flag_query_flagging_flag_names_alter(QueryAlterableInterface $query) {
// Get value and operator for bundle condition from meta data.
$value = $query->getMetaData('flag_name_value');
@@ -71,90 +71,7 @@ function flag_query_flagging_flag_names_alter(QueryAlterableInterface $query) {
// apply bundle condition on [flag].[name] field.
$query->join('flag', 'f', 'flagging.fid = f.fid');
$query->condition('f.name', $value, $operator);
-}
-
-/**
- * Implements hook_menu().
- */
-function flag_menu() {
-
- $items[FLAG_ADMIN_PATH . '/add'] = array(
- 'route_name' => 'flag_add_page',
- 'type' => MENU_SIBLING_LOCAL_TASK,
- 'weight' => 1,
- );
- $items[FLAG_ADMIN_PATH . '/add/%node_type'] = array(
- 'title' => 'Flag Add',
- 'route_name' => 'flag_add',
- 'type' => MENU_CALLBACK,
- );
-/*
- $items[FLAG_ADMIN_PATH . '/manage/%flag'] = array(
- 'load arguments' => array(TRUE), // Allow for disabled flags.
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('flag_form', FLAG_ADMIN_PATH_START + 1),
- 'access callback' => 'user_access',
- 'access arguments' => array('administer flags'),
- 'file' => 'includes/flag.admin.inc',
- 'type' => MENU_CALLBACK,
- // Make the flag title the default title for descendant menu items.
- 'title callback' => '_flag_menu_title',
- 'title arguments' => array(FLAG_ADMIN_PATH_START + 1),
- );
- $items[FLAG_ADMIN_PATH . '/manage/%flag/edit'] = array(
- 'load arguments' => array(TRUE), // Allow for disabled flags.
- 'title' => 'Edit flag',
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => -10,
- );
- $items[FLAG_ADMIN_PATH . '/manage/%flag/export'] = array(
- 'title' => 'Export',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('flag_export_form', FLAG_ADMIN_PATH_START + 1),
- 'access arguments' => array('administer flags'),
- 'file' => 'includes/flag.export.inc',
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 20,
- );
- $items[FLAG_ADMIN_PATH . '/manage/%flag/delete'] = array(
- 'title' => 'Delete flag',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('flag_delete_confirm', FLAG_ADMIN_PATH_START + 1),
- 'access callback' => 'user_access',
- 'access arguments' => array('administer flags'),
- 'file' => 'includes/flag.admin.inc',
- 'type' => MENU_CALLBACK,
- );
- $items[FLAG_ADMIN_PATH . '/manage/%flag/update'] = array(
- 'load arguments' => array(TRUE), // Allow for disabled flags.
- 'title' => 'Update',
- 'page callback' => 'flag_update_page',
- 'page arguments' => array(FLAG_ADMIN_PATH_START + 1),
- 'access arguments' => array('administer flags'),
- 'file' => 'includes/flag.export.inc',
- 'type' => MENU_CALLBACK,
- );
- $items['flag/%/%flag/%'] = array(
- 'title' => 'Flag',
- 'page callback' => 'flag_page',
- 'page arguments' => array(1, 2, 3),
- 'access callback' => 'user_access',
- 'access arguments' => array('access content'),
- 'file' => 'includes/flag.pages.inc',
- 'type' => MENU_CALLBACK,
- );
- $items['flag/confirm/%/%flag/%'] = array(
- 'title' => 'Flag confirm',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('flag_confirm', 2, 3, 4),
- 'access callback' => 'user_access',
- 'access arguments' => array('access content'),
- 'file' => 'includes/flag.pages.inc',
- 'type' => MENU_CALLBACK,
- );
-*/
- return $items;
-}
+}*/
/**
* Implements hook_admin_menu_map().
@@ -235,15 +152,6 @@ function flag_load($flag_name, $include_disabled = FALSE) {
// A menu loader has to return FALSE (not NULL) when no object is found.
return FALSE;
}
-
-/**
- * Menu title callback.
- */
-function _flag_menu_title($flag) {
- // The following conditional it to handle a D7 bug (@todo: link).
- return $flag ? $flag->label : '';
-}
-
/**
* Implements hook_help().
*/
@@ -365,33 +273,6 @@ function flag_get_types() {
return $types;
}
-/**
- * Instantiates a new flag handler.
- *
- * A flag handler is more commonly know as "a flag". A factory method usually
- * populates this empty flag with settings loaded from the database.
- *
- * @param $entity_type
- * The entity type to create a flag handler for. This may be FALSE if the
- * entity type property could not be found in the flag configuration data.
- *
- * @return
- * A flag handler object. This may be the special class BrokenFlag is there is
- * a problem with the flag.
- */
-function flag_create_handler($entity_type) {
- $definition = flag_fetch_definition($entity_type);
- if (isset($definition) && class_exists($definition['handler'])) {
- $handler = new $definition['handler'];
- }
- else {
- $handler = new \Drupal\flag\Handlers\BrokenFlag();
- }
- $handler->entity_type = $entity_type;
- $handler->construct();
- return $handler;
-}
-
/**
* Implements hook_permission().
*/
@@ -690,52 +571,6 @@ function flag_field_attach_save($entity_type, $entity) {
}
}
-/*
- * Implements hook_contextual_links_view_alter().
- */
-function flag_contextual_links_view_alter(&$element, $items) {
-/*
- if (isset($element['#element']['#entity_type'])) {
- $entity_type = $element['#element']['#entity_type'];
-
- // Get the entity out of the element. This requires a bit of legwork.
- if (isset($element['#element']['#entity'])) {
- // EntityAPI entities will all have the entity in the same place.
- $entity = $element['#element']['#entity'];
- }
- elseif (isset($element['#element']['#' . $entity_type])) {
- // Node module at least puts it here.
- $entity = $element['#element']['#' . $entity_type];
- }
- else {
- // Give up.
- return;
- }
-
- // Get all possible flags for this entity type.
- $flags = flag_get_flags($entity_type);
-
- foreach ($flags as $name => $flag) {
- if (!$flag->show_contextual_link) {
- continue;
- }
-
- list($entity_id) = entity_extract_ids($entity_type, $entity);
- if (!$flag->access($entity_id) && (!$flag->is_flagged($entity_id) || !$flag->access($entity_id, 'flag'))) {
- // User has no permission to use this flag or flag does not apply to this
- // object. The link is not skipped if the user has "flag" access but
- // not "unflag" access (this way the unflag denied message is shown).
- continue;
- }
-
- $element['#links']['flag-'. $name] = array(
- 'title' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id),
- 'html' => TRUE,
- );
- }
- }*/
-}
-
/**
* Implements hook_entity_view().
*
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 2515ae2..6c74265 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -315,6 +315,11 @@ public function preSave(EntityStorageInterface $storage_controller) {
// Save the Link Type configuration.
$linkTypePlugin = $this->getLinkTypePlugin();
$this->set('linkTypeConfig', $linkTypePlugin->getConfiguration());
+
+ // Reset the render cache for the entity.
+ \Drupal::entityManager()
+ ->getViewBuilder($this->getFlaggableEntityType())
+ ->resetCache();
}
public function toArray() {
diff --git a/lib/Drupal/flag/Handlers/AbstractFlag.php b/lib/Drupal/flag/Handlers/AbstractFlag.php
deleted file mode 100644
index a43ebad..0000000
--- a/lib/Drupal/flag/Handlers/AbstractFlag.php
+++ /dev/null
@@ -1,1541 +0,0 @@
-construct() on the new handler object.
- */
-class AbstractFlag {
-
- /**
- * The database ID.
- *
- * NULL for flags that haven't been saved to the database yet.
- *
- * @var integer
- */
- var $fid = NULL;
-
- /**
- * The entity type this flag works with.
- *
- * @var string
- */
- var $entity_type = NULL;
-
- /**
- * The flag's "machine readable" name.
- *
- * @var string
- */
- var $name = '';
-
- /**
- * The human-readable title for this flag.
- *
- * @var string
- */
- var $title = '';
-
- /**
- * Whether this flag state should act as a single toggle to all users.
- *
- * @var bool
- */
- var $global = FALSE;
-
- /**
- * The sub-types, AKA bundles, this flag applies to.
- *
- * This may be an empty array to indicate all types apply.
- *
- * @var array
- */
- var $types = array();
-
- /**
- * The roles array. This can be populated by fetch_roles() when needed.
- */
- var $roles = array(
- 'flag' => array(),
- 'unflag' => array(),
- );
-
- /**
- * An associative array containing textual errors that may be created during validation.
- *
- * The array keys should reflect the type of error being set. At this time,
- * the only "special" behavior related to the array keys is that
- * drupal_access_denied() is called when the key is 'access-denied' and
- * javascript is disabled.
- *
- * @var array
- */
- var $errors = array();
-
- /**
- * Creates a flag from a database row. Returns it.
- *
- * This is static method.
- *
- * The reason this isn't a non-static instance method --like Views's init()--
- * is because the class to instantiate changes according to the 'entity_type'
- * database column. This design pattern is known as the "Single Table
- * Inheritance".
- */
- static function factory_by_row($row) {
- $flag = flag_create_handler($row->entity_type);
-
- // Lump all data unto the object...
- foreach ($row as $field => $value) {
- $flag->$field = $value;
- }
- // ...but skip the following two.
- unset($flag->options, $flag->type);
-
- // Populate the options with the defaults.
- $options = (array) unserialize($row->options);
- $options += $flag->options();
-
- // Make the unserialized options accessible as normal properties.
- foreach ($options as $option => $value) {
- $flag->$option = $value;
- }
-
- if (!empty($row->type)) {
- // The loop loading from the database should further populate this property.
- $flag->types[] = $row->type;
- }
-
- return $flag;
- }
-
- /**
- * Create a complete flag (except an FID) from an array definition.
- */
- static function factory_by_array($config) {
- // Allow for flags with a missing entity type.
- $config += array(
- 'entity_type' => FALSE,
- );
- $flag = flag_create_handler($config['entity_type']);
-
- foreach ($config as $option => $value) {
- $flag->$option = $value;
- }
-
- if (isset($config['locked']) && is_array($config['locked'])) {
- $flag->locked = drupal_map_assoc($config['locked']);
- }
-
- return $flag;
- }
-
- /**
- * Another factory method. Returns a new, "empty" flag; e.g., one suitable for
- * the "Add new flag" page.
- */
- static function factory_by_entity_type($entity_type) {
- return flag_create_handler($entity_type);
- }
-
- /**
- * Declares the options this flag supports, and their default values.
- *
- * Derived classes should want to override this.
- */
- function options() {
- $options = array(
- // The text for the "flag this" link for this flag.
- 'flag_short' => '',
- // The description of the "flag this" link.
- 'flag_long' => '',
- // Message displayed after flagging an entity.
- 'flag_message' => '',
- // Likewise but for unflagged.
- 'unflag_short' => '',
- 'unflag_long' => '',
- 'unflag_message' => '',
- 'unflag_denied_text' => '',
- // The link type used by the flag, as defined in hook_flag_link_type_info().
- 'link_type' => 'toggle',
- 'weight' => 0,
- );
-
- // Merge in options from the current link type.
- $link_type = $this->get_link_type();
- $options = array_merge($options, $link_type['options']);
-
- // Allow other modules to change the flag options.
- drupal_alter('flag_options', $options, $this);
- return $options;
- }
- /**
- * Provides a form for setting options.
- *
- * Derived classes should want to override this.
- */
- function options_form(&$form) {
- }
-
- /**
- * Default constructor. Loads the default options.
- */
- function construct() {
- $options = $this->options();
- foreach ($options as $option => $value) {
- $this->$option = $value;
- }
- }
-
- /**
- * Load this flag's role data from permissions.
- *
- * Loads an array of roles into the flag, where each key is an action ('flag'
- * and 'unflag'), and each value is a flat array of role ids which may perform
- * that action.
- *
- * This should only be used when a complete overview of a flag's permissions
- * is needed. Use $flag->access or $flag->user_access() instead.
- */
- function fetch_roles() {
- $actions = array('flag', 'unflag');
- foreach ($actions as $action) {
- // Build the permission string.
- $permission = "$action $this->name";
- // We want a flat array of rids rather than $rid => $role_name.
- $this->roles[$action] = array_keys(user_roles(FALSE, $permission));
- }
- }
-
- /**
- * Update the flag with settings entered in a form.
- */
- function form_input($form_values) {
- // Load the form fields indiscriminately unto the flag (we don't care about
- // stray FormAPI fields because we aren't touching unknown properties anyway.
- foreach ($form_values as $field => $value) {
- $this->$field = $value;
- }
- $this->types = array_values(array_filter($this->types));
- // Clear internal titles cache:
- $this->get_title(NULL, TRUE);
- }
-
- /**
- * Validates this flag's options.
- *
- * @return
- * A list of errors encountered while validating this flag's options.
- */
- function validate() {
- // TODO: It might be nice if this used automatic method discovery rather
- // than hard-coding the list of validate functions.
- return array_merge_recursive(
- $this->validate_name(),
- $this->validate_access()
- );
- }
-
- /**
- * Validates that the current flag's name is valid.
- *
- * @return
- * A list of errors encountered while validating this flag's name.
- */
- function validate_name() {
- $errors = array();
-
- // Ensure a safe machine name.
- if (!preg_match('/^[a-z_][a-z0-9_]*$/', $this->name)) {
- $errors['name'][] = array(
- 'error' => 'flag_name_characters',
- 'message' => t('The flag name may only contain lowercase letters, underscores, and numbers.'),
- );
- }
- // Ensure the machine name is unique.
- $flag = flag_get_flag($this->name);
- if (!empty($flag) && (!isset($this->fid) || $flag->fid != $this->fid)) {
- $errors['name'][] = array(
- 'error' => 'flag_name_unique',
- 'message' => t('Flag names must be unique. This flag name is already in use.'),
- );
- }
-
- return $errors;
- }
-
- /**
- * Validates that the current flag's access settings are valid.
- */
- function validate_access() {
- $errors = array();
-
- // Require an unflag access denied message a role is not allowed to unflag.
- if (empty($this->unflag_denied_text)) {
- foreach ($this->roles['flag'] as $key => $rid) {
- if ($rid && empty($this->roles['unflag'][$key])) {
- $errors['unflag_denied_text'][] = array(
- 'error' => 'flag_denied_text_required',
- 'message' => t('The "Unflag not allowed text" is required if any user roles are not allowed to unflag.'),
- );
- break;
- }
- }
- }
-
- // Do not allow unflag access without flag access.
- foreach ($this->roles['unflag'] as $key => $rid) {
- if ($rid && empty($this->roles['flag'][$key])) {
- $errors['roles'][] = array(
- 'error' => 'flag_roles_unflag',
- 'message' => t('Any user role that has the ability to unflag must also have the ability to flag.'),
- );
- break;
- }
- }
-
- return $errors;
- }
-
- /**
- * Fetches, possibly from some cache, an entity this flag works with.
- */
- function fetch_entity($entity_id, $object_to_remember = NULL) {
- static $cache = array();
- if (isset($object_to_remember)) {
- $cache[$entity_id] = $object_to_remember;
- }
- if (!array_key_exists($entity_id, $cache)) {
- $entity = $this->_load_entity($entity_id);
- $cache[$entity_id] = $entity ? $entity : NULL;
- }
- return $cache[$entity_id];
- }
-
- /**
- * Loads an entity this flag works with.
- * Derived classes must implement this.
- *
- * @abstract
- * @private
- * @static
- */
- function _load_entity($entity_id) {
- return NULL;
- }
-
- /**
- * Store an object in the flag handler's cache.
- *
- * This is needed because otherwise fetch_object() loads the object from the
- * database (by calling _load_entity()), whereas sometimes we want to fetch
- * an object that hasn't yet been saved to the database. Subsequent calls to
- * fetch_entity() return the remembered object.
- *
- * @param $entity_id
- * The ID of the object to cache.
- * @param $object
- * The object to cache.
- */
- function remember_entity($entity_id, $object) {
- $this->fetch_entity($entity_id, $object);
- }
-
- /**
- * @defgroup access Access control
- * @{
- */
-
- /**
- * Returns TRUE if the flag applies to the given entity.
- *
- * Derived classes must implement this.
- *
- * @abstract
- */
- function applies_to_entity($entity) {
- return FALSE;
- }
-
- /**
- * Returns TRUE if the flag applies to the entity with the given ID.
- *
- * This is a convenience method that simply loads the object and calls
- * applies_to_entity(). If you already have the object, don't call
- * this function: call applies_to_entity() directly.
- */
- function applies_to_entity_id($entity_id) {
- return $this->applies_to_entity($this->fetch_entity($entity_id));
- }
-
- /**
- * Provides permissions for this flag.
- *
- * @return
- * An array of permissions for hook_permission().
- */
- function get_permissions() {
- return array(
- "flag $this->name" => array(
- 'title' => t('Flag %flag_title', array(
- '%flag_title' => $this->title,
- )),
- ),
- "unflag $this->name" => array(
- 'title' => t('Unflag %flag_title', array(
- '%flag_title' => $this->title,
- )),
- ),
- );
- }
-
- /**
- * Determines whether the user has the permission to use this flag.
- *
- * @param $action
- * (optional) The action to test, either "flag" or "unflag". If none given,
- * "flag" will be tested, which is the minimum permission to use a flag.
- * @param $account
- * (optional) The user object. If none given, the current user will be used.
- *
- * @return
- * Boolean TRUE if the user is allowed to flag/unflag. FALSE otherwise.
- *
- * @see flag_permission()
- */
- function user_access($action = 'flag', $account = NULL) {
- if (!isset($account)) {
- $account = $GLOBALS['user'];
- }
-
- // Anonymous user can't use this system unless Session API is installed.
- if ($account->uid == 0 && !module_exists('session_api')) {
- return FALSE;
- }
-
- $permission_string = "$action $this->name";
- return user_access($permission_string, $account);
- }
-
- /**
- * Determines whether the user may flag, or unflag, the given entity.
- *
- * This method typically should not be overridden by child classes. Instead
- * they should implement type_access(), which is called by this method.
- *
- * @param $entity_id
- * The entity ID to flag/unflag.
- * @param $action
- * The action to test. Either 'flag' or 'unflag'. Leave NULL to determine
- * by flag status.
- * @param $account
- * The user on whose behalf to test the flagging action. Leave NULL for the
- * current user.
- *
- * @return
- * Boolean TRUE if the user is allowed to flag/unflag the given entity.
- * FALSE otherwise.
- */
- function access($entity_id, $action = NULL, $account = NULL) {
- if (!isset($account)) {
- $account = $GLOBALS['user'];
- }
-
- if (isset($entity_id) && !$this->applies_to_entity_id($entity_id)) {
- // Flag does not apply to this entity.
- return FALSE;
- }
-
- if (!isset($action)) {
- $uid = $account->uid;
- $sid = flag_get_sid($uid);
- $action = $this->is_flagged($entity_id, $uid, $sid) ? 'unflag' : 'flag';
- }
-
- // Base initial access on the user's basic permission to use this flag.
- $access = $this->user_access($action, $account);
-
- // Check for additional access rules provided by sub-classes.
- $child_access = $this->type_access($entity_id, $action, $account);
- if (isset($child_access)) {
- $access = $child_access;
- }
-
- // Allow modules to disallow (or allow) access to flagging.
- // We grant access to the flag if both of the following conditions are met:
- // - No modules say to deny access.
- // - At least one module says to grant access.
- // If no module specified either allow or deny, we fall back to the
- // default access check above.
- $module_access = module_invoke_all('flag_access', $this, $entity_id, $action, $account);
- if (in_array(FALSE, $module_access, TRUE)) {
- $access = FALSE;
- }
- elseif (in_array(TRUE, $module_access, TRUE)) {
- // WARNING: This allows modules to bypass the default access check!
- $access = TRUE;
- }
-
- return $access;
- }
-
- /**
- * Determine access to multiple objects.
- *
- * Similar to user_access() but works on multiple IDs at once. Called in the
- * pre_render() stage of the 'Flag links' field within Views to find out where
- * that link applies. The reason we do a separate DB query, and not lump this
- * test in the Views query, is to make 'many to one' tests possible without
- * interfering with the rows, and also to reduce the complexity of the code.
- *
- * This method typically should not be overridden by child classes. Instead
- * they should implement type_access_multiple(), which is called by this
- * method.
- *
- * @param $entity_ids
- * The array of entity IDs to check. The keys are the entity IDs, the
- * values are the actions to test: either 'flag' or 'unflag'.
- * @param $account
- * (optional) The account for which the actions will be compared against.
- * If left empty, the current user will be used.
- *
- * @return
- * An array whose keys are the object IDs and values are booleans indicating
- * access.
- *
- * @see hook_flag_access_multiple()
- */
- function access_multiple($entity_ids, $account = NULL) {
- $account = isset($account) ? $account : $GLOBALS['user'];
- $access = array();
-
- // First check basic user access for this action.
- foreach ($entity_ids as $entity_id => $action) {
- $access[$entity_id] = $this->user_access($entity_ids[$entity_id], $account);
- }
-
- // Check for additional access rules provided by sub-classes.
- $child_access = $this->type_access_multiple($entity_ids, $account);
- if (isset($child_access)) {
- foreach ($child_access as $entity_id => $entity_access) {
- if (isset($entity_access)) {
- $access[$entity_id] = $entity_access;
- }
- }
- }
-
- // Merge in module-defined access.
- foreach (module_implements('flag_access_multiple') as $module) {
- $module_access = module_invoke($module, 'flag_access_multiple', $this, $entity_ids, $account);
- foreach ($module_access as $entity_id => $entity_access) {
- if (isset($entity_access)) {
- $access[$entity_id] = $entity_access;
- }
- }
- }
-
- return $access;
- }
-
- /**
- * Implements access() implemented by each child class.
- *
- * @abstract
- *
- * @return
- * FALSE if access should be denied, or NULL if there is no restriction to
- * be made. This should NOT return TRUE.
- */
- function type_access($entity_id, $action, $account) {
- return NULL;
- }
-
- /**
- * Implements access_multiple() implemented by each child class.
- *
- * @abstract
- *
- * @return
- * An array keyed by entity ids, whose values represent the access to the
- * corresponding entity. The access value may be FALSE if access should be
- * denied, or NULL (or not set) if there is no restriction to be made. It
- * should NOT be TRUE.
- */
- function type_access_multiple($entity_ids, $account) {
- return array();
- }
-
- /**
- * @} End of "defgroup access".
- */
-
- /**
- * Given an entity, returns its ID.
- * Derived classes must implement this.
- *
- * @abstract
- */
- function get_entity_id($entity) {
- return NULL;
- }
-
- /**
- * Utility function: Checks whether a flag applies to a certain type, and
- * possibly subtype, of entity.
- *
- * @param $entity_type
- * The type of entity being checked, such as "node".
- * @param $content_subtype
- * The subtype being checked. For entities this will be the bundle name (the
- * node type in the case of nodes).
- *
- * @return
- * TRUE if the flag is enabled for this type and subtype.
- */
- function access_entity_enabled($entity_type, $content_subtype = NULL) {
- $entity_type_matches = ($this->entity_type == $entity_type);
- $sub_type_matches = FALSE;
- if (!isset($content_subtype) || !count($this->types)) {
- // Subtype automatically matches if we're not asked about it,
- // or if the flag applies to all subtypes.
- $sub_type_matches = TRUE;
- }
- else {
- $sub_type_matches = in_array($content_subtype, $this->types);
- }
- return $entity_type_matches && $sub_type_matches;
- }
-
- /**
- * Determine whether the flag should show a flag link in entity links.
- *
- * Derived classes are likely to implement this.
- *
- * @param $view_mode
- * The view mode of the entity being displayed.
- *
- * @return
- * A boolean indicating whether the flag link is to be shown in entity
- * links.
- */
- function shows_in_entity_links($view_mode) {
- return FALSE;
- }
-
- /**
- * Returns TRUE if this flag requires anonymous user cookies.
- */
- function uses_anonymous_cookies() {
- global $user;
- return $user->uid == 0 && variable_get('cache', 0);
- }
-
- /**
- * Flags, or unflags, an item.
- *
- * @param $action
- * Either 'flag' or 'unflag'.
- * @param $entity_id
- * The ID of the item to flag or unflag.
- * @param $account
- * The user on whose behalf to flag. Leave empty for the current user.
- * @param $skip_permission_check
- * Flag the item even if the $account user don't have permission to do so.
- * @param $flagging
- * (optional) This method works in tandem with Drupal's Field subsystem.
- * Pass in a flagging entity if you want operate on it as well.
- *
- * @return
- * FALSE if some error occured (e.g., user has no permission, flag isn't
- * applicable to the item, etc.), TRUE otherwise.
- */
- function flag($action, $entity_id, $account = NULL, $skip_permission_check = FALSE, $flagging = NULL) {
- // Get the user.
- if (!isset($account)) {
- $account = $GLOBALS['user'];
- }
- if (!$account) {
- return FALSE;
- }
-
- // Check access and applicability.
- if (!$skip_permission_check) {
- if (!$this->access($entity_id, $action, $account)) {
- $this->errors['access-denied'] = t('You are not allowed to flag, or unflag, this content.');
- // User has no permission to flag/unflag this object.
- return FALSE;
- }
- }
- else {
- // We are skipping permission checks. However, at a minimum we must make
- // sure the flag applies to this entity type:
- if (!$this->applies_to_entity_id($entity_id)) {
- $this->errors['entity-type'] = t('This flag does not apply to this entity type.');
- return FALSE;
- }
- }
-
- if (($this->errors = module_invoke_all('flag_validate', $action, $this, $entity_id, $account, $skip_permission_check, $flagging))) {
- return FALSE;
- }
-
- // Clear various caches; We don't want code running after us to report
- // wrong counts or false flaggings.
- drupal_static_reset('flag_get_counts');
- drupal_static_reset('flag_get_user_flags');
- drupal_static_reset('flag_get_entity_flags');
-
- // Find out which user id to use.
- $uid = $this->global ? 0 : $account->uid;
-
- // Find out which session id to use.
- if ($this->global) {
- $sid = 0;
- }
- else {
- $sid = flag_get_sid($uid, TRUE);
- // Anonymous users must always have a session id.
- if ($sid == 0 && $account->uid == 0) {
- $this->errors['session'] = t('Internal error: You are anonymous but you have no session ID.');
- return FALSE;
- }
- }
-
- // Set our uid and sid to the flagging object.
- if (isset($flagging)) {
- $flagging->uid = $uid;
- $flagging->sid = $sid;
- }
-
- // @todo: Discuss: Should we call field_attach_validate()? None of the
- // entities in core does this (fields entered through forms are already
- // validated).
- //
- // @todo: Discuss: Core wraps everything in a try { }, should we?
-
- // Perform the flagging or unflagging of this flag.
- $existing_flagging_id = $this->_is_flagged($entity_id, $uid, $sid);
- $flagged = (bool) $existing_flagging_id;
- if ($action == 'unflag') {
- if ($this->uses_anonymous_cookies()) {
- $this->_unflag_anonymous($entity_id);
- }
- if ($flagged) {
- if (!isset($flagging)) {
- $flagging = flagging_load($existing_flagging_id);
- }
- $transaction = db_transaction();
- try {
- // Note the order: We decrease the count first so hooks have accurate
- // data, then invoke hooks, then delete the flagging entity.
- $this->_decrease_count($entity_id);
- module_invoke_all('flag_unflag', $this, $entity_id, $account, $flagging);
- // Invoke Rules event.
- if (module_exists('rules')) {
- $event_name = 'flag_unflagged_' . $this->name;
- // We only support flags on entities.
- if (entity_get_info($this->entity_type)) {
- $variables = array(
- 'flag' => $this,
- 'flagged_' . $this->entity_type => $entity_id,
- 'flagging_user' => $account,
- 'flagging' => $flagging,
- );
- rules_invoke_event_by_args($event_name, $variables);
- }
- }
- $this->_delete_flagging($flagging);
- $this->_unflag($entity_id, $flagging->flagging_id);
- }
- catch (Exception $e) {
- $transaction->rollback();
- watchdog_exception('flag', $e);
- throw $e;
- }
- }
- }
- elseif ($action == 'flag') {
- if ($this->uses_anonymous_cookies()) {
- $this->_flag_anonymous($entity_id);
- }
- if (!$flagged) {
- // The entity is unflagged. By definition there is no flagging entity,
- // but we may have been passed one in to save.
- if (!isset($flagging)) {
- // Construct a new flagging object if we don't have one.
- $flagging = $this->new_flagging($entity_id, $uid, $sid);
- }
- // Save the flagging entity (just our table).
- $flagging_id = $this->_flag($entity_id, $uid, $sid);
- // The _flag() method is a plain DB record writer, so it's a bit
- // antiquated. We have to explicitly get our new ID out.
- $flagging->flagging_id = $flagging_id;
- $this->_increase_count($entity_id);
- // We're writing out a flagging entity even when we aren't passed one
- // (e.g., when flagging via JavaScript toggle links); in this case
- // Field API will assign the fields their default values.
- $this->_insert_flagging($flagging);
- module_invoke_all('flag_flag', $this, $entity_id, $account, $flagging);
- // Invoke Rules event.
- if (module_exists('rules')) {
- $event_name = 'flag_flagged_' . $this->name;
- // We only support flags on entities.
- if (entity_get_info($this->entity_type)) {
- $variables = array(
- 'flag' => $this,
- 'flagged_' . $this->entity_type => $entity_id,
- 'flagging_user' => $account,
- 'flagging' => $this->get_flagging($entity_id, $account->uid),
- );
- rules_invoke_event_by_args($event_name, $variables);
- }
- }
- }
- else {
- // Nothing to do. Item is already flagged.
- //
- // Except in the case a $flagging object is passed in: in this case
- // we're, for example, arriving from an editing form and need to update
- // the entity.
- if ($flagging) {
- $this->_update_flagging($flagging);
- }
- }
- }
-
- return TRUE;
- }
-
- /**
- * The entity CRUD methods _{insert,update,delete}_flagging() are for private
- * use by the flag() method.
- *
- * The reason programmers should not call them directly is because a flagging
- * operation is also accompanied by some bookkeeping (calling hooks, updating
- * counters) or access control. These tasks are handled by the flag() method.
- */
- private function _insert_flagging($flagging) {
- field_attach_presave('flagging', $flagging);
- field_attach_insert('flagging', $flagging);
- }
- private function _update_flagging($flagging) {
- field_attach_presave('flagging', $flagging);
- field_attach_update('flagging', $flagging);
- // Update the cache.
- entity_get_controller('flagging')->resetCache();
- }
- private function _delete_flagging($flagging) {
- field_attach_delete('flagging', $flagging);
- // Remove from the cache.
- entity_get_controller('flagging')->resetCache();
- }
-
- /**
- * Construct a new, empty flagging entity object.
- *
- * @param mixed $entity_id
- * The unique identifier of the object being flagged.
- * @param int $uid
- * (optional) The user id of the user doing the flagging.
- * @param mixed $sid
- * (optional) The user SID (provided by Session API) who is doing the
- * flagging. The SID is 0 for logged in users.
- *
- * @return stdClass
- * The returned object has at least the 'flag_name' property set, which
- * enables Field API to figure out the bundle, but it's your responsibility
- * to eventually populate 'entity_id' and 'flagging_id'.
- */
- function new_flagging($entity_id = NULL, $uid = NULL, $sid = NULL) {
- return (object) array(
- 'flagging_id' => NULL,
- 'flag_name' => $this->name,
- 'entity_id' => $entity_id,
- 'uid' => $uid,
- 'sid' => $sid,
- );
- }
-
- /**
- * Determines if a certain user has flagged this object.
- *
- * Thanks to using a cache, inquiring several different flags about the same
- * item results in only one SQL query.
- *
- * @param $uid
- * (optional) The user ID whose flags we're checking. If none given, the
- * current user will be used.
- *
- * @return
- * TRUE if the object is flagged, FALSE otherwise.
- */
- function is_flagged($entity_id, $uid = NULL, $sid = NULL) {
- return (bool) $this->get_flagging_record($entity_id, $uid, $sid);
- }
-
- /**
- * Returns the flagging record.
- *
- * This method returns the "flagging record": the {flagging} record that
- * exists for each flagged item (for a certain user). If the item isn't
- * flagged, returns NULL. This method could be useful, for example, when you
- * want to find out the 'flagging_id' or 'timestamp' values.
- *
- * Thanks to using a cache, inquiring several different flags about the same
- * item results in only one SQL query.
- *
- * Parameters are the same as is_flagged()'s.
- */
- function get_flagging_record($entity_id, $uid = NULL, $sid = NULL) {
- $uid = $this->global ? 0 : (!isset($uid) ? $GLOBALS['user']->uid : $uid);
- $sid = $this->global ? 0 : (!isset($sid) ? flag_get_sid($uid) : $sid);
-
- // flag_get_user_flags() does caching.
- $user_flags = flag_get_user_flags($this->entity_type, $entity_id, $uid, $sid);
- return isset($user_flags[$this->name]) ? $user_flags[$this->name] : NULL;
- }
-
- /**
- * Similar to is_flagged() excepts it returns the flagging entity.
- */
- function get_flagging($entity_id, $uid = NULL, $sid = NULL) {
- if (($record = $this->get_flagging_record($entity_id, $uid, $sid))) {
- return flagging_load($record->flagging_id);
- }
- }
-
- /**
- * Determines if a certain user has flagged this object.
- *
- * You probably shouldn't call this raw private method: call the
- * is_flagged() method instead.
- *
- * This method is similar to is_flagged() except that it does direct SQL and
- * doesn't do caching. Use it when you want to not affect the cache, or to
- * bypass it.
- *
- * @return
- * If the object is flagged, returns the value of the 'flagging_id' column.
- * Else, returns FALSE.
- *
- * @private
- */
- function _is_flagged($entity_id, $uid, $sid) {
- return db_select('flagging', 'fc')
- ->fields('fc', array('flagging_id'))
- ->condition('fid', $this->fid)
- ->condition('uid', $uid)
- ->condition('sid', $sid)
- ->condition('entity_id', $entity_id)
- ->execute()
- ->fetchField();
- }
-
- /**
- * A low-level method to flag an object.
- *
- * You probably shouldn't call this raw private method: call the flag()
- * function instead.
- *
- * @return
- * The 'flagging_id' column of the new {flagging} record.
- *
- * @private
- */
- function _flag($entity_id, $uid, $sid) {
- $flagging_id = db_insert('flagging')
- ->fields(array(
- 'fid' => $this->fid,
- 'entity_type' => $this->entity_type,
- 'entity_id' => $entity_id,
- 'uid' => $uid,
- 'sid' => $sid,
- 'timestamp' => REQUEST_TIME,
- ))
- ->execute();
- return $flagging_id;
- }
-
- /**
- * A low-level method to unflag an object.
- *
- * You probably shouldn't call this raw private method: call the flag()
- * function instead.
- *
- * @private
- */
- function _unflag($entity_id, $flagging_id) {
- db_delete('flagging')->condition('flagging_id', $flagging_id)->execute();
- }
-
- /**
- * Increases the flag count for an object.
- *
- * @param $entity_id
- * For which item should the count be increased.
- * @param $number
- * The amount of counts to increasing. Defaults to 1.
- *
- * @private
- */
- function _increase_count($entity_id, $number = 1) {
- db_merge('flag_counts')
- ->key(array(
- 'fid' => $this->fid,
- 'entity_id' => $entity_id,
- ))
- ->fields(array(
- 'entity_type' => $this->entity_type,
- 'count' => $number,
- 'last_updated' => REQUEST_TIME,
- ))
- ->updateFields(array(
- 'last_updated' => REQUEST_TIME,
- ))
- ->expression('count', 'count + :inc', array(':inc' => $number))
- ->execute();
- }
-
- /**
- * Decreases the flag count for an object.
- *
- * @param $entity_id
- * For which item should the count be descreased.
- * @param $number
- * The amount of counts to decrease. Defaults to 1.
- *
- * @private
- */
- function _decrease_count($entity_id, $number = 1) {
- // Delete rows with count 0, for data consistency and space-saving.
- // Done before the db_update() to prevent out-of-bounds errors on "count".
- db_delete('flag_counts')
- ->condition('fid', $this->fid)
- ->condition('entity_id', $entity_id)
- ->condition('count', $number, '<=')
- ->execute();
-
- // Update the count with the new value otherwise.
- db_update('flag_counts')
- ->expression('count', 'count - :inc', array(':inc' => $number))
- ->fields(array(
- 'last_updated' => REQUEST_TIME,
- ))
- ->condition('fid', $this->fid)
- ->condition('entity_id', $entity_id)
- ->execute();
- }
-
- /**
- * Set a cookie for anonymous users to record their flagging.
- *
- * @private
- */
- function _flag_anonymous($entity_id) {
- $storage = FlagCookieStorage::factory($this);
- $storage->flag($entity_id);
- }
-
- /**
- * Remove the cookie for anonymous users to record their unflagging.
- *
- * @private
- */
- function _unflag_anonymous($entity_id) {
- $storage = FlagCookieStorage::factory($this);
- $storage->unflag($entity_id);
- }
-
- /**
- * Returns the number of times an item is flagged.
- *
- * Thanks to using a cache, inquiring several different flags about the same
- * item results in only one SQL query.
- */
- function get_count($entity_id) {
- $counts = flag_get_counts($this->entity_type, $entity_id);
- return isset($counts[$this->name]) ? $counts[$this->name] : 0;
- }
-
- /**
- * Returns the number of items a user has flagged.
- *
- * For global flags, pass '0' as the user ID and session ID.
- */
- function get_user_count($uid, $sid = NULL) {
- if (!isset($sid)) {
- $sid = flag_get_sid($uid);
- }
- return db_select('flagging', 'fc')->fields('fc', array('flagging_id'))
- ->condition('fid', $this->fid)
- ->condition('uid', $uid)
- ->condition('sid', $sid)
- ->countQuery()
- ->execute()
- ->fetchField();
- }
-
- /**
- * Processes a flag label for display. This means language translation and
- * token replacements.
- *
- * You should always call this function and not get at the label directly.
- * E.g., do `print $flag->get_label('title')` instead of `print
- * $flag->title`.
- *
- * @param $label
- * The label to get, e.g. 'title', 'flag_short', 'unflag_short', etc.
- * @param $entity_id
- * The ID in whose context to interpret tokens. If not given, only global
- * tokens will be substituted.
- * @return
- * The processed label.
- */
- function get_label($label, $entity_id = NULL) {
- if (!isset($this->$label)) {
- return;
- }
- $label = t($this->$label);
- if (strpos($label, '[') !== FALSE) {
- $label = $this->replace_tokens($label, array(), array('sanitize' => FALSE), $entity_id);
- }
- return filter_xss_admin($label);
- }
-
- /**
- * Get the link type for this flag.
- */
- function get_link_type() {
- $link_types = flag_get_link_types();
- return (isset($this->link_type) && isset($link_types[$this->link_type])) ? $link_types[$this->link_type] : $link_types['normal'];
- }
-
- /**
- * Replaces tokens in a label. Only the 'global' token context is recognized
- * by default, so derived classes should override this method to add all
- * token contexts they understand.
- */
- function replace_tokens($label, $contexts, $options, $entity_id) {
- if (strpos($label , 'flagging:') !== FALSE) {
- if (($flagging = $this->get_flagging($entity_id))) {
- $contexts['flagging'] = $flagging;
- }
- }
- return token_replace($label, $contexts, $options);
- }
-
- /**
- * Returns the token types this flag understands in labels. These are used
- * for narrowing down the token list shown in the help box to only the
- * relevant ones.
- *
- * Derived classes should override this.
- */
- function get_labels_token_types() {
- return array('flagging');
- }
-
- /**
- * A convenience method for getting the flag title.
- *
- * `$flag->get_title()` is shorthand for `$flag->get_label('title')`.
- */
- function get_title($entity_id = NULL, $reset = FALSE) {
- static $titles = array();
- if ($reset) {
- $titles = array();
- }
- $slot = intval($entity_id); // Convert NULL to 0.
- if (!isset($titles[$this->fid][$slot])) {
- $titles[$this->fid][$slot] = $this->get_label('title', $entity_id);
- }
- return $titles[$this->fid][$slot];
- }
-
- /**
- * Returns a 'flag action' object. It exists only for the sake of its
- * informative tokens. Currently, it's utilized only for the 'mail' action.
- *
- * Derived classes should populate the 'content_title' and 'content_url'
- * slots.
- */
- function get_flag_action($entity_id) {
- $flag_action = new stdClass();
- $flag_action->flag = $this->name;
- $flag_action->entity_type = $this->entity_type;
- $flag_action->entity_id = $entity_id;
- return $flag_action;
- }
-
- /**
- * Returns an array of errors set during validation.
- */
- function get_errors() {
- return $this->errors;
- }
-
- /**
- * @addtogroup actions
- * @{
- * Methods that can be overridden to support Actions.
- */
-
- /**
- * Returns an array of all actions that are executable with this flag.
- */
- function get_valid_actions() {
- $actions = module_invoke_all('action_info');
- foreach ($actions as $callback => $action) {
- if ($action['type'] != $this->entity_type && !in_array('any', $action['triggers'])) {
- unset($actions[$callback]);
- }
- }
- return $actions;
- }
-
- /**
- * Returns objects the action may possibly need. This method should return at
- * least the 'primary' object the action operates on.
- *
- * This method is needed because get_valid_actions() returns actions that
- * don't necessarily operate on an object of a type this flag manages. For
- * example, flagging a comment may trigger an 'Unpublish post' action on a
- * node; So the comment flag needs to tell the action about some node.
- *
- * Derived classes must implement this.
- *
- * @abstract
- */
- function get_relevant_action_objects($entity_id) {
- return array();
- }
-
- /**
- * @} End of "addtogroup actions".
- */
-
- /**
- * @addtogroup views
- * @{
- * Methods that can be overridden to support the Views module.
- */
-
- /**
- * Returns information needed for Views integration. E.g., the Views table
- * holding the flagged object, its primary key, and various labels. See
- * derived classes for examples.
- *
- * @static
- */
- function get_views_info() {
- return array();
- }
-
- /**
- * @} End of "addtogroup views".
- */
-
- /**
- * Saves a flag to the database. It is a wrapper around update() and insert().
- */
- function save() {
- // Allow the 'global' property to be a boolean, particularly when defined in
- // hook_flag_default_flags(). Without this, a value of FALSE gets casted to
- // an empty string which violates our schema. Other boolean properties are
- // fine, as they are serialized.
- $this->global = (int) $this->global;
-
- if (isset($this->fid)) {
- $this->update();
- $this->is_new = FALSE;
- }
- else {
- $this->insert();
- $this->is_new = TRUE;
- }
- // Clear the page cache for anonymous users.
- cache()->deleteTags(array('content' => TRUE));
- }
-
- /**
- * Saves an existing flag to the database. Better use save().
- */
- function update() {
- db_update('flag')->fields(array(
- 'name' => $this->name,
- 'title' => $this->title,
- 'global' => $this->global,
- 'options' => $this->get_serialized_options()))
- ->condition('fid', $this->fid)
- ->execute();
- db_delete('flag_types')->condition('fid', $this->fid)->execute();
- foreach ($this->types as $type) {
- db_insert('flag_types')->fields(array(
- 'fid' => $this->fid,
- 'type' => $type))
- ->execute();
- }
- }
-
- /**
- * Saves a new flag to the database. Better use save().
- */
- function insert() {
- $this->fid = db_insert('flag')
- ->fields(array(
- 'entity_type' => $this->entity_type,
- 'name' => $this->name,
- 'title' => $this->title,
- 'global' => $this->global,
- 'options' => $this->get_serialized_options(),
- ))
- ->execute();
- foreach ($this->types as $type) {
- db_insert('flag_types')
- ->fields(array(
- 'fid' => $this->fid,
- 'type' => $type,
- ))
- ->execute();
- }
- }
-
- /**
- * Options are stored serialized in the database.
- */
- function get_serialized_options() {
- $option_names = array_keys($this->options());
- $options = array();
- foreach ($option_names as $option) {
- $options[$option] = $this->$option;
- }
- return serialize($options);
- }
-
- /**
- * Deletes a flag from the database.
- */
- function delete() {
- db_delete('flag')->condition('fid', $this->fid)->execute();
- db_delete('flagging')->condition('fid', $this->fid)->execute();
- db_delete('flag_types')->condition('fid', $this->fid)->execute();
- db_delete('flag_counts')->condition('fid', $this->fid)->execute();
- module_invoke_all('flag_delete', $this);
- }
-
- /**
- * Returns TRUE if this flag's declared API version is compatible with this
- * module.
- *
- * An "incompatible" flag is one exported (and now being imported or exposed
- * via hook_flag_default_flags()) by a different version of the Flag module.
- * An incompatible flag should be treated as a "black box": it should not be
- * saved or exported because our code may not know to handle its internal
- * structure.
- */
- function is_compatible() {
- if (isset($this->fid)) {
- // Database flags are always compatible.
- return TRUE;
- }
- else {
- if (!isset($this->api_version)) {
- $this->api_version = 1;
- }
- return $this->api_version == FLAG_API_VERSION;
- }
- }
-
- /**
- * Finds the "default flag" corresponding to this flag.
- *
- * Flags defined in code ("default flags") can be overridden. This method
- * returns the default flag that is being overridden by $this. Returns NULL
- * if $this overrides no default flag.
- */
- function find_default_flag() {
- if ($this->fid) {
- $default_flags = flag_get_default_flags(TRUE);
- if (isset($default_flags[$this->name])) {
- return $default_flags[$this->name];
- }
- }
- }
-
- /**
- * Reverts an overriding flag to its default state.
- *
- * Note that $this isn't altered. To see the reverted flag you'll have to
- * call flag_get_flag($this->name) again.
- *
- * @return
- * TRUE if the flag was reverted successfully; FALSE if there was an error;
- * NULL if this flag overrides no default flag.
- */
- function revert() {
- if (($default_flag = $this->find_default_flag())) {
- if ($default_flag->is_compatible()) {
- $default_flag = clone $default_flag;
- $default_flag->fid = $this->fid;
- $default_flag->save();
- drupal_static_reset('flag_get_flags');
- return TRUE;
- }
- else {
- return FALSE;
- }
- }
- }
-
- /**
- * Disable a flag provided by a module.
- */
- function disable() {
- if (isset($this->module)) {
- $flag_status = variable_get('flag_default_flag_status', array());
- $flag_status[$this->name] = FALSE;
- variable_set('flag_default_flag_status', $flag_status);
- }
- }
-
- /**
- * Enable a flag provided by a module.
- */
- function enable() {
- if (isset($this->module)) {
- $flag_status = variable_get('flag_default_flag_status', array());
- $flag_status[$this->name] = TRUE;
- variable_set('flag_default_flag_status', $flag_status);
- }
- }
-
- /**
- * Returns administrative menu path for carrying out some action.
- */
- function admin_path($action) {
- if ($action == 'edit') {
- // Since 'edit' is the default tab, we omit the action.
- return FLAG_ADMIN_PATH . '/manage/' . $this->name;
- }
- else {
- return FLAG_ADMIN_PATH . '/manage/' . $this->name . '/' . $action;
- }
- }
-
- /**
- * Renders a flag/unflag link.
- *
- * This is a wrapper around theme('flag') that channels the call to the right
- * template file.
- *
- * @param $action
- * The action the link is about to carry out, either "flag" or "unflag".
- * @param $entity_id
- * The ID of the object to flag.
- * @param $variables = array()
- * An array of further variables to pass to theme('flag'). For the full list
- * of parameters, see flag.tpl.php. Of particular interest:
- * - after_flagging: Set to TRUE if this flag link is being displayed as the result
- * of a flagging action.
- * - errors: An array of error messages.
- *
- * @return
- * The HTML for the flag link.
- */
- function theme($action, $entity_id, $variables = array()) {
- static $js_added = array();
- global $user;
-
- $after_flagging = !empty($variables['after_flagging']);
-
- // If the flagging user is anonymous, set a boolean for the benefit of
- // JavaScript code. Currently, only our "anti-crawlers" mechanism uses it.
- if ($user->uid == 0 && !isset($js_added['anonymous'])) {
- $js_added['anonymous'] = TRUE;
- drupal_add_js(array('flag' => array('anonymous' => TRUE)), 'setting');
- }
-
- // If the flagging user is anonymous and the page cache is enabled, we
- // update the links through JavaScript.
- if ($this->uses_anonymous_cookies() && !$after_flagging) {
- if ($this->global) {
- // In case of global flags, the JavaScript template is to contain
- // the opposite of the current state.
- $js_action = ($action == 'flag' ? 'unflag' : 'flag');
- }
- else {
- // In case of non-global flags, we always show the "flag!" link,
- // and then replace it with the "unflag!" link through JavaScript.
- $js_action = 'unflag';
- $action = 'flag';
- }
- if (!isset($js_added[$this->name . '_' . $entity_id])) {
- $js_added[$this->name . '_' . $entity_id] = TRUE;
- $js_template = theme($this->theme_suggestions(), array(
- 'flag' => $this,
- 'action' => $js_action,
- 'entity_id' => $entity_id,
- 'after_flagging' => $after_flagging,
- ));
- drupal_add_js(array('flag' => array('templates' => array($this->name . '_' . $entity_id => $js_template))), 'setting');
- }
- }
-
- return theme($this->theme_suggestions(), array(
- 'flag' => $this,
- 'action' => $action,
- 'entity_id' => $entity_id,
- ) + $variables);
- }
-
- /**
- * Provides an array of possible themes to try for a given flag.
- */
- function theme_suggestions() {
- $suggestions = array();
- $suggestions[] = 'flag__' . $this->name;
- $suggestions[] = 'flag__' . $this->link_type;
- $suggestions[] = 'flag';
- return $suggestions;
- }
-
- /**
- * A shortcut function to output the link URL.
- */
- function _flag_url($path, $fragment = NULL, $absolute = TRUE) {
- return url($path, array('fragment' => $fragment, 'absolute' => $absolute));
- }
-}
diff --git a/lib/Drupal/flag/Handlers/BrokenFlag.php b/lib/Drupal/flag/Handlers/BrokenFlag.php
deleted file mode 100644
index 0ea9d3e..0000000
--- a/lib/Drupal/flag/Handlers/BrokenFlag.php
+++ /dev/null
@@ -1,19 +0,0 @@
- $this->entity_type)), 'error');
- $form = array();
- }
-}
diff --git a/lib/Drupal/flag/Handlers/CommentFlag.php b/lib/Drupal/flag/Handlers/CommentFlag.php
deleted file mode 100644
index a0148dd..0000000
--- a/lib/Drupal/flag/Handlers/CommentFlag.php
+++ /dev/null
@@ -1,103 +0,0 @@
- '',
- );
- return $options;
- }
-
- /**
- * Options form extras for comment flags.
- */
- function options_form(&$form) {
- parent::options_form($form);
-
- $form['access']['access_author'] = array(
- '#type' => 'radios',
- '#title' => t('Flag access by content authorship'),
- '#options' => array(
- '' => t('No additional restrictions'),
- 'comment_own' => t('Users may only flag own comments'),
- 'comment_others' => t('Users may only flag comments by others'),
- 'node_own' => t('Users may only flag comments of nodes they own'),
- 'node_others' => t('Users may only flag comments of nodes by others'),
- ),
- '#default_value' => $this->access_author,
- '#description' => t("Restrict access to this flag based on the user's ownership of the content. Users must also have access to the flag through the role settings."),
- );
- }
-
- function type_access_multiple($entity_ids, $account) {
- $access = array();
-
- // If all subtypes are allowed, we have nothing to say here.
- if (empty($this->types)) {
- return $access;
- }
-
- // Ensure node types are granted access. This avoids a
- // node_load() on every type, usually done by applies_to_entity_id().
- $query = db_select('comment', 'c');
- $query->innerJoin('node', 'n', 'c.nid = n.nid');
- $result = $query
- ->fields('c', array('cid'))
- ->condition('c.cid', $entity_ids, 'IN')
- ->condition('n.type', $this->types, 'NOT IN')
- ->execute();
- foreach ($result as $row) {
- $access[$row->nid] = FALSE;
- }
-
- return $access;
- }
-
- function get_entity_id($comment) {
- // Store the comment object in the static cache, to avoid getting it
- // again unneedlessly.
- $this->remember_entity($comment->cid, $comment);
- return $comment->cid;
- }
-
- function get_labels_token_types() {
- return array_merge(array('comment', 'node'), parent::get_labels_token_types());
- }
-
- function replace_tokens($label, $contexts, $options, $entity_id) {
- if ($entity_id) {
- if (($comment = $this->fetch_entity($entity_id)) && ($node = node_load($comment->nid))) {
- $contexts['node'] = $node;
- $contexts['comment'] = $comment;
- }
- }
- return parent::replace_tokens($label, $contexts, $options, $entity_id);
- }
-
- function get_flag_action($entity_id) {
- $flag_action = parent::get_flag_action($entity_id);
- $comment = $this->fetch_entity($entity_id);
- $flag_action->content_title = $comment->subject;
- $flag_action->content_url = $this->_flag_url("comment/$comment->cid", "comment-$comment->cid");
- return $flag_action;
- }
-
- function get_relevant_action_objects($entity_id) {
- $comment = $this->fetch_entity($entity_id);
- return array(
- 'comment' => $comment,
- 'node' => node_load($comment->nid),
- );
- }
-}
diff --git a/lib/Drupal/flag/Handlers/Flag.php b/lib/Drupal/flag/Handlers/Flag.php
deleted file mode 100644
index f659049..0000000
--- a/lib/Drupal/flag/Handlers/Flag.php
+++ /dev/null
@@ -1,239 +0,0 @@
- array(),
- // Output the flag as individual pseudofields.
- 'show_as_field' => FALSE,
- // Add a checkbox for the flag in the entity form.
- // @see hook_field_attach_form().
- 'show_on_form' => FALSE,
- 'access_author' => '',
- 'show_contextual_link' => FALSE,
- );
- return $options;
- }
-
- /**
- * Options form extras for the generic entity flag.
- */
- function options_form(&$form) {
- $bundles = array();
- $bundle_info = entity_get_bundles($this->entity_type);
- foreach ($bundle_info as $bundle_key => $info) {
- $bundles[$bundle_key] = $info['label'];
- }
- $form['access']['types'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Bundles'),
- '#options' => $bundles,
- '#description' => t('Select the bundles that this flag may be used on. Leave blank to allow on all bundles for the entity type.'),
- '#default_value' => $this->types,
- );
-
- // Add checkboxes to show flag link on each entity view mode.
- $options = array();
- $defaults = array();
- $view_modes = entity_get_view_modes($this->entity_type);
- foreach ($view_modes as $name => $view_mode) {
- $options[$name] = t('Display on @name view mode', array('@name' => $view_mode['label']));
- $defaults[$name] = !empty($this->show_in_links[$name]) ? $name : 0;
- }
-
- $form['display']['show_in_links'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Display in entity links'),
- '#description' => t('Show the flag link with the other links on the entity.'),
- '#options' => $options,
- '#default_value' => $defaults,
- );
-
- $form['display']['show_as_field'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display link as field'),
- '#description' => t('Show the flag link as a pseudofield, which can be ordered among other entity elements in the "Manage display" settings for the entity type.'),
- '#default_value' => isset($this->show_as_field) ? $this->show_as_field : TRUE,
- );
- if (empty($entity_info['fieldable'])) {
- $form['display']['show_as_field']['#disabled'] = TRUE;
- $form['display']['show_as_field']['#description'] = t("This entity type is not fieldable.");
- }
-
- $form['display']['show_on_form'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display checkbox on entity edit form'),
- '#default_value' => $this->show_on_form,
- '#weight' => 5,
- );
-
- // We use FieldAPI to put the flag checkbox on the entity form, so therefore
- // require the entity to be fielable. Since this is a potential DX
- // headscratcher for a developer wondering where this option has gone,
- // we disable it and explain why.
- if (empty($entity_info['fieldable'])) {
- $form['display']['show_on_form']['#disabled'] = TRUE;
- $form['display']['show_on_form']['#description'] = t('This is only possible on entities which are fieldable.');
- }
- $form['display']['show_contextual_link'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display in contextual links'),
- '#default_value' => $this->show_contextual_link,
- '#description' => t('Note that not all entity types support contextual links.'),
- '#access' => module_exists('contextual'),
- '#weight' => 10,
- );
- }
-
- /**
- * Loads the entity object.
- */
- function _load_entity($entity_id) {
- if (is_numeric($entity_id)) {
- $entity = entity_load($this->entity_type, array($entity_id));
- return reset($entity);
- }
- return NULL;
- }
-
- /**
- * Checks whether the flag applies for the current entity bundle.
- */
- function applies_to_entity($entity) {
- $entity_info = entity_get_info($this->entity_type);
- // The following conditions are applied:
- // - if the types array is empty, the flag applies to all bundles and thus
- // to this entity.
- // - if the entity has no bundles, the flag applies to the entity.
- // - if the entity's bundle is in the list of types.
- if (empty($this->types) || empty($entity_info['entity keys']['bundle']) || in_array($entity->{$entity_info['entity keys']['bundle']}, $this->types)) {
- return TRUE;
- }
- return FALSE;
- }
-
- /**
- * Provides permissions for this flag.
- *
- * @return
- * An array of permissions for hook_permission().
- */
- function get_permissions() {
- // For entity flags, use the human label of the entity.
- $entity_info = entity_get_info($this->entity_type);
- $entity_label = $entity_info['label'];
- return array(
- "flag $this->name" => array(
- 'title' => t('Flag %entity entities as %flag_title', array(
- '%flag_title' => $this->title,
- '%entity' => $entity_label,
- )),
- ),
- "unflag $this->name" => array(
- 'title' => t('Unflag %entity entities as %flag_title', array(
- '%flag_title' => $this->title,
- '%entity' => $entity_label,
- )),
- ),
- );
- }
-
- /**
- * Returns the entity id, if it already exists.
- */
- function get_entity_id($entity) {
- $entity_info = entity_get_info($this->entity_type);
- if ($entity && isset($entity->{$entity_info['entity keys']['id']})) {
- return $entity->{$entity_info['entity keys']['id']};
- }
- }
-
- /**
- * Determine whether the flag should show a flag link in entity links.
- */
- function shows_in_entity_links($view_mode) {
- // Check for settings for the given view mode.
- if (isset($this->show_in_links[$view_mode])) {
- return (bool) $this->show_in_links[$view_mode];
- }
- return FALSE;
- }
-
- /**
- * Returns token types for the current entity type.
- */
- function get_labels_token_types() {
- // The token type name might be different to the entity type name. If so,
- // an own flag entity handler can be used for overriding this.
- return array_merge(array($this->entity_type), parent::get_labels_token_types());
- }
-
- /**
- * Replaces tokens.
- */
- function replace_tokens($label, $contexts, $options, $entity_id) {
- if ($entity_id && ($entity = $this->fetch_entity($entity_id))) {
- $contexts[$this->entity_type] = $entity;
- }
- return parent::replace_tokens($label, $contexts, $options, $entity_id);
- }
-
- /**
- * Returns a 'flag action' object.
- */
- function get_flag_action($entity_id) {
- $flag_action = parent::get_flag_action($entity_id);
- $entity = $this->fetch_entity($entity_id);
- $flag_action->content_title = entity_label($this->entity_type, $entity);
- $flag_action->content_url = $this->_flag_url($this->entity_type . '/' . $this->get_entity_id($entity));
- return $flag_action;
- }
-
- /**
- * Returns objects the action may possible need.
- */
- function get_relevant_action_objects($entity_id) {
- return array(
- $this->entity_type => $this->fetch_entity($entity_id),
- );
- }
-
- /**
- * Returns information for the Views integration.
- */
- function get_views_info() {
- $entity_info = entity_get_info($this->entity_type);
-
- if (!isset($entity_info['base table'])) {
- return NULL;
- }
-
- return array(
- 'views table' => $entity_info['base table'],
- 'join field' => $entity_info['entity keys']['id'],
- 'title field' => isset($entity_info['entity keys']['label']) ? $entity_info['entity keys']['label'] : '',
- 'title' => t('@entity_label flag', array('@entity_label' => $entity_info['label'])),
- 'help' => t('Limit results to only those entity flagged by a certain flag; Or display information about the flag set on a entity.'),
- 'counter title' => t('@entity_label flag counter', array('@entity_label' => $entity_info['label'])),
- 'counter help' => t('Include this to gain access to the flag counter field.'),
- );
- }
-}
diff --git a/lib/Drupal/flag/Handlers/NodeFlag.php b/lib/Drupal/flag/Handlers/NodeFlag.php
deleted file mode 100644
index 18a5b7f..0000000
--- a/lib/Drupal/flag/Handlers/NodeFlag.php
+++ /dev/null
@@ -1,122 +0,0 @@
- 0,
- );
- return $options;
- }
-
- /**
- * Options form extras for node flags.
- */
- function options_form(&$form) {
- parent::options_form($form);
-
- $form['access']['access_author'] = array(
- '#type' => 'radios',
- '#title' => t('Flag access by content authorship'),
- '#options' => array(
- '' => t('No additional restrictions'),
- 'own' => t('Users may only flag content they own'),
- 'others' => t('Users may only flag content of others'),
- ),
- '#default_value' => $this->access_author,
- '#description' => t("Restrict access to this flag based on the user's ownership of the content. Users must also have access to the flag through the role settings."),
- );
-
- // Support for i18n flagging requires Translation helpers module.
- $form['i18n'] = array(
- '#type' => 'radios',
- '#title' => t('Internationalization'),
- '#options' => array(
- '1' => t('Flag translations of content as a group'),
- '0' => t('Flag each translation of content separately'),
- ),
- '#default_value' => $this->i18n,
- '#description' => t('Flagging translations as a group effectively allows users to flag the original piece of content regardless of the translation they are viewing. Changing this setting will not update content that has been flagged already.'),
- '#access' => module_exists('translation_helpers'),
- '#weight' => 5,
- );
-
- // Override the UI texts for nodes.
- $form['display']['show_on_form'] = array(
- '#title' => t('Display checkbox on node edit form'),
- '#description' => t('If you elect to have a checkbox on the node edit form, you may specify its initial state in the settings form for each content type.', array('@content-types-url' => url('admin/structure/types'))),
- ) + $form['display']['show_on_form'];
- }
-
- function type_access_multiple($entity_ids, $account) {
- $access = array();
-
- // If all subtypes are allowed, we have nothing to say here.
- if (empty($this->types)) {
- return $access;
- }
-
- // Ensure that only flaggable node types are granted access. This avoids a
- // node_load() on every type, usually done by applies_to_entity_id().
- $result = db_select('node', 'n')->fields('n', array('nid'))
- ->condition('nid', array_keys($entity_ids), 'IN')
- ->condition('type', $this->types, 'NOT IN')
- ->execute();
- foreach ($result as $row) {
- $access[$row->nid] = FALSE;
- }
-
- return $access;
- }
-
- /**
- * Adjust the Content ID to find the translation parent if i18n-enabled.
- *
- * @param $entity_id
- * The nid for the content.
- * @return
- * The tnid if available, the nid otherwise.
- */
- function get_translation_id($entity_id) {
- if ($this->i18n) {
- $node = $this->fetch_entity($entity_id);
- if (!empty($node->tnid)) {
- $entity_id = $node->tnid;
- }
- }
- return $entity_id;
- }
-
- function flag($action, $entity_id, $account = NULL, $skip_permission_check = FALSE, $flagging = NULL) {
- $entity_id = $this->get_translation_id($entity_id);
- return parent::flag($action, $entity_id, $account, $skip_permission_check, $flagging);
- }
-
- // Instead of overriding is_flagged() we override get_flagging_record(),
- // which is the underlying method.
- function get_flagging_record($entity_id, $uid = NULL, $sid = NULL) {
- $entity_id = $this->get_translation_id($entity_id);
- return parent::get_flagging_record($entity_id, $uid, $sid);
- }
-
- /**
- * This is overridden for no other purpose than to document that $entity_id
- * can be one of the following fake IDs in certain contexts:
- * - 'new': On a new node form.
- * - 'fake': On the node type admin form.
- */
- function replace_tokens($label, $contexts, $options, $entity_id) {
- return parent::replace_tokens($label, $contexts, $options, $entity_id);
- }
-}
diff --git a/lib/Drupal/flag/Handlers/UserFlag.php b/lib/Drupal/flag/Handlers/UserFlag.php
deleted file mode 100644
index e009c5c..0000000
--- a/lib/Drupal/flag/Handlers/UserFlag.php
+++ /dev/null
@@ -1,99 +0,0 @@
- TRUE,
- 'access_uid' => '',
- );
- return $options;
- }
-
- /**
- * Options form extras for user flags.
- */
- function options_form(&$form) {
- parent::options_form($form);
- $form['access']['types'] = array(
- // A user flag doesn't support node types.
- // TODO: Maybe support roles instead of node types.
- '#type' => 'value',
- '#value' => array(0 => 0),
- );
- $form['access']['access_uid'] = array(
- '#type' => 'checkbox',
- '#title' => t('Users may flag themselves'),
- '#description' => t('Disabling this option may be useful when setting up a "friend" flag, when a user flagging themself does not make sense.'),
- '#default_value' => $this->access_uid ? 0 : 1,
- );
- $form['display']['show_on_profile'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display link on user profile page'),
- '#description' => t('Show the link formatted as a user profile element.'),
- '#default_value' => $this->show_on_profile,
- // Put this above 'show on entity'.
- '#weight' => -1,
- );
- }
-
- function form_input($form_values) {
- parent::form_input($form_values);
- // The access_uid value is intentionally backwards from the UI, to avoid
- // confusion caused by checking a box to disable a feature.
- $this->access_uid = empty($form_values['access_uid']) ? 'others' : '';
- }
-
- function type_access($entity_id, $action, $account) {
- // Prevent users from flagging themselves.
- if ($this->access_uid == 'others' && $entity_id == $account->uid) {
- return FALSE;
- }
- }
-
- function type_access_multiple($entity_ids, $account) {
- $access = array();
-
- // Exclude anonymous.
- if (array_key_exists(0, $entity_ids)) {
- $access[0] = FALSE;
- }
-
- // Prevent users from flagging themselves.
- if ($this->access_uid == 'others' && array_key_exists($account->uid, $entity_ids)) {
- $access[$account->uid] = FALSE;
- }
-
- return $access;
- }
-
- function get_flag_action($entity_id) {
- $flag_action = parent::get_flag_action($entity_id);
- $user = $this->fetch_entity($entity_id);
- $flag_action->content_title = $user->name;
- $flag_action->content_url = $this->_flag_url('user/' . $user->uid);
- return $flag_action;
- }
-
- function get_relevant_action_objects($entity_id) {
- return array(
- 'user' => $this->fetch_entity($entity_id),
- );
- }
-
- function get_views_info() {
- $views_info = parent::get_views_info();
- $views_info['title field'] = 'name';
- return $views_info;
- }
-}
From d2c20a676828b68a2216ee8fb0c526b87ec3c789 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Thu, 10 Apr 2014 22:44:39 -0500
Subject: [PATCH 380/629] Refinded ConfirmForm action link plugin to work more
like Reload.
---
flag.routing.yml | 15 +++++++-
lib/Drupal/flag/Form/FlagFormBase.php | 4 +-
lib/Drupal/flag/Form/FlaggingConfirmForm.php | 37 ++++++++++++++-----
.../flag/Plugin/ActionLink/ConfirmForm.php | 8 +++-
4 files changed, 49 insertions(+), 15 deletions(-)
diff --git a/flag.routing.yml b/flag.routing.yml
index 7b780dd..7d13611 100644
--- a/flag.routing.yml
+++ b/flag.routing.yml
@@ -68,8 +68,19 @@ flag_link_unflag:
requirements:
_entity_access: flagging.delete
-flag_confirm_form:
- path: '/flag/confirm/{action}/{flag_id}/{entity_id}'
+flag_confirm_flag:
+ path: '/flag/confirm/flag/{flag_id}/{entity_id}'
defaults:
_form: '\Drupal\flag\Form\FlaggingConfirmForm'
_title: 'Flag Content'
+ requirements:
+ _entity_create_access: flagging
+
+flag_confirm_unflag:
+ path: '/flag/confirm/unflag/{flag_id}/{entity_id}'
+ defaults:
+ _form: '\Drupal\flag\Form\FlaggingConfirmForm'
+ _title: 'Flag Content'
+ requirements:
+ _entity_access: flagging.delete
+
diff --git a/lib/Drupal/flag/Form/FlagFormBase.php b/lib/Drupal/flag/Form/FlagFormBase.php
index 433869f..257a692 100644
--- a/lib/Drupal/flag/Form/FlagFormBase.php
+++ b/lib/Drupal/flag/Form/FlagFormBase.php
@@ -190,10 +190,10 @@ public function validate(array $form, array &$form_state) {
if ($form_values['link_type'] == 'confirm') {
if (empty($form_values['flag_confirmation'])) {
- form_set_error('flag_confirmation', t('A flag confirmation message is required when using the confirmation link type.'));
+ form_set_error('flag_confirmation', array(t('A flag confirmation message is required when using the confirmation link type.')));
}
if (empty($form_values['unflag_confirmation'])) {
- form_set_error('unflag_confirmation', t('An unflag confirmation message is required when using the confirmation link type.'));
+ form_set_error('unflag_confirmation', array(t('An unflag confirmation message is required when using the confirmation link type.')));
}
}
/*
diff --git a/lib/Drupal/flag/Form/FlaggingConfirmForm.php b/lib/Drupal/flag/Form/FlaggingConfirmForm.php
index 11e8d59..8d212d4 100644
--- a/lib/Drupal/flag/Form/FlaggingConfirmForm.php
+++ b/lib/Drupal/flag/Form/FlaggingConfirmForm.php
@@ -9,23 +9,20 @@
namespace Drupal\flag\Form;
use Drupal\Core\Form\ConfirmFormBase;
-use Drupal\Core\EntityInterface;
+use Drupal\Core\Entity\EntityInterface;
use Drupal\flag\FlagInterface;
class FlaggingConfirmForm extends ConfirmFormBase {
- protected $action;
-
protected $entity;
protected $flag;
- // @todo add parameters for the entity, flag
public function buildForm(array $form, array &$form_state,
- $action, FlagInterface $flag, EntityInterface $entity) {
+ FlagInterface $flag = NULL,
+ EntityInterface $entity = NULL) {
- $this->action = $action;
$this->flag = $flag;
$this->entity = $entity;
}
@@ -37,7 +34,7 @@ public function getFormID() {
public function getQuestion() {
$linkType = $this->flag->getLinkTypePlugin();
- if ($action == 'unflag') {
+ if (!$this->isFlagged()) {
return $linkType->getUnflagQuestion();
}
else {
@@ -47,19 +44,41 @@ public function getQuestion() {
}
public function getCancelRoute() {
+/* $destination = \Drupal::request()->get('destination');
+ if (!empty($destination)) {
+ return new URL($destination);
+ }
+*/
return $this->entity->urlInfo();
}
public function getDescription() {
- return $this->t('');
+ if (!$this->isFlagged()) {
+ return $this->flag->unflag_long;
+ }
+
+ return $this->flag->flag_long;
}
public function getConfirmText() {
+ if (!$this->isFlagged()) {
+ return $this->t('Unflag');
+ }
+
return $this->t('Flag');
}
- public function submitForm(array &$form, array &$form_state) {
+ protected function isFlagged() {
+ return $this->flag->isFlagged($this->entity);
+ }
+ public function submitForm(array &$form, array &$form_state) {
+ if ($this->isFlagged()) {
+ \Drupal::service('flag')->unflagByObject($this->flag, $this->entity);
+ }
+ else {
+ \Drupal::service('flag')->flagByObject($this->flag, $this->entity);
+ }
}
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php b/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php
index c2ff2e9..6b46b88 100644
--- a/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php
+++ b/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php
@@ -22,8 +22,12 @@
*/
class ConfirmForm extends ActionLinkTypeBase {
- public function routeName() {
- return 'flag_confirm_form';
+ public function routeName($action = NULL) {
+ if ($action == 'unflag') {
+ return 'flag_confirm_unflag';
+ }
+
+ return 'flag_confirm_flag';
}
public function defaultConfiguration() {
From f9d2c3a83c1ac5c0ca359b3b5134257124b412d1 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Fri, 11 Apr 2014 21:34:34 -0500
Subject: [PATCH 381/629] Working flagging confirm form.
---
lib/Drupal/flag/Form/FlaggingConfirmForm.php | 21 ++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/lib/Drupal/flag/Form/FlaggingConfirmForm.php b/lib/Drupal/flag/Form/FlaggingConfirmForm.php
index 8d212d4..6965763 100644
--- a/lib/Drupal/flag/Form/FlaggingConfirmForm.php
+++ b/lib/Drupal/flag/Form/FlaggingConfirmForm.php
@@ -20,11 +20,12 @@ class FlaggingConfirmForm extends ConfirmFormBase {
protected $flag;
public function buildForm(array $form, array &$form_state,
- FlagInterface $flag = NULL,
- EntityInterface $entity = NULL) {
+ $flag_id = NULL, $entity_id = NULL) {
- $this->flag = $flag;
- $this->entity = $entity;
+ $flagService = \Drupal::service('flag');
+ $this->flag = $flagService->getFlagByID($flag_id);
+ $this->entity = $flagService->getFlaggableById($this->flag, $entity_id);
+ return parent::buildForm($form, $form_state);
}
public function getFormID() {
@@ -34,7 +35,7 @@ public function getFormID() {
public function getQuestion() {
$linkType = $this->flag->getLinkTypePlugin();
- if (!$this->isFlagged()) {
+ if ($this->isFlagged()) {
return $linkType->getUnflagQuestion();
}
else {
@@ -44,16 +45,16 @@ public function getQuestion() {
}
public function getCancelRoute() {
-/* $destination = \Drupal::request()->get('destination');
+ $destination = \Drupal::request()->get('destination');
if (!empty($destination)) {
- return new URL($destination);
+ return URL::createFromPath($destination);
}
-*/
+
return $this->entity->urlInfo();
}
public function getDescription() {
- if (!$this->isFlagged()) {
+ if ($this->isFlagged()) {
return $this->flag->unflag_long;
}
@@ -61,7 +62,7 @@ public function getDescription() {
}
public function getConfirmText() {
- if (!$this->isFlagged()) {
+ if ($this->isFlagged()) {
return $this->t('Unflag');
}
From 52b0cad10dc4b809188b507759d92b54f86ccc95 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 13 Apr 2014 00:03:11 -0500
Subject: [PATCH 382/629] Working AJAX link.
---
lib/Drupal/flag/ActionLinkTypeBase.php | 1 +
.../flag/Controller/ReloadLinkController.php | 24 ++++++++++++++---
lib/Drupal/flag/Entity/Flagging.php | 6 ++++-
.../flag/Plugin/ActionLink/AJAXactionLink.php | 27 +++++++++++++++++++
4 files changed, 53 insertions(+), 5 deletions(-)
create mode 100644 lib/Drupal/flag/Plugin/ActionLink/AJAXactionLink.php
diff --git a/lib/Drupal/flag/ActionLinkTypeBase.php b/lib/Drupal/flag/ActionLinkTypeBase.php
index 82ac259..fa32b2f 100644
--- a/lib/Drupal/flag/ActionLinkTypeBase.php
+++ b/lib/Drupal/flag/ActionLinkTypeBase.php
@@ -62,6 +62,7 @@ public function renderLink($action, FlagInterface $flag, EntityInterface $entity
$render = $url->toRenderArray();
$render['#type'] = 'link';
+ $render['#attributes']['id'] = 'flag-' . $flag->id() . '-id-' . $entity->id();
//@todo check if flagged, assign flag or unflag text.
if ($action === 'unflag') {
diff --git a/lib/Drupal/flag/Controller/ReloadLinkController.php b/lib/Drupal/flag/Controller/ReloadLinkController.php
index 9928005..9ab05fb 100644
--- a/lib/Drupal/flag/Controller/ReloadLinkController.php
+++ b/lib/Drupal/flag/Controller/ReloadLinkController.php
@@ -11,23 +11,39 @@
use Drupal\Core\Controller\ControllerBase;
use Drupal\flag\FlagInterface;
use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Ajax\AjaxResponse;
+use Drupal\Core\Ajax\ReplaceCommand;
+use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
class ReloadLinkController extends ControllerBase {
- public function flag($flag_id, $entity_id) {
+ public function flag(Request $request, $flag_id, $entity_id) {
$flagging = \Drupal::service('flag')->flag($flag_id, $entity_id);
+ // If the response is coming from JavaScript, we can't return a redirect.
+ // Instead, we replace the flag link with an unflag link via JSON.
+ if ($request->request->get('js')) {
+ $response = new AjaxResponse();
+ $linkType = $flagging->getFlag()->getLinkTypePlugin();
+ $link = $linkType->renderLink('unflag', $flagging->getFlag(), $flagging->getFlaggable());
+ $linkId = '#' . $link['#attributes']['id'];
+ $html = drupal_render($link);
+ $replace = new ReplaceCommand($linkId, $html);
+ $response->addCommand($replace);
+
+ return $response;
+ }
+
// Get the destination.
- $destination = \Drupal::request()->get('destination',
- $flagging->getFlaggable()->url());
+ $destination = $request->get('destination', $flagging->getFlaggable()->url());
//@todo SECURITY HOLE. Please fix!
return new RedirectResponse($destination);
}
- public function unflag($flag_id, $entity_id) {
+ public function unflag(Request $request, $flag_id, $entity_id) {
// Get the Flag Service.
$flagService = \Drupal::service('flag');
diff --git a/lib/Drupal/flag/Entity/Flagging.php b/lib/Drupal/flag/Entity/Flagging.php
index b1d37ad..6e4fdb2 100644
--- a/lib/Drupal/flag/Entity/Flagging.php
+++ b/lib/Drupal/flag/Entity/Flagging.php
@@ -44,8 +44,12 @@
*/
class Flagging extends ContentEntityBase implements FlaggingInterface {
+ public function getFlagId() {
+ return $this->get('fid')->value;
+ }
+
public function getFlag() {
- return $this->bundle;
+ return entity_load($this->bundle, $this->getFlagId());
}
public function getFlaggableType() {
diff --git a/lib/Drupal/flag/Plugin/ActionLink/AJAXactionLink.php b/lib/Drupal/flag/Plugin/ActionLink/AJAXactionLink.php
new file mode 100644
index 0000000..b3c8fd1
--- /dev/null
+++ b/lib/Drupal/flag/Plugin/ActionLink/AJAXactionLink.php
@@ -0,0 +1,27 @@
+
Date: Tue, 15 Apr 2014 23:39:18 -0500
Subject: [PATCH 383/629] Converted FlaggingAccessController to a custom
controller. Separated Reload and AJAX controllers.
---
flag.module | 2 +-
flag.routing.yml | 27 ++++++-
.../flag/Controller/AJAXLinkController.php | 73 +++++++++++++++++++
.../flag/Controller/ReloadLinkController.php | 22 +-----
lib/Drupal/flag/FlaggingAccessController.php | 47 +++++-------
.../flag/Plugin/ActionLink/AJAXactionLink.php | 12 ++-
6 files changed, 126 insertions(+), 57 deletions(-)
create mode 100644 lib/Drupal/flag/Controller/AJAXLinkController.php
diff --git a/flag.module b/flag.module
index ed42a9e..4e823d2 100644
--- a/flag.module
+++ b/flag.module
@@ -701,7 +701,7 @@ function flag_entity_delete($entity, $type) {
return;
}
- _flag_entity_delete($entity->getFlaggableEntityType(), $entity->id());
+// _flag_entity_delete($entity->getFlaggableEntityType(), $entity->id());
}
/**
diff --git a/flag.routing.yml b/flag.routing.yml
index 7d13611..a007500 100644
--- a/flag.routing.yml
+++ b/flag.routing.yml
@@ -59,14 +59,32 @@ flag_link_flag:
defaults:
_controller: '\Drupal\flag\Controller\ReloadLinkController::flag'
requirements:
- _entity_create_access: flagging
+ _custom_access: '\Drupal\flag\FlaggingAccessController::checkflag'
+ _format: 'html'
+
+flag.link_flag.json:
+ path: '/flag/flag/{flag_id}/{entity_id}'
+ defaults:
+ _controller: '\Drupal\flag\Controller\AJAXLinkController::flag'
+ requirements:
+ _custom_access: '\Drupal\flag\FlaggingAccessController::checkflag'
+ _format: 'json'
flag_link_unflag:
path: '/flag/unflag/{flag_id}/{entity_id}'
defaults:
_controller: '\Drupal\flag\Controller\ReloadLinkController::unflag'
requirements:
- _entity_access: flagging.delete
+ _custom_access: '\Drupal\flag\FlaggingAccessController::checkUnflag'
+ _format: 'html'
+
+flag.link_unflag.json:
+ path: '/flag/unflag/{flag_id}/{entity_id}'
+ defaults:
+ _controller: '\Drupal\flag\Controller\AJAXLinkController::unflag'
+ requirements:
+ _custom_access: '\Drupal\flag\FlaggingAccessController::checkUnflag'
+ _format: 'json'
flag_confirm_flag:
path: '/flag/confirm/flag/{flag_id}/{entity_id}'
@@ -74,7 +92,7 @@ flag_confirm_flag:
_form: '\Drupal\flag\Form\FlaggingConfirmForm'
_title: 'Flag Content'
requirements:
- _entity_create_access: flagging
+ _custom_access: '\Drupal\flag\FlaggingAccessController::checkflag'
flag_confirm_unflag:
path: '/flag/confirm/unflag/{flag_id}/{entity_id}'
@@ -82,5 +100,6 @@ flag_confirm_unflag:
_form: '\Drupal\flag\Form\FlaggingConfirmForm'
_title: 'Flag Content'
requirements:
- _entity_access: flagging.delete
+ _custom_access: '\Drupal\flag\FlaggingAccessController::checkUnflag'
+
diff --git a/lib/Drupal/flag/Controller/AJAXLinkController.php b/lib/Drupal/flag/Controller/AJAXLinkController.php
new file mode 100644
index 0000000..8f99d53
--- /dev/null
+++ b/lib/Drupal/flag/Controller/AJAXLinkController.php
@@ -0,0 +1,73 @@
+flag($flag_id, $entity_id);
+
+ $flag = $flagging->getFlag();
+ $entity = $flagging->getFlaggable();
+
+ return $this->generateResponse('unflag', $flag, $entity);
+ }
+
+ /**
+ * @param $flag_id
+ * @param $entity_id
+ * @return AjaxResponse
+ */
+ public function unflag($flag_id, $entity_id) {
+ $flagService = \Drupal::service('flag');
+ $flagService->unflag($flag_id, $entity_id);
+
+ $flag = $flagService->getFlagById($flag_id);
+ $entity = $flagService->getFlaggableById($flag, $entity_id);
+
+ return $this->generateResponse('flag', $flag, $entity);
+ }
+
+ /**
+ * @param $action
+ * @param FlagInterface $flag
+ * @param EntityInterface $entity
+ * @return AjaxResponse
+ */
+ protected function generateResponse($action, FlagInterface $flag, EntityInterface $entity) {
+ // Create a new AJAX response.
+ $response = new AjaxResponse();
+
+ // Get the link type plugin.
+ $linkType = $flag->getLinkTypePlugin();
+
+ // Generate the link render array and get the link CSS ID.
+ $link = $linkType->renderLink($action, $flag, $entity);
+ $linkId = '#' . $link['#attributes']['id'];
+
+ // Create a new JQuery Replace command to update the link display.
+ $replace = new ReplaceCommand($linkId, drupal_render($link));
+ $response->addCommand($replace);
+
+ return $response;
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Controller/ReloadLinkController.php b/lib/Drupal/flag/Controller/ReloadLinkController.php
index 9ab05fb..b4dc711 100644
--- a/lib/Drupal/flag/Controller/ReloadLinkController.php
+++ b/lib/Drupal/flag/Controller/ReloadLinkController.php
@@ -22,20 +22,6 @@ public function flag(Request $request, $flag_id, $entity_id) {
$flagging = \Drupal::service('flag')->flag($flag_id, $entity_id);
- // If the response is coming from JavaScript, we can't return a redirect.
- // Instead, we replace the flag link with an unflag link via JSON.
- if ($request->request->get('js')) {
- $response = new AjaxResponse();
- $linkType = $flagging->getFlag()->getLinkTypePlugin();
- $link = $linkType->renderLink('unflag', $flagging->getFlag(), $flagging->getFlaggable());
- $linkId = '#' . $link['#attributes']['id'];
- $html = drupal_render($link);
- $replace = new ReplaceCommand($linkId, $html);
- $response->addCommand($replace);
-
- return $response;
- }
-
// Get the destination.
$destination = $request->get('destination', $flagging->getFlaggable()->url());
@@ -44,18 +30,12 @@ public function flag(Request $request, $flag_id, $entity_id) {
}
public function unflag(Request $request, $flag_id, $entity_id) {
- // Get the Flag Service.
$flagService = \Drupal::service('flag');
+ $flagService->unflag($flag_id, $entity_id);
- // Get the Flag and Entity objects.
$flag = $flagService->getFlagById($flag_id);
$entity = $flagService->getFlaggableById($flag, $entity_id);
- $flaggings = \Drupal::service('flag')->getFlaggings($entity, $flag);
- foreach ($flaggings as $flagging) {
- \Drupal::service('flag')->unflagByObject($flagging);
- }
-
$destination = \Drupal::request()->get('destination', $entity->url());
//@todo SECURITY HOLE. Please fix!
diff --git a/lib/Drupal/flag/FlaggingAccessController.php b/lib/Drupal/flag/FlaggingAccessController.php
index 906b0f8..e2c0ce1 100644
--- a/lib/Drupal/flag/FlaggingAccessController.php
+++ b/lib/Drupal/flag/FlaggingAccessController.php
@@ -8,48 +8,37 @@
namespace Drupal\flag;
+use Drupal\Core\Access\AccessInterface;
+use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityAccessController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
+use Symfony\Component\HttpFoundation\Request;
-class FlaggingAccessController extends EntityAccessController {
- protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
- if ($account->id() == 1) {
- return TRUE;
- }
-
- switch ($operation) {
- case 'view':
- case 'flag':
- return user_access('flag ' . $entity->id(), $account);
- break;
-
- case 'delete':
- case 'unflag':
- return user_access('unflag' . $entity->id(), $account);
- break;
- }
+class FlaggingAccessController extends ControllerBase {
- return parent::checkAccess($entity, $operation, $langcode, $account);
- }
+ public function checkFlag(Request $request) {
+ $entity_id = $request->get('entity_id');
- protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
- if ($account->id() == 1) {
- return TRUE;
+ if (user_access('flag' . $entity_id)) {
+ return AccessInterface::ALLOW;
}
- //@todo Figure out how to handle the NULL $entity_bundle case.
- return user_access('flag ' . $entity_bundle, $account);
+ return AccessInterface::DENY;
}
- public function getRoles() {
- $roles = array();
+ /**
+ *
+ */
+ public function checkUnflag(Request $request) {
+ $entity_id = $request->get('entity_id');
- $roles['flag'] = user_roles(FALSE, 'flag ' . $this->entityTypeId);
- $roles['unflag'] = user_roles(FALSE, 'unflag ' . $this->entityTypeId);
+ if (user_access('unflag' . $entity_id)) {
+ return AccessInterface::ALLOW;
+ }
- return $roles;
+ return AccessInterface::DENY;
}
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/ActionLink/AJAXactionLink.php b/lib/Drupal/flag/Plugin/ActionLink/AJAXactionLink.php
index b3c8fd1..933b0c0 100644
--- a/lib/Drupal/flag/Plugin/ActionLink/AJAXactionLink.php
+++ b/lib/Drupal/flag/Plugin/ActionLink/AJAXactionLink.php
@@ -2,7 +2,7 @@
namespace Drupal\flag\Plugin\ActionLink;
-use Drupal\flag\Plugin\ActionLink\Reload;
+use Drupal\flag\ActionLinkTypeBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\flag\FlagInterface;
@@ -15,7 +15,15 @@
* description = "An AJAX JavaScript request will be made without reloading the page."
* )
*/
-class AJAXactionLink extends Reload{
+class AJAXactionLink extends ActionLinkTypeBase{
+
+ public function routeName($action = NULL) {
+ if ($action === 'unflag') {
+ return 'flag.link_unflag.json';
+ }
+
+ return 'flag.link_flag.json';
+ }
public function renderLink($action, FlagInterface $flag, EntityInterface $entity) {
$render = parent::renderLink($action, $flag, $entity);
From a6a3859ecd2afe52224981cd96af492ced37b6b2 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Fri, 25 Apr 2014 19:24:26 -0500
Subject: [PATCH 384/629] Renamed most routes to start with flag.*
---
flag.local_actions.yml | 4 ++--
flag.menu_links.yml | 2 +-
flag.routing.yml | 22 +++++++++----------
lib/Drupal/flag/Entity/Flag.php | 4 ++--
lib/Drupal/flag/Entity/Flagging.php | 2 +-
lib/Drupal/flag/Form/FlagDeleteForm.php | 4 ++--
.../flag/Plugin/ActionLink/ConfirmForm.php | 4 ++--
lib/Drupal/flag/Plugin/ActionLink/Reload.php | 4 ++--
8 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/flag.local_actions.yml b/flag.local_actions.yml
index 9b9f593..ea4e830 100644
--- a/flag.local_actions.yml
+++ b/flag.local_actions.yml
@@ -1,5 +1,5 @@
flag_add_page_action:
- route_name: flag_add_page
+ route_name: flag.add_page
title: 'Add New Flag'
appears_on:
- - flag_list
\ No newline at end of file
+ - flag.list
\ No newline at end of file
diff --git a/flag.menu_links.yml b/flag.menu_links.yml
index 4e8a2c7..e4282e8 100644
--- a/flag.menu_links.yml
+++ b/flag.menu_links.yml
@@ -2,4 +2,4 @@ flag.admin.structure.flag:
title: 'Flags'
description: 'Configure flags for marking content with arbitrary information (such as offensive or bookmarked).'
parent: system.admin_structure
- route_name: flag_list
\ No newline at end of file
+ route_name: flag.list
\ No newline at end of file
diff --git a/flag.routing.yml b/flag.routing.yml
index a007500..01c585c 100644
--- a/flag.routing.yml
+++ b/flag.routing.yml
@@ -1,4 +1,4 @@
-flag_add_page:
+flag.add_page:
path: '/admin/structure/flags/add'
defaults:
_form: '\Drupal\flag\Form\FlagAddPageForm'
@@ -6,7 +6,7 @@ flag_add_page:
requirements:
_permission: 'administer flags'
-flag_list:
+flag.list:
path: '/admin/structure/flags'
defaults:
_entity_list: 'flag_flag'
@@ -14,7 +14,7 @@ flag_list:
requirements:
_permission: 'administer flags'
-flag_add:
+flag.add:
path: '/admin/structure/flags/add/{entity_type}'
defaults:
_entity_form: flag_flag.add
@@ -22,7 +22,7 @@ flag_add:
requirements:
_permission: 'administer flags'
-flag_edit:
+flag.edit:
path: '/admin/structure/flags/manage/{flag_flag}'
defaults:
_entity_form: flag_flag.edit
@@ -30,7 +30,7 @@ flag_edit:
requirements:
_entity_access: 'flag_flag.update'
-flag_delete:
+flag.delete:
path: '/admin/structure/flags/manage/{flag_flag}/delete'
defaults:
_entity_form: flag_flag.delete
@@ -38,7 +38,7 @@ flag_delete:
requirements:
_entity_access: 'flag_flag.update'
-flag_import:
+flag.import:
path: '/admin/structure/flags/import'
defaults:
_form: '\Drupal\flag\Form\FlagImportForm'
@@ -46,7 +46,7 @@ flag_import:
requirements:
_permission: 'use flag import'
-flag_export:
+flag.export:
path: '/admin/structure/flags/export'
defaults:
_form: '\Drupal\flag\Form\FlagExportForm'
@@ -54,7 +54,7 @@ flag_export:
requirements:
_permission: 'use flag import'
-flag_link_flag:
+flag_link_flag.html:
path: '/flag/flag/{flag_id}/{entity_id}'
defaults:
_controller: '\Drupal\flag\Controller\ReloadLinkController::flag'
@@ -70,7 +70,7 @@ flag.link_flag.json:
_custom_access: '\Drupal\flag\FlaggingAccessController::checkflag'
_format: 'json'
-flag_link_unflag:
+flag_link_unflag.html:
path: '/flag/unflag/{flag_id}/{entity_id}'
defaults:
_controller: '\Drupal\flag\Controller\ReloadLinkController::unflag'
@@ -86,7 +86,7 @@ flag.link_unflag.json:
_custom_access: '\Drupal\flag\FlaggingAccessController::checkUnflag'
_format: 'json'
-flag_confirm_flag:
+flag.confirm_flag:
path: '/flag/confirm/flag/{flag_id}/{entity_id}'
defaults:
_form: '\Drupal\flag\Form\FlaggingConfirmForm'
@@ -94,7 +94,7 @@ flag_confirm_flag:
requirements:
_custom_access: '\Drupal\flag\FlaggingAccessController::checkflag'
-flag_confirm_unflag:
+flag.confirm_unflag:
path: '/flag/confirm/unflag/{flag_id}/{entity_id}'
defaults:
_form: '\Drupal\flag\Form\FlaggingConfirmForm'
diff --git a/lib/Drupal/flag/Entity/Flag.php b/lib/Drupal/flag/Entity/Flag.php
index 6c74265..ea87af2 100644
--- a/lib/Drupal/flag/Entity/Flag.php
+++ b/lib/Drupal/flag/Entity/Flag.php
@@ -40,8 +40,8 @@
* "label" = "label",
* },
* links = {
- * "edit-form" = "flag_edit",
- * "delete-form" = "flag_delete"
+ * "edit-form" = "flag.edit",
+ * "delete-form" = "flag.delete"
* }
* )
*
diff --git a/lib/Drupal/flag/Entity/Flagging.php b/lib/Drupal/flag/Entity/Flagging.php
index 6e4fdb2..4147d38 100644
--- a/lib/Drupal/flag/Entity/Flagging.php
+++ b/lib/Drupal/flag/Entity/Flagging.php
@@ -38,7 +38,7 @@
* "bundle" = "type"
* },
* links = {
- * "admin-form" = "flag_edit"
+ * "admin-form" = "flag.edit"
* }
* )
*/
diff --git a/lib/Drupal/flag/Form/FlagDeleteForm.php b/lib/Drupal/flag/Form/FlagDeleteForm.php
index 02cb518..fb74c8b 100644
--- a/lib/Drupal/flag/Form/FlagDeleteForm.php
+++ b/lib/Drupal/flag/Form/FlagDeleteForm.php
@@ -24,7 +24,7 @@ public function getConfirmText() {
public function getCancelRoute() {
return array(
- 'route_name' => 'flag_list',
+ 'route_name' => 'flag.list',
);
}
@@ -34,7 +34,7 @@ public function submit(array $form, array &$form_state) {
'%label' => $this->entity->label(),
)));
- $form_state['redirect_route']['route_name'] = 'flag_list';
+ $form_state['redirect_route']['route_name'] = 'flag.list';
}
}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php b/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php
index 6b46b88..e92986a 100644
--- a/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php
+++ b/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php
@@ -24,10 +24,10 @@ class ConfirmForm extends ActionLinkTypeBase {
public function routeName($action = NULL) {
if ($action == 'unflag') {
- return 'flag_confirm_unflag';
+ return 'flag.confirm_unflag';
}
- return 'flag_confirm_flag';
+ return 'flag.confirm_flag';
}
public function defaultConfiguration() {
diff --git a/lib/Drupal/flag/Plugin/ActionLink/Reload.php b/lib/Drupal/flag/Plugin/ActionLink/Reload.php
index 8683e90..69d0de1 100644
--- a/lib/Drupal/flag/Plugin/ActionLink/Reload.php
+++ b/lib/Drupal/flag/Plugin/ActionLink/Reload.php
@@ -26,10 +26,10 @@ class Reload extends ActionLinkTypeBase {
*/
public function routeName($action = NULL) {
if ($action === 'unflag') {
- return 'flag_link_unflag';
+ return 'flag_link_unflag.html';
}
- return 'flag_link_flag';
+ return 'flag_link_flag.html';
}
}
\ No newline at end of file
From 204b4b219e6d307bd663eef3f82fa5571d09fd80 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Fri, 25 Apr 2014 22:00:22 -0500
Subject: [PATCH 385/629] Changes due to https://drupal.org/node/2218341 and
https://drupal.org/node/2200867
---
lib/Drupal/flag/ActionLinkTypeBase.php | 7 +++++++
lib/Drupal/flag/FlagTypeBase.php | 7 +++++++
lib/Drupal/flag/Form/FlagFormBase.php | 4 ++--
lib/Drupal/flag/Plugin/Flag/EntityFlagType.php | 2 +-
4 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/lib/Drupal/flag/ActionLinkTypeBase.php b/lib/Drupal/flag/ActionLinkTypeBase.php
index fa32b2f..55ff42a 100644
--- a/lib/Drupal/flag/ActionLinkTypeBase.php
+++ b/lib/Drupal/flag/ActionLinkTypeBase.php
@@ -77,6 +77,13 @@ public function renderLink($action, FlagInterface $flag, EntityInterface $entity
return $render;
}
+ /**
+ * {@inhereitdoc}
+ */
+ public function calculateDependencies() {
+ return array();
+ }
+
/**
* Provides a form array for the action link plugin's settings form.
* Derived classes will want to override this method.
diff --git a/lib/Drupal/flag/FlagTypeBase.php b/lib/Drupal/flag/FlagTypeBase.php
index ec2412d..bc5b4f8 100644
--- a/lib/Drupal/flag/FlagTypeBase.php
+++ b/lib/Drupal/flag/FlagTypeBase.php
@@ -35,6 +35,13 @@ public function defaultConfiguration() {
return array();
}
+ /**
+ * {@inhereitdoc}
+ */
+ public function calculateDependencies() {
+ return array();
+ }
+
/**
* Returns this flag type plugin's configuration array.
*
diff --git a/lib/Drupal/flag/Form/FlagFormBase.php b/lib/Drupal/flag/Form/FlagFormBase.php
index 257a692..ae8c84f 100644
--- a/lib/Drupal/flag/Form/FlagFormBase.php
+++ b/lib/Drupal/flag/Form/FlagFormBase.php
@@ -8,10 +8,10 @@
namespace Drupal\flag\Form;
-use Drupal\Core\Entity\EntityFormController;
+use Drupal\Core\Entity\EntityForm;
use Drupal\flag\Handlers\AbstractFlag;
-abstract class FlagFormBase extends EntityFormController {
+abstract class FlagFormBase extends EntityForm {
public function buildForm(array $form, array &$form_state, $entity_type = NULL) {
diff --git a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
index 98c862f..339d879 100644
--- a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
+++ b/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
@@ -57,7 +57,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
// Add checkboxes to show flag link on each entity view mode.
$options = array();
$defaults = array();
- $view_modes = entity_get_view_modes($this->entity_type);
+ $view_modes = \Drupal::entityManager()->getViewModes($this->entity_type);
foreach ($view_modes as $name => $view_mode) {
$options[$name] = t('Display on @name view mode', array('@name' => $view_mode['label']));
$defaults[$name] = !empty($this->show_in_links[$name]) ? $name : 0;
From 8a9b44ec7b8430aebfd105fa5ee71b9a03396bd0 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Tue, 27 May 2014 21:25:13 -0500
Subject: [PATCH 386/629] Initial (non-working) views functionality.
---
flag.views.inc | 207 ++++++++++++++++++
flag_bookmark/flag_bookmark.install | 67 ------
flag_bookmark/flag_bookmark.module | 10 -
.../flag_bookmark.flag_flag.bookmark.yml | 33 +++
lib/Drupal/flag/Form/FlagAddPageForm.php | 2 +-
.../Plugin/views/field/FlagViewsLinkField.php | 74 +++++++
.../relationship/FlagViewsRelationship.php | 71 ++++++
7 files changed, 386 insertions(+), 78 deletions(-)
create mode 100644 flag.views.inc
delete mode 100644 flag_bookmark/flag_bookmark.install
create mode 100644 flag_bookmark/lib/Drupal/flag_bookmark/config/install/flag_bookmark.flag_flag.bookmark.yml
create mode 100644 lib/Drupal/flag/Plugin/views/field/FlagViewsLinkField.php
create mode 100644 lib/Drupal/flag/Plugin/views/relationship/FlagViewsRelationship.php
diff --git a/flag.views.inc b/flag.views.inc
new file mode 100644
index 0000000..edcd699
--- /dev/null
+++ b/flag.views.inc
@@ -0,0 +1,207 @@
+ array(
+ 'type' => 'INNER',
+ 'left_field' => 'nid',
+ 'field' => 'entity_id',
+ ),
+ );
+ $data['flagging']['entity_id'] = array(
+ 'title' => t('Entity ID'),
+ 'help' => t('The ID of the entity'),
+ 'sort' => array(
+ 'id' => 'standard',
+ ),
+ );
+
+/*
+ // Flag content links.
+ $data['flagging']['ops'] = array(
+ 'title' => t('Flag link'),
+ 'help' => t('Display flag/unflag link.'),
+ 'field' => array(
+ 'handler' => 'flag_handler_field_ops',
+ ),
+ );*/
+
+ return $data;
+}
+
+function flag_views_data_alter(&$data) {
+ $flags = \Drupal::service('flag')->getFlags();
+
+ foreach ($flags as $fid => $flag) {
+ $flag_type_plugin = $flag->getFlagTypePlugin();
+ $flag_type_def = $flag_type_plugin->getPluginDefinition();
+
+ $info = \Drupal::entityManager()->getDefinition($flag_type_def['entity_type']);
+
+ $base_table = $info->getBaseTable();
+ if ($flag_type_def['entity_type'] == 'node') {
+ $base_table = $info->getDataTable();
+ }
+
+ $data[$base_table]['flag_content_rel'] = array(
+ 'title' => t('@entity_label flag', array('@entity_label' => $flag_type_def['entity_type'])),
+ 'help' => t('Limit results to only those entity flagged by a certain flag; Or display information about the flag set on a entity.'),
+ 'relationship' => array(
+ 'group' => t('Flag'),
+ 'label' => t('Flags'),
+ 'base' => 'flagging',
+ 'base field' => 'entity_id',
+ 'relationship field' => $info->getKey('id'),
+ 'id' => 'flag_relationship',
+ 'flag type' => $fid,
+ ),
+ );
+
+ }
+}
+
+
+/*
+function flag_views_data() {
+ $data = array();
+
+
+
+
+ $data['flagging']['table']['group'] = t('Flags');
+ $data['flagging']['table']['base'] = array(
+ 'field' => 'id',
+ 'title' => t('Flag Id'),
+ 'help' => t('The flagging Id.'),
+ );
+ $data['flagging']['table']['entity type'] = 'flagging';
+
+// $data['flag_counts']['table']['group'] = t('Flags');
+
+ $data['flagging']['uid'] = array(
+ 'title' => t('User uid'),
+ 'help' => t('The user that flagged an item. If you need more fields than the uid add the "Flags: User" relationship.'),
+ 'relationship' => array(
+ 'title' => t('User'),
+ 'help' => t('Relate an item to the user that flagged it.'),
+ 'id' => 'standard',
+ 'base' => 'users',
+ 'field' => uid,
+ 'label' => t('Flag user'),
+ ),
+/* 'filter' => array(
+ 'handler' => 'views_handler_filter_user_name',
+ ),
+ 'argument' => array(
+ 'handler' => 'views_handler_argument_numeric',
+ ),
+ 'field' => array(
+ 'handler' => 'views_handler_field_user',
+ ),
+ );
+
+ $data['flagging']['timestamp'] = array(
+ 'title' => t('Flagged time'),
+ 'help' => t('Display the time the content was flagged by a user.'),
+ 'field' => array(
+ 'handler' => 'views_handler_field_date',
+ 'click sortable' => TRUE,
+ ),
+ 'sort' => array(
+ 'id' => 'date',
+ ),
+ 'filter' => array(
+ 'id' => 'date',
+ ),
+// 'argument' => array(
+// 'handler' => 'views_handler_argument_date',
+// ),
+ );
+/*
+ // Argument for content ID, used for "Who's flagged this" views.
+ $data['flagging']['entity_id'] = array(
+ 'title' => t('Content ID'),
+ 'help' => t('The unique ID of the object that has been flagged.'),
+ 'argument' => array(
+ 'handler' => 'flag_handler_argument_entity_id',
+ ),
+ );
+
+ // Specialized is null/is not null filter.
+ $data['flagging']['flagged'] = array(
+ 'title' => t('Flagged'),
+ 'real field' => 'uid',
+ 'field' => array(
+ 'handler' => 'flag_handler_field_flagged',
+ 'label' => t('Flagged'),
+ 'help' => t('A boolean field to show whether the flag is set or not.'),
+ ),
+ 'filter' => array(
+ 'handler' => 'flag_handler_filter_flagged',
+ 'label' => t('Flagged'),
+ 'help' => t('Filter to ensure content has or has not been flagged.'),
+ ),
+ 'sort' => array(
+ 'handler' => 'flag_handler_sort_flagged',
+ 'label' => t('Flagged'),
+ 'help' => t('Sort by whether entities have or have not been flagged.'),
+ ),
+ );
+
+ // Flag content links.
+ $data['flagging']['ops'] = array(
+ 'title' => t('Flag link'),
+ 'help' => t('Display flag/unflag link.'),
+ 'field' => array(
+ 'handler' => 'flag_handler_field_ops',
+ ),
+ );
+
+ $data['flag_counts']['count'] = array(
+ 'title' => t('Flag counter'),
+ 'help' => t('The number of times a piece of content is flagged by any user.'),
+ 'field' => array(
+ 'handler' => 'views_handler_field_numeric',
+ 'click sortable' => TRUE,
+ ),
+ 'sort' => array(
+ 'handler' => 'views_handler_sort',
+ ),
+ 'filter' => array(
+ 'handler' => 'views_handler_filter_numeric',
+ ),
+ 'argument' => array(
+ 'handler' => 'views_handler_argument_numeric',
+ ),
+ );
+
+ $data['flag_counts']['last_updated'] = array(
+ 'title' => t('Time last flagged'),
+ 'help' => t('The time a piece of content was most recently flagged by any user.'),
+ 'field' => array(
+ 'handler' => 'views_handler_field_date',
+ 'click sortable' => TRUE,
+ ),
+ 'sort' => array(
+ 'handler' => 'views_handler_sort_date',
+ ),
+ 'filter' => array(
+ 'handler' => 'views_handler_filter_date',
+ ),
+ 'argument' => array(
+ 'handler' => 'views_handler_argument_date',
+ ),
+ );
+
+ return $data;
+}
+
+*/
\ No newline at end of file
diff --git a/flag_bookmark/flag_bookmark.install b/flag_bookmark/flag_bookmark.install
deleted file mode 100644
index 284784a..0000000
--- a/flag_bookmark/flag_bookmark.install
+++ /dev/null
@@ -1,67 +0,0 @@
- 'bookmarks',
- 'global' => 0,
- 'show_in_links' => array(
- 'full' => 1,
- 'teaser' => 1,
- ),
- 'show_on_form' => 1,
- // The following UI labels aren't wrapped in t() because they are written
- // to the DB in English. They are passed to t() later, thus allowing for
- // multilingual sites.
- 'title' => 'Bookmarks',
- 'flag_short' => 'Bookmark this',
- 'flag_long' => 'Add this post to your bookmarks',
- 'flag_message' => 'This post has been added to your bookmarks',
- 'unflag_short' => 'Unbookmark this',
- 'unflag_long' => 'Remove this post from your bookmarks',
- 'unflag_message' => 'This post has been removed from your bookmarks',
- 'types' => _flag_bookmark_install_get_suggested_node_types(),
- );
- $flag->form_input($configuration);
- $flag->save();
-
- // Clear the flag cache so the new permission is seen by core.
- drupal_static_reset('flag_get_flags');
-
- // Grant permissions.
- $permissions = array('flag bookmarks', 'unflag bookmarks');
- user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, $permissions);
- }
-}
-
-/**
- * Returns some node types to which the demonstration 'bookmarks' flag will apply.
- */
-function _flag_bookmark_install_get_suggested_node_types() {
- $preferred = array('article', 'story', 'forum', 'blog');
- $existing = array_intersect($preferred, array_keys(node_type_get_types()));
- if (!$existing) {
- // As a last resort, take the first preference.
- return array($preferred[0]);
- }
- return $existing;
-}
-
diff --git a/flag_bookmark/flag_bookmark.module b/flag_bookmark/flag_bookmark.module
index d182cf4..626ccd8 100644
--- a/flag_bookmark/flag_bookmark.module
+++ b/flag_bookmark/flag_bookmark.module
@@ -7,13 +7,3 @@
* This module creates a default Flag and associated views when enabled. The
* content is intended to be an example and may be deleted afterward.
*/
-
-/**
- * Implements hook_views_api().
- */
-function flag_bookmark_views_api() {
- return array(
- 'api' => 2.0,
- 'path' => drupal_get_path('module', 'flag_bookmark') . '/includes',
- );
-}
diff --git a/flag_bookmark/lib/Drupal/flag_bookmark/config/install/flag_bookmark.flag_flag.bookmark.yml b/flag_bookmark/lib/Drupal/flag_bookmark/config/install/flag_bookmark.flag_flag.bookmark.yml
new file mode 100644
index 0000000..6e16e55
--- /dev/null
+++ b/flag_bookmark/lib/Drupal/flag_bookmark/config/install/flag_bookmark.flag_flag.bookmark.yml
@@ -0,0 +1,33 @@
+id: bookmark
+entity_type: node
+label: Bookmark
+types:
+ article: article
+ page: page
+flag_short: 'Bookmark this'
+flag_long: 'Add this post to your bookmarks'
+flag_message: 'This post has been added to your bookmarks'
+unflag_short: 'Remove bookmark'
+unflag_long: 'Remove this post from your bookmarks'
+unflag_message: 'This post has been removed from your bookmarks'
+unflag_denied_text: ''
+weight: 0
+status: true
+langcode: en
+dependencies: { }
+roles: null
+flag_type: flagtype_node
+link_type: reload
+flagTypeConfig:
+ show_in_links:
+ full: full
+ teaser: teaser
+ rss: 0
+ search_index: 0
+ search_result: 0
+ show_as_field: 1
+ show_on_form: 0
+ show_contextual_link: 0
+ i18n: null
+ access_author: ''
+linkTypeConfig: { }
diff --git a/lib/Drupal/flag/Form/FlagAddPageForm.php b/lib/Drupal/flag/Form/FlagAddPageForm.php
index 4a18772..82eaeab 100644
--- a/lib/Drupal/flag/Form/FlagAddPageForm.php
+++ b/lib/Drupal/flag/Form/FlagAddPageForm.php
@@ -11,7 +11,7 @@
use Drupal\Core\Form\FormBase;
use Drupal\flag\Handlers\AbstractFlag;
-class FlagAddPageForm extends FormBase{
+class FlagAddPageForm extends FormBase {
/**
* {@inheritdoc}
diff --git a/lib/Drupal/flag/Plugin/views/field/FlagViewsLinkField.php b/lib/Drupal/flag/Plugin/views/field/FlagViewsLinkField.php
new file mode 100644
index 0000000..f9f94af
--- /dev/null
+++ b/lib/Drupal/flag/Plugin/views/field/FlagViewsLinkField.php
@@ -0,0 +1,74 @@
+ '',
+ 'translatable' => TRUE,
+ );
+/*
+ $options['link_to_entity'] = array(
+ 'default' => FALSE,
+ 'bool' => TRUE,
+ );
+*/
+ //@todo return link type
+
+ return $options;
+ }
+
+ /**
+ * @param $form
+ * @param $form_state
+ */
+ public function buildOptionsForm(&$form, &$form_state) {
+ $form['text'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Text to display'),
+ '#default_value' => $this->options['text'],
+ );
+
+ parent::buildOptionsForm($form, $form_state);
+ }
+
+ /**
+ * @param ResultRow $values
+ * @return string|void
+ */
+ public function render(ResultRow $values) {
+ $comment = $this->getEntity($values);
+ return $this->renderLink($comment, $values);
+ }
+
+ /**
+ * @param $data
+ * @param ResultRow $values
+ */
+ protected function renderLink($data, ResultRow $values) {
+ if ($node->access('view')) {
+ $text = !empty($this->options['text']) ? $this->options['text'] : t('View');
+ return $text;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Drupal/flag/Plugin/views/relationship/FlagViewsRelationship.php b/lib/Drupal/flag/Plugin/views/relationship/FlagViewsRelationship.php
new file mode 100644
index 0000000..14cb1fe
--- /dev/null
+++ b/lib/Drupal/flag/Plugin/views/relationship/FlagViewsRelationship.php
@@ -0,0 +1,71 @@
+ NULL);
+ $options['required'] = array('default' => 1);
+ $options['user_scope'] = array('default' => 'current');
+ return $options;
+ }
+
+ protected function buildOptionsForm(&$form, &$form_state) {
+ $entity_type = $this->definition['flag type'];
+ $form['label']['#description'] .= ' ' . t('The name of the selected flag makes a good label.');
+ $form['flag'] = array(
+ '#type' => $form_type,
+ '#title' => t('Flag'),
+ '#default_value' => $current_flag,
+ '#required' => TRUE,
+ );
+
+ $flags = \Drupal::service('flag')->getFlags($entity_type)
+ foreach ($flags as $flag) {
+ $form['flag']['#options'][$flag->label()] = $flag->id();
+ }
+
+ $form['user_scope'] = array(
+ '#type' => 'radios',
+ '#title' => t('By'),
+ '#options' => array('current' => t('Current user'), 'any' => t('Any user')),
+ '#default_value' => $this->options['user_scope'],
+ );
+
+ $form['required']['#title'] = t('Include only flagged content');
+ $form['required']['#description'] = t('If checked, only content that has this flag will be included. Leave unchecked to include all content; or, in combination with the Flagged filter, to limit the results to specifically unflagged content.', array('@unflagged-url' => 'http://drupal.org/node/299335'));
+
+ if (!$form['flag']['#options']) {
+ $form = array(
+ 'error' => array(
+ '#markup' => '' . t('No %type flags exist. You must first create a %type flag before being able to use this relationship type.', array('%type' => $entity_type, '@create-url' => url(FLAG_ADMIN_PATH))) . '
',
+ ),
+ );
+ $form_state['no flags exist'] = TRUE;
+ }
+
+ parent::buildOptionsForm($form, $form_state);
+ }
+
+ public query() {
+ $this->ensureMyTable();
+
+ $def = $this->definition;
+ $def['table'] = 'flag';
+ }
+}
\ No newline at end of file
From c4e86d38718c1613f30dd6449013bf652ad723b2 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 28 May 2014 22:57:33 -0500
Subject: [PATCH 387/629] Partially working FlagViewsRelationship.
---
flag.views.inc | 47 +++++++++++++++++--
.../Plugin/views/field/FlagViewsLinkField.php | 9 ++++
.../relationship/FlagViewsRelationship.php | 33 ++++++++-----
3 files changed, 75 insertions(+), 14 deletions(-)
diff --git a/flag.views.inc b/flag.views.inc
index edcd699..90082dc 100644
--- a/flag.views.inc
+++ b/flag.views.inc
@@ -16,6 +16,46 @@ function flag_views_data() {
'field' => 'entity_id',
),
);
+
+ $data['flagging']['uid'] = array(
+ 'title' => t('User uid'),
+ 'help' => t('The user that flagged an item. If you need more fields than the uid add the "Flags: User" relationship.'),
+ 'relationship' => array(
+ 'base' => 'users',
+ 'title' => t('User'),
+ 'help' => t('Relate an item to the user that flagged it.'),
+ 'id' => 'standard',
+ 'label' => t('Flag user'),
+ ),
+ 'filter' => array(
+ 'id' => 'numeric',
+ ),
+ 'argument' => array(
+ 'id' => 'numeric',
+ ),
+ 'field' => array(
+ 'id' => 'user',
+ ),
+ );
+
+ $data['flagging']['timestamp'] = array(
+ 'title' => t('Flagged time'),
+ 'help' => t('Display the time the content was flagged by a user.'),
+ 'field' => array(
+ 'id' => 'date',
+ //'click sortable' => TRUE,
+ ),
+ 'sort' => array(
+ 'id' => 'date',
+ ),
+ 'filter' => array(
+ 'id' => 'date',
+ ),
+ 'argument' => array(
+ 'id' => 'date',
+ ),
+ );
+
$data['flagging']['entity_id'] = array(
'title' => t('Entity ID'),
'help' => t('The ID of the entity'),
@@ -43,8 +83,9 @@ function flag_views_data_alter(&$data) {
foreach ($flags as $fid => $flag) {
$flag_type_plugin = $flag->getFlagTypePlugin();
$flag_type_def = $flag_type_plugin->getPluginDefinition();
+ $entity_type = $flag_type_def['entity_type'];
- $info = \Drupal::entityManager()->getDefinition($flag_type_def['entity_type']);
+ $info = \Drupal::entityManager()->getDefinition($entity_type);
$base_table = $info->getBaseTable();
if ($flag_type_def['entity_type'] == 'node') {
@@ -52,7 +93,7 @@ function flag_views_data_alter(&$data) {
}
$data[$base_table]['flag_content_rel'] = array(
- 'title' => t('@entity_label flag', array('@entity_label' => $flag_type_def['entity_type'])),
+ 'title' => t('@entity_label flag', array('@entity_label' => $entity_type)),
'help' => t('Limit results to only those entity flagged by a certain flag; Or display information about the flag set on a entity.'),
'relationship' => array(
'group' => t('Flag'),
@@ -61,7 +102,7 @@ function flag_views_data_alter(&$data) {
'base field' => 'entity_id',
'relationship field' => $info->getKey('id'),
'id' => 'flag_relationship',
- 'flag type' => $fid,
+ 'flaggable' => $entity_type,
),
);
diff --git a/lib/Drupal/flag/Plugin/views/field/FlagViewsLinkField.php b/lib/Drupal/flag/Plugin/views/field/FlagViewsLinkField.php
index f9f94af..74e7913 100644
--- a/lib/Drupal/flag/Plugin/views/field/FlagViewsLinkField.php
+++ b/lib/Drupal/flag/Plugin/views/field/FlagViewsLinkField.php
@@ -19,6 +19,15 @@
*/
class FlagViewsLinkField extends FieldPluginBase {
+ public function getFlag() {
+ // When editing a view it's possible to delete the relationship (either by
+ // error or to later recreate it), so we have to guard against a missing
+ // one.
+ if (isset($this->view->relationship[$this->options['relationship']])) {
+ return $this->view->relationship[$this->options['relationship']]->getFlag();
+ }
+ }
+
protected function defineOptions() {
$options = parent::defineOptions();
diff --git a/lib/Drupal/flag/Plugin/views/relationship/FlagViewsRelationship.php b/lib/Drupal/flag/Plugin/views/relationship/FlagViewsRelationship.php
index 14cb1fe..a3ad58d 100644
--- a/lib/Drupal/flag/Plugin/views/relationship/FlagViewsRelationship.php
+++ b/lib/Drupal/flag/Plugin/views/relationship/FlagViewsRelationship.php
@@ -15,29 +15,40 @@
*
* @ViewsRelationship("flag_relationship")
*/
-public class FlagViewsRelationship extends RelationshipPluginBase {
+class FlagViewsRelationship extends RelationshipPluginBase {
- protected function defineOptions() {
+ public function defineOptions() {
$options = parent::defineOptions();
- $options['flag'] = array('default' => NULL);
+ $options['flag'] = array('default' => NULL); // @todo load first defined flag for entity.
$options['required'] = array('default' => 1);
$options['user_scope'] = array('default' => 'current');
return $options;
}
- protected function buildOptionsForm(&$form, &$form_state) {
- $entity_type = $this->definition['flag type'];
+ public function buildOptionsForm(&$form, &$form_state) {
+ $entity_type = $this->definition['flaggable'];
$form['label']['#description'] .= ' ' . t('The name of the selected flag makes a good label.');
+
+ /*//////////////////////////////////////////////////////////////////////////
+ @todo Add Flag selection form
+
+ The Flag relationship relates a single flag to a single entity. Since
+ multiple flags may be configured for the same entity type, we need to
+ provide a form here that allows us to choose the flag.
+ //////////////////////////////////////////////////////////////////////////*/
+ $flags = \Drupal::service('flag')->getFlags($entity_type);
+
$form['flag'] = array(
- '#type' => $form_type,
+ '#type' => 'radios',
'#title' => t('Flag'),
- '#default_value' => $current_flag,
+ // '#default_value' => current(array_keys($flags)),
'#required' => TRUE,
);
- $flags = \Drupal::service('flag')->getFlags($entity_type)
- foreach ($flags as $flag) {
- $form['flag']['#options'][$flag->label()] = $flag->id();
+ foreach ($flags as $fid => $flag) {
+ if (!empty($flag)) {
+ $form['flag']['#options'][$flag->label()] = $fid;
+ }
}
$form['user_scope'] = array(
@@ -62,7 +73,7 @@ protected function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
}
- public query() {
+ public function query() {
$this->ensureMyTable();
$def = $this->definition;
From 5439724e6ae24905bc87244b550ad439c7221fae Mon Sep 17 00:00:00 2001
From: socketwench
Date: Tue, 3 Jun 2014 10:17:33 -0500
Subject: [PATCH 388/629] Holy mega PSR-4 class move, batman\!
---
{lib/Drupal/flag => src}/ActionLinkPluginManager.php | 0
{lib/Drupal/flag => src}/ActionLinkTypeBase.php | 0
{lib/Drupal/flag => src}/ActionLinkTypePluginInterface.php | 0
{lib/Drupal/flag => src}/Annotation/ActionLinkType.php | 0
{lib/Drupal/flag => src}/Annotation/FlagType.php | 0
{lib/Drupal/flag => src}/BrokenFlagType.php | 0
{lib/Drupal/flag => src}/Controller/AJAXLinkController.php | 0
{lib/Drupal/flag => src}/Controller/FlagListController.php | 0
{lib/Drupal/flag => src}/Controller/ReloadLinkController.php | 0
{lib/Drupal/flag => src}/Entity/Flag.php | 0
{lib/Drupal/flag => src}/Entity/Flagging.php | 0
{lib/Drupal/flag => src}/FlagInterface.php | 0
{lib/Drupal/flag => src}/FlagService.php | 0
{lib/Drupal/flag => src}/FlagTypeBase.php | 0
{lib/Drupal/flag => src}/FlagTypePluginInterface.php | 0
{lib/Drupal/flag => src}/FlagTypePluginManager.php | 0
{lib/Drupal/flag => src}/FlaggingAccessController.php | 0
{lib/Drupal/flag => src}/FlaggingInterface.php | 0
{lib/Drupal/flag => src}/Form/FlagAddForm.php | 0
{lib/Drupal/flag => src}/Form/FlagAddPageForm.php | 0
{lib/Drupal/flag => src}/Form/FlagDeleteForm.php | 0
{lib/Drupal/flag => src}/Form/FlagEditForm.php | 0
{lib/Drupal/flag => src}/Form/FlagExportForm.php | 0
{lib/Drupal/flag => src}/Form/FlagFormBase.php | 0
{lib/Drupal/flag => src}/Form/FlagImportForm.php | 0
{lib/Drupal/flag => src}/Form/FlaggingConfirmForm.php | 0
{lib/Drupal/flag => src}/Plugin/ActionLink/AJAXactionLink.php | 0
{lib/Drupal/flag => src}/Plugin/ActionLink/ConfirmForm.php | 0
{lib/Drupal/flag => src}/Plugin/ActionLink/Reload.php | 0
{lib/Drupal/flag => src}/Plugin/Derivative/EntityFlagType.php | 0
{lib/Drupal/flag => src}/Plugin/Flag/CommentFlagType.php | 0
{lib/Drupal/flag => src}/Plugin/Flag/EntityFlagType.php | 0
{lib/Drupal/flag => src}/Plugin/Flag/NodeFlagType.php | 0
{lib/Drupal/flag => src}/Plugin/Flag/UserFlagType.php | 0
.../Drupal/flag => src}/Plugin/views/field/FlagViewsLinkField.php | 0
.../Plugin/views/relationship/FlagViewsRelationship.php | 0
{lib/Drupal/flag => src}/config/schema/flag.schema.yml | 0
37 files changed, 0 insertions(+), 0 deletions(-)
rename {lib/Drupal/flag => src}/ActionLinkPluginManager.php (100%)
rename {lib/Drupal/flag => src}/ActionLinkTypeBase.php (100%)
rename {lib/Drupal/flag => src}/ActionLinkTypePluginInterface.php (100%)
rename {lib/Drupal/flag => src}/Annotation/ActionLinkType.php (100%)
rename {lib/Drupal/flag => src}/Annotation/FlagType.php (100%)
rename {lib/Drupal/flag => src}/BrokenFlagType.php (100%)
rename {lib/Drupal/flag => src}/Controller/AJAXLinkController.php (100%)
rename {lib/Drupal/flag => src}/Controller/FlagListController.php (100%)
rename {lib/Drupal/flag => src}/Controller/ReloadLinkController.php (100%)
rename {lib/Drupal/flag => src}/Entity/Flag.php (100%)
rename {lib/Drupal/flag => src}/Entity/Flagging.php (100%)
rename {lib/Drupal/flag => src}/FlagInterface.php (100%)
rename {lib/Drupal/flag => src}/FlagService.php (100%)
rename {lib/Drupal/flag => src}/FlagTypeBase.php (100%)
rename {lib/Drupal/flag => src}/FlagTypePluginInterface.php (100%)
rename {lib/Drupal/flag => src}/FlagTypePluginManager.php (100%)
rename {lib/Drupal/flag => src}/FlaggingAccessController.php (100%)
rename {lib/Drupal/flag => src}/FlaggingInterface.php (100%)
rename {lib/Drupal/flag => src}/Form/FlagAddForm.php (100%)
rename {lib/Drupal/flag => src}/Form/FlagAddPageForm.php (100%)
rename {lib/Drupal/flag => src}/Form/FlagDeleteForm.php (100%)
rename {lib/Drupal/flag => src}/Form/FlagEditForm.php (100%)
rename {lib/Drupal/flag => src}/Form/FlagExportForm.php (100%)
rename {lib/Drupal/flag => src}/Form/FlagFormBase.php (100%)
rename {lib/Drupal/flag => src}/Form/FlagImportForm.php (100%)
rename {lib/Drupal/flag => src}/Form/FlaggingConfirmForm.php (100%)
rename {lib/Drupal/flag => src}/Plugin/ActionLink/AJAXactionLink.php (100%)
rename {lib/Drupal/flag => src}/Plugin/ActionLink/ConfirmForm.php (100%)
rename {lib/Drupal/flag => src}/Plugin/ActionLink/Reload.php (100%)
rename {lib/Drupal/flag => src}/Plugin/Derivative/EntityFlagType.php (100%)
rename {lib/Drupal/flag => src}/Plugin/Flag/CommentFlagType.php (100%)
rename {lib/Drupal/flag => src}/Plugin/Flag/EntityFlagType.php (100%)
rename {lib/Drupal/flag => src}/Plugin/Flag/NodeFlagType.php (100%)
rename {lib/Drupal/flag => src}/Plugin/Flag/UserFlagType.php (100%)
rename {lib/Drupal/flag => src}/Plugin/views/field/FlagViewsLinkField.php (100%)
rename {lib/Drupal/flag => src}/Plugin/views/relationship/FlagViewsRelationship.php (100%)
rename {lib/Drupal/flag => src}/config/schema/flag.schema.yml (100%)
diff --git a/lib/Drupal/flag/ActionLinkPluginManager.php b/src/ActionLinkPluginManager.php
similarity index 100%
rename from lib/Drupal/flag/ActionLinkPluginManager.php
rename to src/ActionLinkPluginManager.php
diff --git a/lib/Drupal/flag/ActionLinkTypeBase.php b/src/ActionLinkTypeBase.php
similarity index 100%
rename from lib/Drupal/flag/ActionLinkTypeBase.php
rename to src/ActionLinkTypeBase.php
diff --git a/lib/Drupal/flag/ActionLinkTypePluginInterface.php b/src/ActionLinkTypePluginInterface.php
similarity index 100%
rename from lib/Drupal/flag/ActionLinkTypePluginInterface.php
rename to src/ActionLinkTypePluginInterface.php
diff --git a/lib/Drupal/flag/Annotation/ActionLinkType.php b/src/Annotation/ActionLinkType.php
similarity index 100%
rename from lib/Drupal/flag/Annotation/ActionLinkType.php
rename to src/Annotation/ActionLinkType.php
diff --git a/lib/Drupal/flag/Annotation/FlagType.php b/src/Annotation/FlagType.php
similarity index 100%
rename from lib/Drupal/flag/Annotation/FlagType.php
rename to src/Annotation/FlagType.php
diff --git a/lib/Drupal/flag/BrokenFlagType.php b/src/BrokenFlagType.php
similarity index 100%
rename from lib/Drupal/flag/BrokenFlagType.php
rename to src/BrokenFlagType.php
diff --git a/lib/Drupal/flag/Controller/AJAXLinkController.php b/src/Controller/AJAXLinkController.php
similarity index 100%
rename from lib/Drupal/flag/Controller/AJAXLinkController.php
rename to src/Controller/AJAXLinkController.php
diff --git a/lib/Drupal/flag/Controller/FlagListController.php b/src/Controller/FlagListController.php
similarity index 100%
rename from lib/Drupal/flag/Controller/FlagListController.php
rename to src/Controller/FlagListController.php
diff --git a/lib/Drupal/flag/Controller/ReloadLinkController.php b/src/Controller/ReloadLinkController.php
similarity index 100%
rename from lib/Drupal/flag/Controller/ReloadLinkController.php
rename to src/Controller/ReloadLinkController.php
diff --git a/lib/Drupal/flag/Entity/Flag.php b/src/Entity/Flag.php
similarity index 100%
rename from lib/Drupal/flag/Entity/Flag.php
rename to src/Entity/Flag.php
diff --git a/lib/Drupal/flag/Entity/Flagging.php b/src/Entity/Flagging.php
similarity index 100%
rename from lib/Drupal/flag/Entity/Flagging.php
rename to src/Entity/Flagging.php
diff --git a/lib/Drupal/flag/FlagInterface.php b/src/FlagInterface.php
similarity index 100%
rename from lib/Drupal/flag/FlagInterface.php
rename to src/FlagInterface.php
diff --git a/lib/Drupal/flag/FlagService.php b/src/FlagService.php
similarity index 100%
rename from lib/Drupal/flag/FlagService.php
rename to src/FlagService.php
diff --git a/lib/Drupal/flag/FlagTypeBase.php b/src/FlagTypeBase.php
similarity index 100%
rename from lib/Drupal/flag/FlagTypeBase.php
rename to src/FlagTypeBase.php
diff --git a/lib/Drupal/flag/FlagTypePluginInterface.php b/src/FlagTypePluginInterface.php
similarity index 100%
rename from lib/Drupal/flag/FlagTypePluginInterface.php
rename to src/FlagTypePluginInterface.php
diff --git a/lib/Drupal/flag/FlagTypePluginManager.php b/src/FlagTypePluginManager.php
similarity index 100%
rename from lib/Drupal/flag/FlagTypePluginManager.php
rename to src/FlagTypePluginManager.php
diff --git a/lib/Drupal/flag/FlaggingAccessController.php b/src/FlaggingAccessController.php
similarity index 100%
rename from lib/Drupal/flag/FlaggingAccessController.php
rename to src/FlaggingAccessController.php
diff --git a/lib/Drupal/flag/FlaggingInterface.php b/src/FlaggingInterface.php
similarity index 100%
rename from lib/Drupal/flag/FlaggingInterface.php
rename to src/FlaggingInterface.php
diff --git a/lib/Drupal/flag/Form/FlagAddForm.php b/src/Form/FlagAddForm.php
similarity index 100%
rename from lib/Drupal/flag/Form/FlagAddForm.php
rename to src/Form/FlagAddForm.php
diff --git a/lib/Drupal/flag/Form/FlagAddPageForm.php b/src/Form/FlagAddPageForm.php
similarity index 100%
rename from lib/Drupal/flag/Form/FlagAddPageForm.php
rename to src/Form/FlagAddPageForm.php
diff --git a/lib/Drupal/flag/Form/FlagDeleteForm.php b/src/Form/FlagDeleteForm.php
similarity index 100%
rename from lib/Drupal/flag/Form/FlagDeleteForm.php
rename to src/Form/FlagDeleteForm.php
diff --git a/lib/Drupal/flag/Form/FlagEditForm.php b/src/Form/FlagEditForm.php
similarity index 100%
rename from lib/Drupal/flag/Form/FlagEditForm.php
rename to src/Form/FlagEditForm.php
diff --git a/lib/Drupal/flag/Form/FlagExportForm.php b/src/Form/FlagExportForm.php
similarity index 100%
rename from lib/Drupal/flag/Form/FlagExportForm.php
rename to src/Form/FlagExportForm.php
diff --git a/lib/Drupal/flag/Form/FlagFormBase.php b/src/Form/FlagFormBase.php
similarity index 100%
rename from lib/Drupal/flag/Form/FlagFormBase.php
rename to src/Form/FlagFormBase.php
diff --git a/lib/Drupal/flag/Form/FlagImportForm.php b/src/Form/FlagImportForm.php
similarity index 100%
rename from lib/Drupal/flag/Form/FlagImportForm.php
rename to src/Form/FlagImportForm.php
diff --git a/lib/Drupal/flag/Form/FlaggingConfirmForm.php b/src/Form/FlaggingConfirmForm.php
similarity index 100%
rename from lib/Drupal/flag/Form/FlaggingConfirmForm.php
rename to src/Form/FlaggingConfirmForm.php
diff --git a/lib/Drupal/flag/Plugin/ActionLink/AJAXactionLink.php b/src/Plugin/ActionLink/AJAXactionLink.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/ActionLink/AJAXactionLink.php
rename to src/Plugin/ActionLink/AJAXactionLink.php
diff --git a/lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php b/src/Plugin/ActionLink/ConfirmForm.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/ActionLink/ConfirmForm.php
rename to src/Plugin/ActionLink/ConfirmForm.php
diff --git a/lib/Drupal/flag/Plugin/ActionLink/Reload.php b/src/Plugin/ActionLink/Reload.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/ActionLink/Reload.php
rename to src/Plugin/ActionLink/Reload.php
diff --git a/lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php b/src/Plugin/Derivative/EntityFlagType.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/Derivative/EntityFlagType.php
rename to src/Plugin/Derivative/EntityFlagType.php
diff --git a/lib/Drupal/flag/Plugin/Flag/CommentFlagType.php b/src/Plugin/Flag/CommentFlagType.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/Flag/CommentFlagType.php
rename to src/Plugin/Flag/CommentFlagType.php
diff --git a/lib/Drupal/flag/Plugin/Flag/EntityFlagType.php b/src/Plugin/Flag/EntityFlagType.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/Flag/EntityFlagType.php
rename to src/Plugin/Flag/EntityFlagType.php
diff --git a/lib/Drupal/flag/Plugin/Flag/NodeFlagType.php b/src/Plugin/Flag/NodeFlagType.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/Flag/NodeFlagType.php
rename to src/Plugin/Flag/NodeFlagType.php
diff --git a/lib/Drupal/flag/Plugin/Flag/UserFlagType.php b/src/Plugin/Flag/UserFlagType.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/Flag/UserFlagType.php
rename to src/Plugin/Flag/UserFlagType.php
diff --git a/lib/Drupal/flag/Plugin/views/field/FlagViewsLinkField.php b/src/Plugin/views/field/FlagViewsLinkField.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/views/field/FlagViewsLinkField.php
rename to src/Plugin/views/field/FlagViewsLinkField.php
diff --git a/lib/Drupal/flag/Plugin/views/relationship/FlagViewsRelationship.php b/src/Plugin/views/relationship/FlagViewsRelationship.php
similarity index 100%
rename from lib/Drupal/flag/Plugin/views/relationship/FlagViewsRelationship.php
rename to src/Plugin/views/relationship/FlagViewsRelationship.php
diff --git a/lib/Drupal/flag/config/schema/flag.schema.yml b/src/config/schema/flag.schema.yml
similarity index 100%
rename from lib/Drupal/flag/config/schema/flag.schema.yml
rename to src/config/schema/flag.schema.yml
From ba21da1e92e6af76966ae9528db4f13913dd75b8 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Tue, 3 Jun 2014 17:58:09 -0500
Subject: [PATCH 389/629] Updated the signature of hook_entity_view() due to
https://drupal.org/node/2246681
---
flag.module | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/flag.module b/flag.module
index 4e823d2..84569ba 100644
--- a/flag.module
+++ b/flag.module
@@ -10,9 +10,10 @@ define('FLAG_API_VERSION', 3);
define('FLAG_ADMIN_PATH', 'admin/structure/flags');
define('FLAG_ADMIN_PATH_START', 3);
-use Drupal\flag\Handlers\AbstractFlag;
use Drupal\flag\Flag;
use Drupal\node\NodeInterface;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
// @todo: Implement flagging_view(). Not extremely useful. I already have it.
@@ -578,7 +579,10 @@ function flag_field_attach_save($entity_type, $entity) {
*
* Note this is broken for taxonomy terms for version of Drupal core < 7.17.
*/
-function flag_entity_view($entity, $display, $view_mode, $langcode) {
+function flag_entity_view(array &$build, EntityInterface $entity,
+ EntityViewDisplayInterface $display,
+ $view_mode, $langcode) {
+
//@todo Check $type->getComponent('flag_whateverHookFieldExtraFieldsIS').
// if not NULL, display it.
From 546b61534ea3a7094cbcc4af5acf08d50e535298 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 4 Jun 2014 09:31:30 -0500
Subject: [PATCH 390/629] Fixes for
https://github.com/socketwench/flag-drupal8/issues/7 and changes to Drupal
core.
---
flag.install | 2 +-
flag.module | 2 +-
src/Entity/Flag.php | 2 ++
src/Entity/Flagging.php | 2 +-
4 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/flag.install b/flag.install
index 364686b..91f8ba8 100644
--- a/flag.install
+++ b/flag.install
@@ -109,7 +109,7 @@ function flag_schema() {
'not null' => TRUE,
'default' => 0,
),
- 'timestamp' => array(
+ 'created' => array(
'description' => 'The UNIX time stamp representing when the flag was set.',
'type' => 'int',
'unsigned' => TRUE,
diff --git a/flag.module b/flag.module
index 84569ba..c2fa936 100644
--- a/flag.module
+++ b/flag.module
@@ -601,7 +601,7 @@ function flag_entity_view(array &$build, EntityInterface $entity,
}
$link = $linkTypePlugin->renderLink($action, $flag, $entity);
- $entity->content['flag_' . $flag->id] = $link;
+ $build['flag_' . $flag->id] = $link;
}
/**
diff --git a/src/Entity/Flag.php b/src/Entity/Flag.php
index ea87af2..2c93152 100644
--- a/src/Entity/Flag.php
+++ b/src/Entity/Flag.php
@@ -320,6 +320,8 @@ public function preSave(EntityStorageInterface $storage_controller) {
\Drupal::entityManager()
->getViewBuilder($this->getFlaggableEntityType())
->resetCache();
+
+ entity_render_cache_clear();
}
public function toArray() {
diff --git a/src/Entity/Flagging.php b/src/Entity/Flagging.php
index 4147d38..9ab2ab8 100644
--- a/src/Entity/Flagging.php
+++ b/src/Entity/Flagging.php
@@ -75,7 +75,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->setDescription(t('The flagging UUID.'))
->setReadOnly(TRUE);
- $fields['fid'] = FieldDefinition::create('integer')
+ $fields['fid'] = FieldDefinition::create('string')
->setLabel(t('Flag ID'))
->setDescription(t('The Flag ID.'))
->setReadOnly(TRUE);
From 0552c5b0035da2b0e9d09ac9a31e909771b28887 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 4 Jun 2014 09:35:05 -0500
Subject: [PATCH 391/629] Removed unnecessary entity cache clear all in
Flag::preSave().
---
src/Entity/Flag.php | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/Entity/Flag.php b/src/Entity/Flag.php
index 2c93152..ea87af2 100644
--- a/src/Entity/Flag.php
+++ b/src/Entity/Flag.php
@@ -320,8 +320,6 @@ public function preSave(EntityStorageInterface $storage_controller) {
\Drupal::entityManager()
->getViewBuilder($this->getFlaggableEntityType())
->resetCache();
-
- entity_render_cache_clear();
}
public function toArray() {
From f2e32d7bda9adb56746cbf481b1ac71ea18f7f05 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 4 Jun 2014 13:49:39 -0500
Subject: [PATCH 392/629] Fixed some breakage with the AJAX link type.
---
flag.module | 60 ++++-----------------------------------
src/Entity/Flagging.php | 2 +-
src/Form/FlagFormBase.php | 8 ++++--
3 files changed, 11 insertions(+), 59 deletions(-)
diff --git a/flag.module b/flag.module
index c2fa936..d65bdc3 100644
--- a/flag.module
+++ b/flag.module
@@ -603,56 +603,6 @@ function flag_entity_view(array &$build, EntityInterface $entity,
$link = $linkTypePlugin->renderLink($action, $flag, $entity);
$build['flag_' . $flag->id] = $link;
}
-
- /**
- foreach ($flags as $flag) {
- // Check if the flag outputs on entity view.
- if (!($flag->show_as_field)) { //} || $flag->shows_in_entity_links($view_mode))) {
- // Flag is not configured to output on entity view, so skip it to save on
- // calls to access checks.
- continue;
- }
-
- $entity_id = $flag->get_entity_id($entity);
- // For a new, unsaved entity, make a dummy entity ID so that the flag
- // handler can remember the entity. This allows access to the flag to be
- // correctly handled in node and comment preview.
- if (is_null($entity_id)) {
- $entity_id = 'new';
- }
- $flag->remember_entity($entity_id, $entity);
-
- if (!$flag->access($entity_id) && (!$flag->is_flagged($entity_id) || !$flag->access($entity_id, 'flag'))) {
- // User has no permission to use this flag or flag does not apply to this
- // entity. The link is not skipped if the user has "flag" access but
- // not "unflag" access (this way the unflag denied message is shown).
- continue;
- }
-
- // We're good to go. Output the flag in the appropriate manner(s).
-
- // The old-style entity links output.
- if ($flag->shows_in_entity_links($view_mode)) {
- // The flag links are actually fully rendered theme functions.
- // The HTML attribute is set to TRUE to allow whatever the themer desires.
- $links['flag-' . $flag->name] = array(
- 'title' => $flag->flag_short, //theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id),
- 'html' => TRUE,
- );
- }
-
- // The pseudofield output.
- if ($flag->show_as_field) {
- $entity->content['flag_' . $flag->name] = array(
- '#markup' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, array('needs_wrapping_element' => TRUE)),
- );
- }
- }
- */
- // If any links were made, add them to the entity's links array.
-// if (isset($links)) {
-// $entity->content['links']['flag'] = $links;
- // }
}
/**
@@ -836,7 +786,7 @@ function flag_user_delete($account) {
/**
* Shared helper for user account cancellation or deletion.
- */
+ *//*
function flag_user_account_removal($account) {
// Remove flags by this user.
$query = db_select('flagging', 'fc');
@@ -872,11 +822,11 @@ function flag_user_account_removal($account) {
// Remove flags that have been done to this user.
_flag_entity_delete('user', $account->uid);
-}
+}*/
/**
* Implements hook_user_view().
- */
+ *//*
function flag_user_view($account, $view_mode) {
$flags = flag_get_flags('user');
$flag_items = array();
@@ -885,7 +835,7 @@ function flag_user_view($account, $view_mode) {
// User has no permission to use this flag.
continue;
}
- if (!$flag->show_on_profile) {
+ if (empty($flag->show_on_profile)) {
// Flag not set to appear on profile.
continue;
}
@@ -904,7 +854,7 @@ function flag_user_view($account, $view_mode) {
'#attributes' => array('class' => array('flag-profile')),
);
}
-}
+}*/
/**
* Implements hook_session_api_cleanup().
diff --git a/src/Entity/Flagging.php b/src/Entity/Flagging.php
index 9ab2ab8..debe1a4 100644
--- a/src/Entity/Flagging.php
+++ b/src/Entity/Flagging.php
@@ -49,7 +49,7 @@ public function getFlagId() {
}
public function getFlag() {
- return entity_load($this->bundle, $this->getFlagId());
+ return entity_load('flag_flag', $this->getFlagId());
}
public function getFlaggableType() {
diff --git a/src/Form/FlagFormBase.php b/src/Form/FlagFormBase.php
index ae8c84f..7d39287 100644
--- a/src/Form/FlagFormBase.php
+++ b/src/Form/FlagFormBase.php
@@ -188,14 +188,16 @@ public function validate(array $form, array &$form_state) {
$form_state['values']['label'] = trim($form_state['values']['label']);
$form_values = $form_state['values'];
+ //@todo Move this to the validation method for the confirm form plugin
+ /*
if ($form_values['link_type'] == 'confirm') {
if (empty($form_values['flag_confirmation'])) {
- form_set_error('flag_confirmation', array(t('A flag confirmation message is required when using the confirmation link type.')));
+ $this->setFormError('flag_confirmation', $form_state, $this->t('A flag confirmation message is required when using the confirmation link type.'));
}
if (empty($form_values['unflag_confirmation'])) {
- form_set_error('unflag_confirmation', array(t('An unflag confirmation message is required when using the confirmation link type.')));
+ $this->setFormError('unflag_confirmation', $form_state, $this->t('An unflag confirmation message is required when using the confirmation link type.'));
}
- }
+ }*/
/*
if (!preg_match('/^[a-z_][a-z0-9_]*$/', $form_values['id'])) {
form_set_error('label', t('The flag name may only contain lowercase letters, underscores, and numbers.'));
From 1c7bdeab40ec6825034a90ef63ea09e868ddec8c Mon Sep 17 00:00:00 2001
From: socketwench
Date: Wed, 4 Jun 2014 14:53:48 -0500
Subject: [PATCH 393/629] Fixed confirm form, some API cleanup in FlagService.
---
src/FlagService.php | 37 ++++++++++++++++++++++-----
src/Plugin/ActionLink/ConfirmForm.php | 4 +--
2 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/src/FlagService.php b/src/FlagService.php
index 17bbcd1..a8352e8 100644
--- a/src/FlagService.php
+++ b/src/FlagService.php
@@ -146,6 +146,15 @@ public function flagByObject(FlagInterface $flag, EntityInterface $entity, Accou
return $flagging;
}
+ /**
+ *
+ * @api
+ *
+ * @param $flag_id
+ * @param $entity_id
+ * @param AccountInterface $account
+ * @return EntityInterface
+ */
public function flag($flag_id, $entity_id, AccountInterface $account = NULL) {
if (empty($account)) {
$account = \Drupal::currentUser();
@@ -157,10 +166,15 @@ public function flag($flag_id, $entity_id, AccountInterface $account = NULL) {
return $this->flagByObject($flag, $entity, $account);
}
- public function unflagByObject(FlaggingInterface $flagging) {
- $flagging->delete();
- }
-
+ /**
+ *
+ * @api
+ *
+ * @param $flag_id
+ * @param $entity_id
+ * @param AccountInterface $account
+ * @return array
+ */
public function unflag($flag_id, $entity_id, AccountInterface $account = NULL) {
if (empty($account)) {
$account = \Drupal::currentUser();
@@ -169,13 +183,24 @@ public function unflag($flag_id, $entity_id, AccountInterface $account = NULL) {
$flag = $this->getFlagById($flag_id);
$entity = $this->getFlaggableById($flag, $entity_id);
+ return $this->unflagByObject($flag, $entity, $account);
+ }
+
+
+ public function unflagByObject(FlagInterface $flag,
+ EntityInterface $entity,
+ AccountInterface $account = NULL) {
$out = array();
$flaggings = $this->getFlaggings($entity, $flag);
foreach ($flaggings as $flagging) {
- $out[] = $this->unflagByObject($flagging);
+ $out[] = $this->unflagByFlagging($flagging);
}
return $out;
}
-}
\ No newline at end of file
+ public function unflagByFlagging(FlaggingInterface $flagging) {
+ $flagging->delete();
+ }
+
+}
\ No newline at end of file
diff --git a/src/Plugin/ActionLink/ConfirmForm.php b/src/Plugin/ActionLink/ConfirmForm.php
index e92986a..5ebfa8c 100644
--- a/src/Plugin/ActionLink/ConfirmForm.php
+++ b/src/Plugin/ActionLink/ConfirmForm.php
@@ -34,8 +34,8 @@ public function defaultConfiguration() {
$options = parent::defaultConfiguration();
$options += array(
- 'flag_confirmation' => '',
- 'unflag_confirmation' => '',
+ 'flag_confirmation' => 'Flag this content?',
+ 'unflag_confirmation' => 'Unflag this content?',
);
return $options;
From 04afa6f1706569c166c66b9e7d70f83bae93cdb4 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Thu, 5 Jun 2014 11:01:57 -0500
Subject: [PATCH 394/629] Updated hook_schema() due to
https://drupal.org/node/2259243.
---
flag.install | 78 ++--------------------------------------------------
1 file changed, 2 insertions(+), 76 deletions(-)
diff --git a/flag.install b/flag.install
index 91f8ba8..613a23b 100644
--- a/flag.install
+++ b/flag.install
@@ -11,56 +11,6 @@
function flag_schema() {
$schema = array();
/*
- $schema['flag'] = array(
- 'description' => 'All available flags in the system.',
- 'fields' => array(
- 'fid' => array(
- 'description' => 'The unique ID for this particular flag.',
- 'type' => 'serial',
- 'size' => 'small',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'entity_type' => array(
- 'description' => 'The flag type, such as one of "node", "comment", or "user".',
- 'type' => 'varchar',
- 'length' => '128',
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'name' => array(
- 'description' => 'The machine-name for this flag.',
- 'type' => 'varchar',
- 'length' => '32',
- 'not null' => FALSE,
- 'default' => '',
- ),
- 'title' => array(
- 'description' => 'The human-readable title for this flag.',
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => FALSE,
- 'default' => '',
- ),
- 'global' => array(
- 'description' => 'Whether this flag state should act as a single toggle to all users across the site.',
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => FALSE,
- 'default' => 0,
- ),
- 'options' => array(
- 'description' => 'The options and configuration of this flag.',
- 'type' => 'text',
- 'not null' => FALSE,
- ),
- ),
- 'primary key' => array('fid'),
- 'unique keys' => array(
- 'name' => array('name'),
- ),
- );
-*/
$schema['flagging'] = array(
'description' => 'Objects that have been flagged.',
'fields' => array(
@@ -135,31 +85,7 @@ function flag_schema() {
'entity_id_fid' => array('entity_id', 'fid'),
),
);
-/*
- $schema['flag_types'] = array(
- 'description' => 'The entity bundles that are affected by a flag.',
- 'fields' => array(
- 'fid' => array(
- 'description' => 'The unqiue flag ID as defined for the flag in {flag}.',
- 'type' => 'int',
- 'size' => 'small',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'type' => array(
- 'description' => 'The entity bundles that can be flagged by this fid.',
- 'type' => 'varchar',
- 'length' => '128',
- 'not null' => TRUE,
- 'default' => '',
- ),
- ),
- 'indexes' => array(
- 'fid' => array('fid'),
- ),
- );
-
+*/
$schema['flag_counts'] = array(
'description' => 'The number of times an item has been flagged.',
'fields' => array(
@@ -210,7 +136,7 @@ function flag_schema() {
'fid_last_updated' => array('fid', 'last_updated'),
),
);
-*/
+
return $schema;
}
From cdc9b1bc11876212d58297e024e1e534366bc5ff Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sat, 7 Jun 2014 12:41:36 -0500
Subject: [PATCH 395/629] Changes due to https://drupal.org/node/2259243, fixes
to views functionality.
---
flag.install | 88 +------------------
flag.views.inc | 2 +-
.../relationship/FlagViewsRelationship.php | 13 ++-
3 files changed, 14 insertions(+), 89 deletions(-)
diff --git a/flag.install b/flag.install
index 613a23b..3e7100b 100644
--- a/flag.install
+++ b/flag.install
@@ -10,82 +10,7 @@
*/
function flag_schema() {
$schema = array();
-/*
- $schema['flagging'] = array(
- 'description' => 'Objects that have been flagged.',
- 'fields' => array(
- 'id' => array(
- 'description' => 'The unique ID for this particular tag.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'uuid' => array(
- 'description' => 'Unique Key: Universally unique identifier for this entity.',
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => FALSE,
- ),
- 'fid' => array(
- 'description' => 'The unique flag ID this object has been flagged with, from {flag}.',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => FALSE,
- ),
- 'entity_type' => array(
- 'description' => 'The flag type, eg "node", "comment", "user".',
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- ),
- 'entity_id' => array(
- 'description' => 'The unique ID of the object, such as either the {cid}, {uid}, or {nid}.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'uid' => array(
- 'description' => 'The user ID by whom this object was flagged.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'sid' => array(
- 'description' => "The user's session id as stored in the session table.",
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'created' => array(
- 'description' => 'The UNIX time stamp representing when the flag was set.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'disp-size' => 11,
- ),
- 'type' => array(
- 'description' => 'The type of this node.',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- 'default' => '',
- ),
- ),
- 'primary key' => array('id'),
- 'unique keys' => array(
- 'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
- ),
- 'indexes' => array(
- 'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
- 'entity_type_entity_id_uid_sid' => array('entity_type', 'entity_id', 'uid', 'sid'),
- 'entity_id_fid' => array('entity_id', 'fid'),
- ),
- );
-*/
+
$schema['flag_counts'] = array(
'description' => 'The number of times an item has been flagged.',
'fields' => array(
@@ -144,15 +69,6 @@ function flag_schema() {
* Implements hook_uninstall().
*/
function flag_uninstall() {
- /*
- $result = db_select('variable', 'v')
- ->fields('v', array('name'))
- ->condition('name', 'flag_%', 'LIKE')
- ->execute();
- foreach ($result as $row) {
- variable_del($row->name);
- }
- */
drupal_set_message(t('Flag has been uninstalled.'));
}
@@ -160,6 +76,7 @@ function flag_uninstall() {
* Implements hook_requirements().
*/
function flag_requirements($phase) {
+ /*
$requirements = array();
if ($phase == 'runtime') {
@@ -191,4 +108,5 @@ function flag_requirements($phase) {
}
}
return $requirements;
+ */
}
diff --git a/flag.views.inc b/flag.views.inc
index 90082dc..7488d59 100644
--- a/flag.views.inc
+++ b/flag.views.inc
@@ -38,7 +38,7 @@ function flag_views_data() {
),
);
- $data['flagging']['timestamp'] = array(
+ $data['flagging']['created'] = array(
'title' => t('Flagged time'),
'help' => t('Display the time the content was flagged by a user.'),
'field' => array(
diff --git a/src/Plugin/views/relationship/FlagViewsRelationship.php b/src/Plugin/views/relationship/FlagViewsRelationship.php
index a3ad58d..18a6831 100644
--- a/src/Plugin/views/relationship/FlagViewsRelationship.php
+++ b/src/Plugin/views/relationship/FlagViewsRelationship.php
@@ -74,9 +74,16 @@ public function buildOptionsForm(&$form, &$form_state) {
}
public function query() {
- $this->ensureMyTable();
+ if (!($flag = $this->getFlag())) {
+ return;
+ }
+
+ parent::query();
+
+ }
- $def = $this->definition;
- $def['table'] = 'flag';
+ protected function getFlag() {
+ $flaggable = $this->options['flaggable'];
+ $this->options['flag'] = \Drupal::service('flag')->getFlag($flaggable);
}
}
\ No newline at end of file
From d7543bbc34aa6fc8e2224bef86bb79cb54d17e8c Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sat, 7 Jun 2014 14:07:39 -0500
Subject: [PATCH 396/629] Ported FlagViewsRelationship. Maybe it even works\!
---
flag.views.inc | 7 ++--
.../relationship/FlagViewsRelationship.php | 34 ++++++++++++++++---
2 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/flag.views.inc b/flag.views.inc
index 7488d59..9775e38 100644
--- a/flag.views.inc
+++ b/flag.views.inc
@@ -11,7 +11,7 @@ function flag_views_data() {
$data['flagging']['table']['group'] = t('Flag');
$data['flagging']['table']['join'] = array(
'node' => array(
- 'type' => 'INNER',
+ 'type' => 'LEFT',
'left_field' => 'nid',
'field' => 'entity_id',
),
@@ -39,11 +39,10 @@ function flag_views_data() {
);
$data['flagging']['created'] = array(
- 'title' => t('Flagged time'),
- 'help' => t('Display the time the content was flagged by a user.'),
+ 'title' => t('Last Flagged Time'),
+ 'help' => t('Display latest time the content was flagged by a user.'),
'field' => array(
'id' => 'date',
- //'click sortable' => TRUE,
),
'sort' => array(
'id' => 'date',
diff --git a/src/Plugin/views/relationship/FlagViewsRelationship.php b/src/Plugin/views/relationship/FlagViewsRelationship.php
index 18a6831..bd495ae 100644
--- a/src/Plugin/views/relationship/FlagViewsRelationship.php
+++ b/src/Plugin/views/relationship/FlagViewsRelationship.php
@@ -27,7 +27,7 @@ public function defineOptions() {
public function buildOptionsForm(&$form, &$form_state) {
$entity_type = $this->definition['flaggable'];
- $form['label']['#description'] .= ' ' . t('The name of the selected flag makes a good label.');
+ //$form['label']['#description'] .= ' ' . t('The name of the selected flag makes a good label.');
/*//////////////////////////////////////////////////////////////////////////
@todo Add Flag selection form
@@ -78,12 +78,38 @@ public function query() {
return;
}
- parent::query();
+ $this->definition['extra'][] = array(
+ 'field' => 'fid',
+ 'value' => $flag->id,
+ 'numeric' => TRUE,
+ );
+
+ if ($this->definition['user_scope'] == 'current' && !$flag->isGlobal()) {
+ $this->definition['extra'][] = array(
+ 'field' => 'uid',
+ 'value' => '***CURRENT_USER***',
+ 'numeric' => TRUE,
+ );
+ $flag_roles = user_roles(FALSE, "flag $flag->name");
+ if (isset($flag_roles[DRUPAL_ANONYMOUS_RID])) {
+ // Disable page caching for anonymous users.
+ drupal_page_is_cacheable(FALSE);
+
+ // Add in the SID from Session API for anonymous users.
+ $this->definition['extra'][] = array(
+ 'field' => 'sid',
+ 'value' => '***FLAG_CURRENT_USER_SID***',
+ 'numeric' => TRUE,
+ );
+ }
+ }
+
+// parent::query();
}
protected function getFlag() {
- $flaggable = $this->options['flaggable'];
- $this->options['flag'] = \Drupal::service('flag')->getFlag($flaggable);
+ $flaggable = $this->definition['flaggable'];
+ $this->options['flag'] = \Drupal::service('flag')->getFlags($flaggable);
}
}
\ No newline at end of file
From a6f39adc21c632406b2d7709ac6e75a44fdf116d Mon Sep 17 00:00:00 2001
From: Fernando Paredes Garcia
Date: Sat, 7 Jun 2014 16:09:26 -0500
Subject: [PATCH 397/629] #5 Remove Import/export functionality.
---
flag.api.php | 12 ----
flag.module | 5 --
flag.routing.yml | 16 ------
src/Form/FlagExportForm.php | 78 --------------------------
src/Form/FlagImportForm.php | 108 ------------------------------------
5 files changed, 219 deletions(-)
delete mode 100644 src/Form/FlagExportForm.php
delete mode 100644 src/Form/FlagImportForm.php
diff --git a/flag.api.php b/flag.api.php
index 88aef7a..9eaea26 100644
--- a/flag.api.php
+++ b/flag.api.php
@@ -360,15 +360,3 @@ function hook_flag_reset($flag, $entity_id, $rows) {
function hook_flag_javascript_info_alter() {
}
-
-/**
- * Alter a flag object that is being prepared for exporting.
- *
- * @param $flag
- * The flag object.
- *
- * @see flag_export_flags()
- */
-function hook_flag_export_alter($flag) {
-
-}
diff --git a/flag.module b/flag.module
index d65bdc3..009bb16 100644
--- a/flag.module
+++ b/flag.module
@@ -283,11 +283,6 @@ function flag_permission() {
'title' => t('Administer flags'),
'description' => t('Create and edit site-wide flags.'),
),
- 'use flag import' => array(
- 'title' => t('Use flag importer'),
- 'description' => t('Access the flag import functionality.'),
- 'restrict access' => TRUE,
- ),
);
$flags = \Drupal::service('flag')->getFlags();
diff --git a/flag.routing.yml b/flag.routing.yml
index 01c585c..a259e8c 100644
--- a/flag.routing.yml
+++ b/flag.routing.yml
@@ -38,22 +38,6 @@ flag.delete:
requirements:
_entity_access: 'flag_flag.update'
-flag.import:
- path: '/admin/structure/flags/import'
- defaults:
- _form: '\Drupal\flag\Form\FlagImportForm'
- _title: 'Import Flags'
- requirements:
- _permission: 'use flag import'
-
-flag.export:
- path: '/admin/structure/flags/export'
- defaults:
- _form: '\Drupal\flag\Form\FlagExportForm'
- _title: 'Export Flags'
- requirements:
- _permission: 'use flag import'
-
flag_link_flag.html:
path: '/flag/flag/{flag_id}/{entity_id}'
defaults:
diff --git a/src/Form/FlagExportForm.php b/src/Form/FlagExportForm.php
deleted file mode 100644
index 93acc6b..0000000
--- a/src/Form/FlagExportForm.php
+++ /dev/null
@@ -1,78 +0,0 @@
- 'checkboxes',
- '#title' => t('Flags to export'),
- '#options' => drupal_map_assoc(array_keys(flag_get_flags())),
- '#description' => t('Exporting your flags is useful for moving flags from one site to another, or when including your flag definitions in a module.'),
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Export'),
- );
- }
- }
-
- // @todo: Move to another controller
- if (isset($flags)) {
- $code = flag_export_flags($flags);
-
- // Link to the Features page if module is present, otherwise link to the
- // Drupal project page.
- $features_link = module_exists('features') ? url('admin/build/features') : url('http://drupal.org/project/features');
-
- $form['export'] = array(
- '#type' => 'textarea',
- '#title' => t('Flag exports'),
- '#description' => t('Use the exported code to later import it. Exports can be included in modules using hook_flag_default_flags() or using the Features module.', array('@import-flag' => url(FLAG_ADMIN_PATH . '/import'), '@features-url' => $features_link)),
- '#value' => $code,
- '#rows' => 15,
- );
- }
-
- return $form;
-
- }
-
- public function submitForm(array &$form, array &$form_state) {
- $form_state['rebuild'] = TRUE;
- }
-
-}
\ No newline at end of file
diff --git a/src/Form/FlagImportForm.php b/src/Form/FlagImportForm.php
deleted file mode 100644
index 3b20956..0000000
--- a/src/Form/FlagImportForm.php
+++ /dev/null
@@ -1,108 +0,0 @@
- t('Flag import code'),
- '#type' => 'textarea',
- '#default_value' => '',
- '#rows' => 15,
- '#required' => TRUE,
- '#description' => t('Paste the code from a flag export here to import it into you site. Flags imported with the same name will update existing flags. Flags with a new name will be created.', array('@export-url' => url(FLAG_ADMIN_PATH . '/export'))),
- );
- $form['submit'] = array(
- '#value' => t('Import'),
- '#type' => 'submit',
- );
-
- return $form;
- }
-
- public function validateForm(array &$form, array &$form_state) {
- $flags = array();
- ob_start();
- eval($form_state['values']['import']);
- ob_end_clean();
-
- if (!isset($flags) || !is_array($flags)) {
- form_set_error('import', t('A valid list of flags could not be found in the import code.'));
- return;
- }
-
- // Create the flag object.
- foreach ($flags as $flag_name => $flag_info) {
- // Backward compatibility: old exported flags have their names in $flag_info
- // instead, so we use the += operator to not overwrite it.
- $flag_info += array(
- 'name' => $flag_name,
- );
- $new_flag = AbstractFlag::factory_by_array($flag_info);
-
- // Give new flags with the same name a matching FID, which tells Flag to
- // update the existing flag, rather than creating a new one.
- if ($existing_flag = flag_get_flag($new_flag->name)) {
- $new_flag->fid = $existing_flag->fid;
- }
-
- if ($errors = $new_flag->validate()) {
- $message = t('The import of the %flag flag failed because the following errors were encountered during the import:', array('%flag' => $new_flag->name));
- $message_errors = array();
- foreach ($errors as $field => $field_errors) {
- foreach ($field_errors as $error) {
- $message_errors[] = $error['message'];
- }
- }
- form_set_error('import', $message . theme('item_list', array('items' => $message_errors)));
- }
- else {
- // Save the new flag for the submit handler.
- $form_state['flags'][] = $new_flag;
- }
- }
- }
-
- public function submitForm(array &$form, array &$form_state) {
- module_load_include('inc', 'flag', 'includes/flag.admin');
-
- // Build up values for the cache clear.
- $entity_types = array();
- $new = FALSE;
-
- foreach ($form_state['flags'] as $flag) {
- $flag->save();
- if (!empty($flag->status)) {
- $flag->enable();
- }
- if ($flag->is_new) {
- drupal_set_message(t('Flag @name has been imported.', array('@name' => $flag->name)));
- $new = TRUE;
- }
- else {
- drupal_set_message(t('Flag @name has been updated.', array('@name' => $flag->name)));
- }
- $entity_types[] = $flag->entity_type;
- }
- _flag_clear_cache($entity_types, $new);
-
- $form_state['redirect'] = FLAG_ADMIN_PATH;
- }
-
-}
\ No newline at end of file
From 95d0176d792622784e70e38af2ee3a55ab408637 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sat, 7 Jun 2014 16:31:47 -0500
Subject: [PATCH 398/629] Working flag views relationship and link field.
---
flag.views.inc | 11 ++++----
src/Plugin/views/field/FlagViewsLinkField.php | 28 +++++++++++++++----
.../relationship/FlagViewsRelationship.php | 8 ++++--
3 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/flag.views.inc b/flag.views.inc
index 9775e38..9910896 100644
--- a/flag.views.inc
+++ b/flag.views.inc
@@ -63,15 +63,14 @@ function flag_views_data() {
),
);
-/*
// Flag content links.
- $data['flagging']['ops'] = array(
- 'title' => t('Flag link'),
- 'help' => t('Display flag/unflag link.'),
+ $data['flagging']['link_flag'] = array(
'field' => array(
- 'handler' => 'flag_handler_field_ops',
+ 'title' => t('Flag Links'),
+ 'help' => t('Display flag/unflag link.'),
+ 'id' => 'flag_link',
),
- );*/
+ );
return $data;
}
diff --git a/src/Plugin/views/field/FlagViewsLinkField.php b/src/Plugin/views/field/FlagViewsLinkField.php
index 74e7913..182f71d 100644
--- a/src/Plugin/views/field/FlagViewsLinkField.php
+++ b/src/Plugin/views/field/FlagViewsLinkField.php
@@ -60,24 +60,40 @@ public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
}
+ public function query() {
+ // Intentionally do nothing here since we're only providing a link and not
+ // querying against a real table column.
+ }
+
/**
* @param ResultRow $values
* @return string|void
*/
public function render(ResultRow $values) {
- $comment = $this->getEntity($values);
- return $this->renderLink($comment, $values);
+ //$entity = $this->getEntity($values);
+ return $this->renderLink($values->_entity, $values);
}
/**
* @param $data
* @param ResultRow $values
*/
- protected function renderLink($data, ResultRow $values) {
- if ($node->access('view')) {
- $text = !empty($this->options['text']) ? $this->options['text'] : t('View');
- return $text;
+ protected function renderLink($entity, ResultRow $values) {
+ if (empty($entity)) { // || !$entity->access('view')) {
+ return t('N/A');
}
+
+ $flag = $this->getFlag();
+ $linkTypePlugin = $flag->getLinkTypePlugin();
+ $action = 'flag';
+
+ if ($flag->isFlagged($entity)) {
+ $action = 'unflag';
+ }
+
+ $link = $linkTypePlugin->renderLink($action, $flag, $entity);
+
+ return $link;
}
}
\ No newline at end of file
diff --git a/src/Plugin/views/relationship/FlagViewsRelationship.php b/src/Plugin/views/relationship/FlagViewsRelationship.php
index bd495ae..6ff8cd3 100644
--- a/src/Plugin/views/relationship/FlagViewsRelationship.php
+++ b/src/Plugin/views/relationship/FlagViewsRelationship.php
@@ -84,7 +84,7 @@ public function query() {
'numeric' => TRUE,
);
- if ($this->definition['user_scope'] == 'current' && !$flag->isGlobal()) {
+ if ($this->options['user_scope'] == 'current' && !$flag->isGlobal()) {
$this->definition['extra'][] = array(
'field' => 'uid',
'value' => '***CURRENT_USER***',
@@ -108,8 +108,10 @@ public function query() {
}
- protected function getFlag() {
+ public function getFlag() {
$flaggable = $this->definition['flaggable'];
- $this->options['flag'] = \Drupal::service('flag')->getFlags($flaggable);
+ $flag = \Drupal::service('flag')->getFlags($flaggable);
+ $this->options['flag'] = $flag;
+ return current($flag);
}
}
\ No newline at end of file
From d90a60550670af15c3c9f755acabbc9b1cba1497 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sat, 7 Jun 2014 17:59:59 -0500
Subject: [PATCH 399/629] Additional non-working flag view handlers.
---
flag.views.inc | 21 +++++++++
.../views/field/FlagViewsFlaggedField.php | 44 +++++++++++++++++
.../views/sort/FlagViewsSortFlagged.php | 47 +++++++++++++++++++
3 files changed, 112 insertions(+)
create mode 100644 src/Plugin/views/field/FlagViewsFlaggedField.php
create mode 100644 src/Plugin/views/sort/FlagViewsSortFlagged.php
diff --git a/flag.views.inc b/flag.views.inc
index 9910896..dcb5860 100644
--- a/flag.views.inc
+++ b/flag.views.inc
@@ -72,6 +72,27 @@ function flag_views_data() {
),
);
+ // Specialized is null/is not null filter.
+ $data['flagging']['flagged'] = array(
+ 'title' => t('Flagged'),
+ 'real field' => 'uid',
+ 'field' => array(
+ 'id' => 'flag_flagged',
+ 'label' => t('Flagged'),
+ 'help' => t('A boolean field to show whether the flag is set or not.'),
+ ), /*
+ 'filter' => array(
+ 'handler' => 'flag_handler_filter_flagged',
+ 'label' => t('Flagged'),
+ 'help' => t('Filter to ensure content has or has not been flagged.'),
+ ),*/
+ 'sort' => array(
+ 'id' => 'flag_sort',
+ 'label' => t('Flagged'),
+ 'help' => t('Sort by whether entities have or have not been flagged.'),
+ ),
+ );
+
return $data;
}
diff --git a/src/Plugin/views/field/FlagViewsFlaggedField.php b/src/Plugin/views/field/FlagViewsFlaggedField.php
new file mode 100644
index 0000000..0056aa4
--- /dev/null
+++ b/src/Plugin/views/field/FlagViewsFlaggedField.php
@@ -0,0 +1,44 @@
+ 1);
+ return $options;
+ }
+
+ public function buildOptionsForm(&$form, &$form_state) {
+ parent::buildOptionsForm($form, $form_state);
+ $form['value']['#type'] = 'radios';
+ $form['value']['#title'] = t('Status');
+ $form['value']['#options'] = array(
+ 1 => t('Flagged'),
+ 0 => t('Not flagged'),
+ 'All' => t('All'),
+ );
+ $form['value']['#default_value'] = empty($this->options['value']) ? '0' : $this->options['value'];
+ $form['value']['#description'] = '' . t('This filter is only needed if the relationship used has the "Include only flagged content" option unchecked. Otherwise, this filter is useless, because all records are already limited to flagged content.') . '
' . t('By choosing Not flagged, it is possible to create a list of content that is specifically not flagged.', array('@unflagged-url' => 'http://drupal.org/node/299335')) . '
';
+ }
+
+ public function query() {
+ $operator = $this->value ? 'IS NOT' : 'IS';
+ $this->query->addWhere($this->options['group'], $this->relationship . '.uid', NULL, $operator . ' NULL');
+ }
+}
\ No newline at end of file
diff --git a/src/Plugin/views/sort/FlagViewsSortFlagged.php b/src/Plugin/views/sort/FlagViewsSortFlagged.php
new file mode 100644
index 0000000..2b763c1
--- /dev/null
+++ b/src/Plugin/views/sort/FlagViewsSortFlagged.php
@@ -0,0 +1,47 @@
+ t('Unflagged first'),
+ 'DESC' => t('Flagged first'),
+ );
+ }
+
+ /**
+ * Display whether or not the sort order is ascending or descending
+ */
+ function adminSummary() {
+ if (!empty($this->options['exposed'])) {
+ return t('Exposed');
+ }
+
+ // Get the labels defined in sortOptions().
+ $sort_options = $this->sortOptions();
+ return $sort_options[strtoupper($this->options['order'])];
+ }
+
+ public function query() {
+ $this->ensureMyTable();
+
+ $this->query->addOrderBy(NULL, "($this->tableAlias.uid IS NOT NULL)", $this->options['order']);
+ }
+}
\ No newline at end of file
From 91d7d8fee3aecd8e2e5708f82d346aa8f0486180 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 8 Jun 2014 13:42:09 -0500
Subject: [PATCH 400/629] Working views flagged field.
---
flag.views.inc | 176 ++++--------------
.../views/field/FlagViewsFlaggedField.php | 30 +--
2 files changed, 47 insertions(+), 159 deletions(-)
diff --git a/flag.views.inc b/flag.views.inc
index dcb5860..54068a0 100644
--- a/flag.views.inc
+++ b/flag.views.inc
@@ -9,6 +9,8 @@
function flag_views_data() {
$data = array();
$data['flagging']['table']['group'] = t('Flag');
+ $data['flag_counts']['table']['group'] = t('Flaggings');
+
$data['flagging']['table']['join'] = array(
'node' => array(
'type' => 'LEFT',
@@ -93,6 +95,42 @@ function flag_views_data() {
),
);
+ $data['flag_counts']['count'] = array(
+ 'title' => t('Flag counter'),
+ 'help' => t('The number of times a piece of content is flagged by any user.'),
+ 'field' => array(
+ 'id' => 'numeric',
+// 'click sortable' => TRUE,
+ ),
+ /*'sort' => array(
+ 'id' => 'groupby_numeric',
+ ),
+ 'filter' => array(
+ 'id' => 'numeric',
+ ),
+ 'argument' => array(
+ 'id' => 'numeric',
+ ),*/
+ );
+
+ $data['flag_counts']['last_updated'] = array(
+ 'title' => t('Time last flagged'),
+ 'help' => t('The time a piece of content was most recently flagged by any user.'),
+ 'field' => array(
+ 'id' => 'date',
+ //'click sortable' => TRUE,
+ ),
+ /*'sort' => array(
+ 'id' => 'date',
+ ),
+ 'filter' => array(
+ 'id' => 'date',
+ ),
+ 'argument' => array(
+ 'id' => 'date',
+ ),*/
+ );
+
return $data;
}
@@ -127,141 +165,3 @@ function flag_views_data_alter(&$data) {
}
}
-
-
-/*
-function flag_views_data() {
- $data = array();
-
-
-
-
- $data['flagging']['table']['group'] = t('Flags');
- $data['flagging']['table']['base'] = array(
- 'field' => 'id',
- 'title' => t('Flag Id'),
- 'help' => t('The flagging Id.'),
- );
- $data['flagging']['table']['entity type'] = 'flagging';
-
-// $data['flag_counts']['table']['group'] = t('Flags');
-
- $data['flagging']['uid'] = array(
- 'title' => t('User uid'),
- 'help' => t('The user that flagged an item. If you need more fields than the uid add the "Flags: User" relationship.'),
- 'relationship' => array(
- 'title' => t('User'),
- 'help' => t('Relate an item to the user that flagged it.'),
- 'id' => 'standard',
- 'base' => 'users',
- 'field' => uid,
- 'label' => t('Flag user'),
- ),
-/* 'filter' => array(
- 'handler' => 'views_handler_filter_user_name',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_numeric',
- ),
- 'field' => array(
- 'handler' => 'views_handler_field_user',
- ),
- );
-
- $data['flagging']['timestamp'] = array(
- 'title' => t('Flagged time'),
- 'help' => t('Display the time the content was flagged by a user.'),
- 'field' => array(
- 'handler' => 'views_handler_field_date',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'id' => 'date',
- ),
- 'filter' => array(
- 'id' => 'date',
- ),
-// 'argument' => array(
-// 'handler' => 'views_handler_argument_date',
-// ),
- );
-/*
- // Argument for content ID, used for "Who's flagged this" views.
- $data['flagging']['entity_id'] = array(
- 'title' => t('Content ID'),
- 'help' => t('The unique ID of the object that has been flagged.'),
- 'argument' => array(
- 'handler' => 'flag_handler_argument_entity_id',
- ),
- );
-
- // Specialized is null/is not null filter.
- $data['flagging']['flagged'] = array(
- 'title' => t('Flagged'),
- 'real field' => 'uid',
- 'field' => array(
- 'handler' => 'flag_handler_field_flagged',
- 'label' => t('Flagged'),
- 'help' => t('A boolean field to show whether the flag is set or not.'),
- ),
- 'filter' => array(
- 'handler' => 'flag_handler_filter_flagged',
- 'label' => t('Flagged'),
- 'help' => t('Filter to ensure content has or has not been flagged.'),
- ),
- 'sort' => array(
- 'handler' => 'flag_handler_sort_flagged',
- 'label' => t('Flagged'),
- 'help' => t('Sort by whether entities have or have not been flagged.'),
- ),
- );
-
- // Flag content links.
- $data['flagging']['ops'] = array(
- 'title' => t('Flag link'),
- 'help' => t('Display flag/unflag link.'),
- 'field' => array(
- 'handler' => 'flag_handler_field_ops',
- ),
- );
-
- $data['flag_counts']['count'] = array(
- 'title' => t('Flag counter'),
- 'help' => t('The number of times a piece of content is flagged by any user.'),
- 'field' => array(
- 'handler' => 'views_handler_field_numeric',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_numeric',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_numeric',
- ),
- );
-
- $data['flag_counts']['last_updated'] = array(
- 'title' => t('Time last flagged'),
- 'help' => t('The time a piece of content was most recently flagged by any user.'),
- 'field' => array(
- 'handler' => 'views_handler_field_date',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort_date',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_date',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_date',
- ),
- );
-
- return $data;
-}
-
-*/
\ No newline at end of file
diff --git a/src/Plugin/views/field/FlagViewsFlaggedField.php b/src/Plugin/views/field/FlagViewsFlaggedField.php
index 0056aa4..eb267c5 100644
--- a/src/Plugin/views/field/FlagViewsFlaggedField.php
+++ b/src/Plugin/views/field/FlagViewsFlaggedField.php
@@ -8,6 +8,8 @@
namespace Drupal\flag\Plugin\views\field;
+use Drupal\views\ViewExecutable;
+use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\Boolean;
/**
@@ -18,27 +20,13 @@
*/
class FlagViewsFlaggedField extends Boolean {
- public function defineOptions() {
- $options = parent::defineOptions();
- $options['value'] = array('default' => 1);
- return $options;
- }
-
- public function buildOptionsForm(&$form, &$form_state) {
- parent::buildOptionsForm($form, $form_state);
- $form['value']['#type'] = 'radios';
- $form['value']['#title'] = t('Status');
- $form['value']['#options'] = array(
- 1 => t('Flagged'),
- 0 => t('Not flagged'),
- 'All' => t('All'),
- );
- $form['value']['#default_value'] = empty($this->options['value']) ? '0' : $this->options['value'];
- $form['value']['#description'] = '' . t('This filter is only needed if the relationship used has the "Include only flagged content" option unchecked. Otherwise, this filter is useless, because all records are already limited to flagged content.') . '
' . t('By choosing Not flagged, it is possible to create a list of content that is specifically not flagged.', array('@unflagged-url' => 'http://drupal.org/node/299335')) . '
';
- }
+ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
+ parent::init($view, $display, $options);
- public function query() {
- $operator = $this->value ? 'IS NOT' : 'IS';
- $this->query->addWhere($this->options['group'], $this->relationship . '.uid', NULL, $operator . ' NULL');
+ // Add our boolean labels.
+ $this->formats['flag'] = array(t('Flagged'), t('Not flagged'));
+ // TODO: We could probably lift the '(Un)Flagged message' strings from the
+ // flag object, but a) we need to lift that from the relationship we're on
+ // and b) they will not necessarily make sense in a static context.
}
}
\ No newline at end of file
From f5f28f4f115ab9ac5cb345264043a0ea8f08d1c4 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 8 Jun 2014 14:28:10 -0500
Subject: [PATCH 401/629] Working flag views sort handler.
---
flag.views.inc | 8 ++++----
src/Plugin/views/relationship/FlagViewsRelationship.php | 2 +-
src/Plugin/views/sort/FlagViewsSortFlagged.php | 6 ++++--
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/flag.views.inc b/flag.views.inc
index 54068a0..d61fdbe 100644
--- a/flag.views.inc
+++ b/flag.views.inc
@@ -82,12 +82,12 @@ function flag_views_data() {
'id' => 'flag_flagged',
'label' => t('Flagged'),
'help' => t('A boolean field to show whether the flag is set or not.'),
- ), /*
- 'filter' => array(
- 'handler' => 'flag_handler_filter_flagged',
+ ),
+ 'id' => array(
+ 'handler' => 'flag_filter',
'label' => t('Flagged'),
'help' => t('Filter to ensure content has or has not been flagged.'),
- ),*/
+ ),
'sort' => array(
'id' => 'flag_sort',
'label' => t('Flagged'),
diff --git a/src/Plugin/views/relationship/FlagViewsRelationship.php b/src/Plugin/views/relationship/FlagViewsRelationship.php
index 6ff8cd3..05e4d28 100644
--- a/src/Plugin/views/relationship/FlagViewsRelationship.php
+++ b/src/Plugin/views/relationship/FlagViewsRelationship.php
@@ -90,7 +90,7 @@ public function query() {
'value' => '***CURRENT_USER***',
'numeric' => TRUE,
);
- $flag_roles = user_roles(FALSE, "flag $flag->name");
+ $flag_roles = user_roles(FALSE, "flag $flag->label");
if (isset($flag_roles[DRUPAL_ANONYMOUS_RID])) {
// Disable page caching for anonymous users.
drupal_page_is_cacheable(FALSE);
diff --git a/src/Plugin/views/sort/FlagViewsSortFlagged.php b/src/Plugin/views/sort/FlagViewsSortFlagged.php
index 2b763c1..5253a28 100644
--- a/src/Plugin/views/sort/FlagViewsSortFlagged.php
+++ b/src/Plugin/views/sort/FlagViewsSortFlagged.php
@@ -5,6 +5,8 @@
* Contains the flagged content sort handler.
*/
+namespace Drupal\flag\Plugin\views\sort;
+
use Drupal\views\Plugin\views\sort\SortPluginBase;
/**
@@ -12,7 +14,7 @@
*
* @ViewsSort("flag_sort")
*/
-class FlagViewsSortFlagged extends SortPluginBase {
+class FlagViewsSortFlagged extends SortPluginBase {
/**
* Provide a list of options for the default sort form.
@@ -42,6 +44,6 @@ function adminSummary() {
public function query() {
$this->ensureMyTable();
- $this->query->addOrderBy(NULL, "($this->tableAlias.uid IS NOT NULL)", $this->options['order']);
+ $this->query->addOrderBy(NULL, "$this->tableAlias.uid", $this->options['order']);
}
}
\ No newline at end of file
From d973c0cd6d3274cc42f50b742908da01fe4b983b Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 8 Jun 2014 15:30:37 -0500
Subject: [PATCH 402/629] Working flag views filter.
---
flag.views.inc | 4 +-
src/Plugin/views/filter/FlagViewsFilter.php | 47 +++++++++++++++++++++
2 files changed, 49 insertions(+), 2 deletions(-)
create mode 100644 src/Plugin/views/filter/FlagViewsFilter.php
diff --git a/flag.views.inc b/flag.views.inc
index d61fdbe..e1adf4f 100644
--- a/flag.views.inc
+++ b/flag.views.inc
@@ -83,8 +83,8 @@ function flag_views_data() {
'label' => t('Flagged'),
'help' => t('A boolean field to show whether the flag is set or not.'),
),
- 'id' => array(
- 'handler' => 'flag_filter',
+ 'filter' => array(
+ 'id' => 'flag_filter',
'label' => t('Flagged'),
'help' => t('Filter to ensure content has or has not been flagged.'),
),
diff --git a/src/Plugin/views/filter/FlagViewsFilter.php b/src/Plugin/views/filter/FlagViewsFilter.php
new file mode 100644
index 0000000..c3fb36c
--- /dev/null
+++ b/src/Plugin/views/filter/FlagViewsFilter.php
@@ -0,0 +1,47 @@
+ 1);
+ return $options;
+ }
+
+ public function buildOptionsForm(&$form, &$form_state) {
+ parent::buildOptionsForm($form, $form_state);
+ $form['value']['#type'] = 'radios';
+ $form['value']['#title'] = t('Status');
+ $form['value']['#options'] = array(
+ 1 => t('Flagged'),
+ 0 => t('Not flagged'),
+ // @todo Find out what in the hell filter type ALL is supposed to do.
+ //'All' => t('All'),
+ );
+ $form['value']['#default_value'] = empty($this->options['value']) ? '0' : $this->options['value'];
+ $form['value']['#description'] = '' . t('This filter is only needed if the relationship used has the "Include only flagged content" option unchecked. Otherwise, this filter is useless, because all records are already limited to flagged content.') . '
' . t('By choosing Not flagged, it is possible to create a list of content that is specifically not flagged.', array('@unflagged-url' => 'http://drupal.org/node/299335')) . '
';
+ }
+
+
+ public function query() {
+ $this->ensureMyTable();
+
+ $operator = $this->options['value'] ? 'IS NOT' : 'IS';
+ $operator .= ' NULL';
+
+ $this->query->addWhere($this->options['group'], "$this->tableAlias.uid", NULL, $operator);
+ }
+}
\ No newline at end of file
From 67ea08182098913165e1c728dae5f8cc9ccbaca1 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 8 Jun 2014 15:53:57 -0500
Subject: [PATCH 403/629] PSR-4 for flag_bookmark.
---
.../config/install/flag_bookmark.flag_flag.bookmark.yml | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename flag_bookmark/{lib/Drupal/flag_bookmark => src}/config/install/flag_bookmark.flag_flag.bookmark.yml (100%)
diff --git a/flag_bookmark/lib/Drupal/flag_bookmark/config/install/flag_bookmark.flag_flag.bookmark.yml b/flag_bookmark/src/config/install/flag_bookmark.flag_flag.bookmark.yml
similarity index 100%
rename from flag_bookmark/lib/Drupal/flag_bookmark/config/install/flag_bookmark.flag_flag.bookmark.yml
rename to flag_bookmark/src/config/install/flag_bookmark.flag_flag.bookmark.yml
From 7693590b31f7374d56e253d790ed3fc01382d1ad Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 8 Jun 2014 15:58:53 -0500
Subject: [PATCH 404/629] Added default flag_bookmark view.
---
.../flag_bookmark.view.flag_bookmark.yml | 500 ++++++++++++++++++
1 file changed, 500 insertions(+)
create mode 100644 flag_bookmark/src/config/install/flag_bookmark.view.flag_bookmark.yml
diff --git a/flag_bookmark/src/config/install/flag_bookmark.view.flag_bookmark.yml b/flag_bookmark/src/config/install/flag_bookmark.view.flag_bookmark.yml
new file mode 100644
index 0000000..f97277d
--- /dev/null
+++ b/flag_bookmark/src/config/install/flag_bookmark.view.flag_bookmark.yml
@@ -0,0 +1,500 @@
+base_field: nid
+base_table: node
+core: 8.x
+description: ''
+status: true
+display:
+ default:
+ display_plugin: default
+ id: default
+ display_title: Master
+ position: 0
+ provider: views
+ display_options:
+ access:
+ type: perm
+ options:
+ perm: 'access content'
+ provider: user
+ dependencies: { }
+ cache:
+ type: none
+ options: { }
+ provider: views
+ dependencies: { }
+ query:
+ type: views_query
+ options:
+ disable_sql_rewrite: false
+ distinct: false
+ slave: false
+ query_comment: false
+ query_tags: { }
+ provider: views
+ dependencies: { }
+ exposed_form:
+ type: basic
+ options:
+ submit_button: Apply
+ reset_button: false
+ reset_button_label: Reset
+ exposed_sorts_label: 'Sort by'
+ expose_sort_order: true
+ sort_asc_label: Asc
+ sort_desc_label: Desc
+ provider: views
+ dependencies: { }
+ pager:
+ type: full
+ options:
+ items_per_page: 25
+ offset: 0
+ id: 0
+ total_pages: null
+ tags:
+ previous: '‹ previous'
+ next: 'next ›'
+ first: '« first'
+ last: 'last »'
+ expose:
+ items_per_page: false
+ items_per_page_label: 'Items per page'
+ items_per_page_options: '5, 10, 20, 40, 60'
+ items_per_page_options_all: false
+ items_per_page_options_all_label: '- All -'
+ offset: false
+ offset_label: Offset
+ quantity: 9
+ style:
+ type: table
+ options:
+ grouping: { }
+ row_class: ''
+ default_row_class: true
+ override: true
+ sticky: false
+ caption: ''
+ summary: ''
+ description: ''
+ columns:
+ title: title
+ created: created
+ changed: changed
+ created_1: created_1
+ info:
+ title:
+ sortable: false
+ default_sort_order: asc
+ align: ''
+ separator: ''
+ empty_column: false
+ responsive: ''
+ created:
+ sortable: false
+ default_sort_order: asc
+ align: ''
+ separator: ''
+ empty_column: false
+ responsive: ''
+ changed:
+ sortable: false
+ default_sort_order: asc
+ align: ''
+ separator: ''
+ empty_column: false
+ responsive: ''
+ created_1:
+ sortable: false
+ default_sort_order: asc
+ align: ''
+ separator: ''
+ empty_column: false
+ responsive: ''
+ default: '-1'
+ empty_table: false
+ row:
+ type: fields
+ fields:
+ type:
+ id: type
+ table: node_field_data
+ field: type
+ relationship: none
+ group_type: group
+ admin_label: ''
+ dependencies:
+ module:
+ - node
+ label: Type
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: ''
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ link_to_node: false
+ machine_name: '0'
+ plugin_id: node_type
+ provider: node
+ title:
+ id: title
+ table: node_field_data
+ field: title
+ provider: node
+ alter:
+ alter_text: false
+ make_link: false
+ absolute: false
+ trim: false
+ word_boundary: false
+ ellipsis: false
+ strip_tags: false
+ html: false
+ hide_empty: false
+ empty_zero: false
+ link_to_node: 1
+ relationship: none
+ group_type: group
+ admin_label: ''
+ dependencies: { }
+ label: Title
+ exclude: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_alter_empty: true
+ name:
+ id: name
+ table: users
+ field: name
+ relationship: uid
+ group_type: group
+ admin_label: ''
+ dependencies:
+ module:
+ - user
+ label: Author
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: ''
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ link_to_user: true
+ overwrite_anonymous: false
+ anonymous_text: ''
+ format_username: true
+ plugin_id: user_name
+ provider: user
+ comment_count:
+ id: comment_count
+ table: comment_entity_statistics
+ field: comment_count
+ relationship: none
+ group_type: group
+ admin_label: ''
+ dependencies:
+ module:
+ - views
+ - views
+ - views
+ label: Replies
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: ''
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: '0'
+ hide_empty: false
+ empty_zero: true
+ hide_alter_empty: false
+ set_precision: false
+ precision: 0
+ decimal: .
+ separator: ','
+ format_plural: false
+ format_plural_singular: '1'
+ format_plural_plural: '@count'
+ prefix: ''
+ suffix: ''
+ plugin_id: numeric
+ provider: views
+ link_flag:
+ id: link_flag
+ table: flagging
+ field: link_flag
+ relationship: flag_content_rel
+ group_type: group
+ admin_label: ''
+ dependencies:
+ module:
+ - flag
+ - flag
+ label: Ops
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: ''
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ text: ''
+ plugin_id: flag_link
+ provider: flag
+ filters:
+ status:
+ value: true
+ table: node_field_data
+ field: status
+ provider: node
+ id: status
+ expose:
+ operator: ''
+ group: 1
+ flagged:
+ id: flagged
+ table: flagging
+ field: flagged
+ relationship: flag_content_rel
+ group_type: group
+ admin_label: ''
+ dependencies:
+ module:
+ - flag
+ - flag
+ - flag
+ - flag
+ - flag
+ - flag
+ - flag
+ - flag
+ - flag
+ operator: '='
+ value: '1'
+ group: 1
+ exposed: false
+ expose:
+ operator_id: ''
+ label: ''
+ description: ''
+ use_operator: false
+ operator: ''
+ identifier: ''
+ required: false
+ remember: false
+ multiple: false
+ remember_roles:
+ authenticated: authenticated
+ is_grouped: false
+ group_info:
+ label: ''
+ description: ''
+ identifier: ''
+ optional: true
+ widget: select
+ multiple: false
+ remember: false
+ default_group: All
+ default_group_multiple: { }
+ group_items: { }
+ plugin_id: flag_filter
+ provider: flag
+ sorts: { }
+ title: 'My Bookmarks'
+ header: { }
+ footer: { }
+ empty: { }
+ relationships:
+ flag_content_rel:
+ id: flag_content_rel
+ table: node_field_data
+ field: flag_content_rel
+ relationship: none
+ group_type: group
+ admin_label: Flags
+ dependencies:
+ module:
+ - flag
+ - flag
+ required: false
+ flag: 'Stuff! custom'
+ user_scope: current
+ plugin_id: flag_relationship
+ provider: flag
+ uid:
+ id: uid
+ table: node_field_data
+ field: uid
+ relationship: none
+ group_type: group
+ admin_label: author
+ dependencies:
+ module:
+ - views
+ required: true
+ plugin_id: standard
+ provider: views
+ arguments: { }
+ page_1:
+ display_plugin: page
+ id: page_1
+ display_title: Page
+ position: 1
+ provider: views
+ display_options:
+ path: bookmarks
+ menu:
+ type: normal
+ title: 'My Bookmarks'
+ description: ''
+ name: main
+ weight: 0
+ context: '0'
+label: flag_bookmark
+module: views
+id: flag_bookmark
+tag: ''
+langcode: en
+dependencies:
+ module:
+ - flag
+ - node
+ - user
From 45e2b240c7d9068bc6739ee6337469e444a62c4a Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 8 Jun 2014 15:59:51 -0500
Subject: [PATCH 405/629] Removed flag_bookmark.views_default.inc
---
.../includes/flag_bookmark.views_default.inc | 284 ------------------
1 file changed, 284 deletions(-)
delete mode 100644 flag_bookmark/includes/flag_bookmark.views_default.inc
diff --git a/flag_bookmark/includes/flag_bookmark.views_default.inc b/flag_bookmark/includes/flag_bookmark.views_default.inc
deleted file mode 100644
index e656ca3..0000000
--- a/flag_bookmark/includes/flag_bookmark.views_default.inc
+++ /dev/null
@@ -1,284 +0,0 @@
- array(
- 'id' => 'type',
- 'table' => 'node',
- 'field' => 'type',
- 'label' => 'Type',
- ),
- 'title' => array(
- 'id' => 'title',
- 'table' => 'node',
- 'field' => 'title',
- 'label' => 'Title',
- 'link_to_node' => 1,
- ),
- 'name' => array(
- 'label' => 'Author',
- 'link_to_user' => 1,
- 'id' => 'name',
- 'table' => 'users',
- 'field' => 'name',
- 'relationship' => 'uid_1',
- ),
- );
-
- $style_options = array(
- 'grouping' => '',
- 'override' => 0,
- 'sticky' => 1,
- 'columns' => array(),
- 'default' => 'title',
- 'order' => 'asc',
- 'columns' => array(
- 'type' => 'type',
- 'title' => 'title',
- 'name' => 'name',
- ),
- 'info' => array(
- 'type' => array(
- 'sortable' => TRUE,
- ),
- 'title' => array(
- 'sortable' => TRUE,
- ),
- 'name' => array(
- 'sortable' => TRUE,
- ),
- ),
- 'override' => FALSE,
- 'order' => 'asc',
- );
-
- $filters = array(
- 'status' => array(
- 'operator' => '=',
- 'value' => 1,
- 'group' => '0',
- 'exposed' => FALSE,
- 'expose' => array(
- 'operator' => FALSE,
- 'label' => '',
- ),
- 'id' => 'status',
- 'table' => 'node',
- 'field' => 'status',
- 'relationship' => 'none',
- ),
- );
-
- $relationships = array(
- 'flag_content_rel' => array(
- 'label' => 'bookmarks',
- 'required' => 1,
- 'flag' => 'bookmarks',
- 'user_scope' => 'current',
- 'id' => 'flag_content_rel',
- 'table' => 'node',
- 'field' => 'flag_content_rel',
- 'relationship' => 'none',
- 'override' => array(
- 'button' => 'Override',
- ),
- ),
- 'uid_1' => array(
- 'label' => 'author',
- 'required' => 0,
- 'id' => 'uid_1',
- 'table' => 'node',
- 'field' => 'uid',
- ),
- );
-
- $access = array(
- 'type' => 'perm',
- 'perm' => 'flag bookmarks',
- );
-
- // Additional fields and style options if comment exists.
- if (module_exists('comment')) {
- $fields += array(
- 'comment_count' => array(
- 'id' => 'comment_count',
- 'table' => 'node_comment_statistics',
- 'field' => 'comment_count',
- 'label' => 'Replies',
- ),
- 'last_comment_timestamp' => array(
- 'id' => 'last_comment_timestamp',
- 'table' => 'node_comment_statistics',
- 'field' => 'last_comment_timestamp',
- 'label' => 'Last Post',
- ),
- );
-
- $style_options['default'] = 'last_comment_timestamp';
- $style_options['order'] = 'desc';
- $style_options['info'] += array(
- 'comment_count' => array(
- 'sortable' => TRUE,
- ),
- 'last_comment_timestamp' => array(
- 'sortable' => TRUE,
- ),
- );
- $style_options['columns'] += array(
- 'comment_count' => 'comment_count',
- 'last_comment_timestamp' => 'last_comment_timestamp',
- );
- }
-
- /* Individual users user/%/bookmarks tab. */
-
- // Additional relationship for this view.
- $relationships_tab = $relationships;
- $relationships_tab['flag_content_rel']['user_scope'] = 'any';
- $relationships_tab += array(
- 'uid' => array(
- 'label' => 'bookmarks_user',
- 'required' => 1,
- 'id' => 'uid',
- 'table' => 'flagging',
- 'field' => 'uid',
- 'relationship' => 'flag_content_rel',
- ),
- );
-
- // Additional argument for this view.
- $arguments_tab = array(
- 'uid' => array(
- 'default_action' => 'empty',
- 'style_plugin' => 'default_summary',
- 'style_options' => array(),
- 'wildcard' => 'all',
- 'wildcard_substitution' => 'All',
- 'title' => '%1\'s bookmarks',
- 'default_argument_type' => 'fixed',
- 'default_argument' => '',
- 'validate_type' => 'none',
- 'validate_fail' => 'not found',
- 'break_phrase' => 0,
- 'not' => 0,
- 'id' => 'uid',
- 'table' => 'users',
- 'field' => 'uid',
- 'override' => array(
- 'button' => 'Override',
- ),
- 'relationship' => 'uid',
- 'default_options_div_prefix' => '',
- 'default_argument_user' => 0,
- 'default_argument_fixed' => '',
- 'default_argument_php' => '',
- ),
- );
-
- $view = new view;
- $view->name = 'flag_bookmarks_tab';
- $view->description = "Provides a tab on all users' profile pages containing bookmarks for that user.";
- $view->tag = 'flag';
- $view->view_php = '';
- $view->base_table = 'node';
- $view->is_cacheable = FALSE;
- $view->api_version = 2;
- $view->disabled = FALSE;
- $handler = $view->new_display('default', 'Defaults', 'default');
- $handler->override_option('relationships', $relationships_tab);
- $handler->override_option('fields', $fields);
- $handler->override_option('arguments', $arguments_tab);
- $handler->override_option('filters', $filters);
- $handler->override_option('access', $access);
- $handler->override_option('title', 'User bookmarks');
- $handler->override_option('empty', 'This user has not yet bookmarked any content.');
- $handler->override_option('empty_format', filter_fallback_format());
- $handler->override_option('items_per_page', '25');
- $handler->override_option('use_pager', TRUE);
- $handler->override_option('style_plugin', 'table');
- $handler->override_option('style_options', $style_options);
-
- $handler = $view->new_display('page', 'Page', 'page');
- $handler->override_option('path', 'user/%/bookmarks');
- $handler->override_option('menu', array(
- 'type' => 'tab',
- 'title' => 'Bookmarks',
- 'weight' => '0',
- 'name' => 'navigation',
- ));
- $handler->override_option('tab_options', array(
- 'type' => 'none',
- 'title' => NULL,
- 'weight' => NULL,
- ));
-
- $views[$view->name] = $view;
-
- /* User bookmarks page with Ops. */
-
- // Add some unique options for this view.
- $style_options['columns'] += array('ops' => 'ops');
- $fields += array(
- 'ops' => array(
- 'label' => 'Ops',
- 'id' => 'ops',
- 'table' => 'flagging',
- 'field' => 'ops',
- 'relationship' => 'flag_content_rel',
- ),
- );
-
- $view = new view;
- $view->name = 'flag_' . $flag->name;
- $view->description = "A page listing the current user's bookmarks at /bookmarks.";
- $view->tag = 'flag';
- $view->view_php = '';
- $view->base_table = 'node';
- $view->is_cacheable = '0';
- $view->api_version = 2;
- $view->disabled = FALSE;
- $handler = $view->new_display('default', 'Defaults', 'default');
- $handler->override_option('relationships', $relationships);
- $handler->override_option('fields', $fields);
- $handler->override_option('filters', $filters);
- $handler->override_option('access', $access);
- $handler->override_option('title', t('My bookmarks'));
- $handler->override_option('items_per_page', '25');
- $handler->override_option('use_pager', TRUE);
- $handler->override_option('empty', 'You have not yet bookmarked any content. Click the "' . $flag->flag_short . '" link when viewing a piece of content to add it to this list.');
- $handler->override_option('empty_format', filter_fallback_format());
- $handler->override_option('style_plugin', 'table');
- $handler->override_option('style_options', $style_options);
- $handler = $view->new_display('page', 'Page', 'page');
- $handler->override_option('path', 'bookmarks');
- $handler->override_option('menu', array(
- 'type' => 'normal',
- 'title' => t('My bookmarks'),
- 'weight' => '0',
- ));
- $handler->override_option('tab_options', array(
- 'type' => 'none',
- 'title' => NULL,
- 'weight' => NULL,
- ));
-
- $views[$view->name] = $view;
-
- return $views;
-}
From 934ab3ad7734bb794f82465e95f2cf13ba6dac22 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Tue, 10 Jun 2014 17:18:01 -0500
Subject: [PATCH 406/629] Moved and renamed default yml files.
---
.../install/flag.flag_flag.bookmark.yml} | 0
.../install/views.view.flag_bookmark.yml} | 0
2 files changed, 0 insertions(+), 0 deletions(-)
rename flag_bookmark/{src/config/install/flag_bookmark.flag_flag.bookmark.yml => config/install/flag.flag_flag.bookmark.yml} (100%)
rename flag_bookmark/{src/config/install/flag_bookmark.view.flag_bookmark.yml => config/install/views.view.flag_bookmark.yml} (100%)
diff --git a/flag_bookmark/src/config/install/flag_bookmark.flag_flag.bookmark.yml b/flag_bookmark/config/install/flag.flag_flag.bookmark.yml
similarity index 100%
rename from flag_bookmark/src/config/install/flag_bookmark.flag_flag.bookmark.yml
rename to flag_bookmark/config/install/flag.flag_flag.bookmark.yml
diff --git a/flag_bookmark/src/config/install/flag_bookmark.view.flag_bookmark.yml b/flag_bookmark/config/install/views.view.flag_bookmark.yml
similarity index 100%
rename from flag_bookmark/src/config/install/flag_bookmark.view.flag_bookmark.yml
rename to flag_bookmark/config/install/views.view.flag_bookmark.yml
From fd39acbd8708c20c708d86f13bec5d825bfd6433 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Tue, 17 Jun 2014 20:40:24 -0500
Subject: [PATCH 407/629] Plugin manager changes due to
https://drupal.org/node/2281905
---
.../config/install/views.view.flag_bookmark.yml | 1 -
src/ActionLinkPluginManager.php | 2 +-
src/FlagTypePluginManager.php | 2 +-
tests/src/FlagTestBase.php | 16 ++++++++++++++++
4 files changed, 18 insertions(+), 3 deletions(-)
create mode 100644 tests/src/FlagTestBase.php
diff --git a/flag_bookmark/config/install/views.view.flag_bookmark.yml b/flag_bookmark/config/install/views.view.flag_bookmark.yml
index f97277d..7224fb8 100644
--- a/flag_bookmark/config/install/views.view.flag_bookmark.yml
+++ b/flag_bookmark/config/install/views.view.flag_bookmark.yml
@@ -9,7 +9,6 @@ display:
id: default
display_title: Master
position: 0
- provider: views
display_options:
access:
type: perm
diff --git a/src/ActionLinkPluginManager.php b/src/ActionLinkPluginManager.php
index 89ad00d..600d17a 100644
--- a/src/ActionLinkPluginManager.php
+++ b/src/ActionLinkPluginManager.php
@@ -23,7 +23,7 @@ class ActionLinkPluginManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/ActionLink', $namespaces, $module_handler, 'Drupal\flag\Annotation\ActionLinkType');
$this->alterInfo('flag_link_type_info');
- $this->setCacheBackend($cache_backend, $language_manager, 'flag_link_type_plugins');
+ $this->setCacheBackend($cache_backend, 'flag_link_type_plugins');
}
public function getAllLinkTypes() {
diff --git a/src/FlagTypePluginManager.php b/src/FlagTypePluginManager.php
index 35ccadf..3dd7d9b 100644
--- a/src/FlagTypePluginManager.php
+++ b/src/FlagTypePluginManager.php
@@ -32,7 +32,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
parent::__construct('Plugin/Flag', $namespaces, $module_handler, 'Drupal\flag\Annotation\FlagType');
//$this->alterInfo('flag_type_info');
- $this->setCacheBackend($cache_backend, $language_manager, 'flag');
+ $this->setCacheBackend($cache_backend, 'flag');
}
public function getAllFlagTypes() {
diff --git a/tests/src/FlagTestBase.php b/tests/src/FlagTestBase.php
new file mode 100644
index 0000000..7bdb96c
--- /dev/null
+++ b/tests/src/FlagTestBase.php
@@ -0,0 +1,16 @@
+
Date: Tue, 17 Jun 2014 20:59:35 -0500
Subject: [PATCH 408/629] Moved and fixed flag schema due to
https://drupal.org/node/2016679.
---
{src/config => config}/schema/flag.schema.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
rename {src/config => config}/schema/flag.schema.yml (95%)
diff --git a/src/config/schema/flag.schema.yml b/config/schema/flag.schema.yml
similarity index 95%
rename from src/config/schema/flag.schema.yml
rename to config/schema/flag.schema.yml
index 9bc3030..4ed192b 100644
--- a/src/config/schema/flag.schema.yml
+++ b/config/schema/flag.schema.yml
@@ -1,5 +1,5 @@
-flag.flag.*:
- type: mapping
+flag.flag_flag.*:
+ type: config_entity
label: 'Flag'
mapping:
id:
From 6d4bcd39d47501b540998e764725cf76310093e7 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Thu, 19 Jun 2014 11:17:42 +0200
Subject: [PATCH 409/629] Fixed linktype settings form in administration. Now
functioning using ajax sub forms.
---
src/Form/FlagFormBase.php | 58 ++++++++++++++++++++++++++-
src/Form/FlaggingConfirmForm.php | 2 +-
src/Plugin/ActionLink/ConfirmForm.php | 10 ++---
3 files changed, 62 insertions(+), 8 deletions(-)
diff --git a/src/Form/FlagFormBase.php b/src/Form/FlagFormBase.php
index 7d39287..f50b0e9 100644
--- a/src/Form/FlagFormBase.php
+++ b/src/Form/FlagFormBase.php
@@ -44,6 +44,14 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'exists' => 'flag_load_by_id',
),
'#disabled' => !$flag->isNew(),
+ '#submit' => array(array($this, 'submitSelectPlugin')),
+ '#required' => TRUE,
+ '#executes_submit_callback' => TRUE,
+ '#ajax' => array(
+ 'callback' => array($this, 'updateSelectedPluginType'),
+ 'wrapper' => 'monitoring-sensor-plugin',
+ 'method' => 'replace',
+ ),
);
$form['is_global'] = array(
@@ -110,6 +118,8 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'#weight' => 10,
);
+ // Switch plugin type in case a different is chosen.
+
$flag_type_plugin = $flag->getFlagTypePlugin();
$flag_type_def = $flag_type_plugin->getPluginDefinition();
@@ -148,6 +158,13 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
// '#after_build' => array('flag_link_type_options_states'),
);
+ $form['display']['settings'] = array(
+ '#type' => 'container',
+ '#prefix' => '',
+ '#suffix' => '
',
+ '#weight' => 21,
+ );
+
$form = $flag_type_plugin->buildConfigurationForm($form, $form_state);
$form['display']['link_type'] = array(
@@ -165,12 +182,32 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
'#attributes' => array(
'class' => array('flag-link-options'),
),
+ '#limit_validation_errors' => array(array('link_type')),
+ '#submit' => array(array($this, 'submitSelectPlugin')),
+ '#required' => TRUE,
+ '#executes_submit_callback' => TRUE,
+ '#ajax' => array(
+ 'callback' => array($this, 'updateSelectedPluginType'),
+ 'wrapper' => 'link-type-settings-wrapper',
+ 'event' => 'change',
+ 'method' => 'replace',
+ ),
+ );
+ $form['display']['link_type_submit'] = array(
+ '#type' => 'submit',
+ '#value' => $this->t('Update'),
+ '#submit' => array(array($this, 'submitSelectPlugin')),
+ '#weight' => 20,
+ '#attributes' => array('class' => array('js-hide')),
);
// Add the descriptions to each ratio button element. These attach to the
// elements when FormAPI expands them.
$action_link_plugin_defs = \Drupal::service('plugin.manager.flag.linktype')->getDefinitions();
foreach ($action_link_plugin_defs as $key => $info) {
$form['display']['link_type'][$key]['#description'] = $info['description'];
+ $form['display']['link_type'][$key]['#submit'] = array(array($this, 'submitSelectPlugin'));
+ $form['display']['link_type'][$key]['#executes_submit_callback'] = TRUE;
+ $form['display']['link_type'][$key]['#limit_validation_errors'] = array(array('link_type'));
}
$action_link_plugin = $flag->getLinkTypePlugin();
@@ -179,6 +216,25 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL)
return $form;
}
+ /**
+ * Handles switching the configuration type selector.
+ */
+ public function updateSelectedPluginType($form, &$form_state) {
+ return $form['display']['settings'];
+ }
+
+ /**
+ * Handles submit call when sensor type is selected.
+ */
+ public function submitSelectPlugin(array $form, array &$form_state) {
+ $this->entity = $this->buildEntity($form, $form_state);
+
+ $form_state['rebuild'] = TRUE;
+ // @todo: This is necessary because there are two different instances of the
+ // form object. Core should handle this.
+ $form_state['build_info']['callback_object'] = $form_state['controller'];
+ }
+
/**
* Overrides Drupal\Core\Entity\EntityFormController::validate().
*/
@@ -266,4 +322,4 @@ public function delete(array $form, array &$form_state) {
$form_state['redirect'] = 'admin/structure/flags';
}
-}
\ No newline at end of file
+}
diff --git a/src/Form/FlaggingConfirmForm.php b/src/Form/FlaggingConfirmForm.php
index 6965763..2af1652 100644
--- a/src/Form/FlaggingConfirmForm.php
+++ b/src/Form/FlaggingConfirmForm.php
@@ -82,4 +82,4 @@ public function submitForm(array &$form, array &$form_state) {
}
}
-}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/Plugin/ActionLink/ConfirmForm.php b/src/Plugin/ActionLink/ConfirmForm.php
index 5ebfa8c..e3c45d2 100644
--- a/src/Plugin/ActionLink/ConfirmForm.php
+++ b/src/Plugin/ActionLink/ConfirmForm.php
@@ -44,8 +44,7 @@ public function defaultConfiguration() {
public function buildConfigurationForm(array $form, array &$form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
-
- $form['display']['link_options_confirm'] = array(
+ $form['display']['settings']['link_options_confirm'] = array(
'#type' => 'fieldset',
'#title' => t('Options for the "Confirmation form" link type'),
// Any "link type" provider module must put its settings fields inside
@@ -53,10 +52,9 @@ public function buildConfigurationForm(array $form, array &$form_state) {
// the machine-name of the link type. This is necessary for the
// radiobutton's JavaScript dependency feature to work.
'#id' => 'link-options-confirm',
- '#weight' => 21,
);
- $form['display']['link_options_confirm']['flag_confirmation'] = array(
+ $form['display']['settings']['link_options_confirm']['flag_confirmation'] = array(
'#type' => 'textfield',
'#title' => t('Flag confirmation message'),
'#default_value' => $this->configuration['flag_confirmation'],
@@ -65,7 +63,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
'#required' => TRUE,
);
- $form['display']['link_options_confirm']['unflag_confirmation'] = array(
+ $form['display']['settings']['link_options_confirm']['unflag_confirmation'] = array(
'#type' => 'textfield',
'#title' => t('Unflag confirmation message'),
'#default_value' => $this->configuration['unflag_confirmation'],
@@ -91,4 +89,4 @@ public function getUnflagQuestion() {
return $this->configuration['unflag_confirmation'];
}
-}
\ No newline at end of file
+}
\ No newline at end of file
From 716e85b8d09b779f0106f94196c61753775a1980 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Thu, 19 Jun 2014 21:56:28 -0500
Subject: [PATCH 410/629] Implemented EntityWithPluginBagsInterface for Flag.
---
config/schema/flag.schema.yml | 12 ++++++------
src/Entity/Flag.php | 32 +++++++++++++++++++++++++-------
src/FlagInterface.php | 5 ++++-
3 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/config/schema/flag.schema.yml b/config/schema/flag.schema.yml
index 4ed192b..8f6ec20 100644
--- a/config/schema/flag.schema.yml
+++ b/config/schema/flag.schema.yml
@@ -38,9 +38,9 @@ flag.flag_flag.*:
weight:
type: integer
label: 'Weight'
-# link_type:
-# type: sequence
-# label: 'Link Type'
-# sequence:
-# - type: flag.link.[plugin]
-# label: 'Flag Link Type's
\ No newline at end of file
+ flag_type:
+ type: string
+ label: 'ID of the Flag Type plugin'
+ link_type:
+ type: string
+ label: 'ID of the Link Type plugin'
diff --git a/src/Entity/Flag.php b/src/Entity/Flag.php
index ea87af2..4d4b6a6 100644
--- a/src/Entity/Flag.php
+++ b/src/Entity/Flag.php
@@ -219,6 +219,16 @@ public function isFlagged(EntityInterface $entity, AccountInterface $account = N
return FALSE;
}
+ /**
+ *
+ */
+ public function getPluginBags() {
+ return array(
+ 'flagTypeConfig' => $this->flagTypeBag,
+ 'linkTypeConfig' => $this->linkTypeBag,
+ );
+ }
+
/**
* Get the flag type plugin for this flag.
*
@@ -236,7 +246,11 @@ public function getFlagTypePlugin() {
*/
public function setFlagTypePlugin($pluginID) {
$this->flag_type = $pluginID;
- $this->flagTypeBag->addInstanceId($pluginID);
+ //$this->flagTypeBag->addInstanceId($pluginID);
+
+ // Workaround for https://www.drupal.org/node/2288805
+ $this->flagTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.flagtype'),
+ $this->flag_type, $this->flagTypeConfig);
// Get the entity type from the plugin definition.
$plugin = $this->getFlagTypePlugin();
@@ -261,7 +275,12 @@ public function getLinkTypePlugin() {
*/
public function setlinkTypePlugin($pluginID) {
$this->link_type = $pluginID;
- $this->linkTypeBag->addInstanceId($pluginID);
+
+ //$this->linkTypeBag->addInstanceId($pluginID);
+
+ // Workaround for https://www.drupal.org/node/2288805
+ $this->linkTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.linktype'),
+ $this->link_type, $this->linkTypeConfig);
}
/**
@@ -307,7 +326,7 @@ public function getFlaggableEntityType() {
*/
public function preSave(EntityStorageInterface $storage_controller) {
parent::preSave($storage_controller);
-
+/*
// Save the Flag Type configuration.
$flagTypePlugin = $this->getFlagTypePlugin();
$this->set('flagTypeConfig', $flagTypePlugin->getConfiguration());
@@ -315,17 +334,16 @@ public function preSave(EntityStorageInterface $storage_controller) {
// Save the Link Type configuration.
$linkTypePlugin = $this->getLinkTypePlugin();
$this->set('linkTypeConfig', $linkTypePlugin->getConfiguration());
-
+*/
// Reset the render cache for the entity.
\Drupal::entityManager()
->getViewBuilder($this->getFlaggableEntityType())
->resetCache();
}
-
+/*
public function toArray() {
$properties = parent::toArray();
$names = array(
- 'roles',
'flag_type',
'link_type',
'flagTypeConfig',
@@ -338,5 +356,5 @@ public function toArray() {
return $properties;
}
-
+*/
}
\ No newline at end of file
diff --git a/src/FlagInterface.php b/src/FlagInterface.php
index 43fcdad..fafd458 100644
--- a/src/FlagInterface.php
+++ b/src/FlagInterface.php
@@ -10,9 +10,10 @@
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\EntityWithPluginBagsInterface;
use Drupal\Core\Session\AccountInterface;
-interface FlagInterface extends ConfigEntityInterface {
+interface FlagInterface extends ConfigEntityInterface, EntityWithPluginBagsInterface {
// todo: Add getters and setters as necessary.
@@ -27,4 +28,6 @@ public function getPermissions();
public function isGlobal();
public function setGlobal($isGlobal);
+
+ public function getPluginBags();
}
\ No newline at end of file
From 7ee32b82ff8939453d3eb2892ba2df9363d98011 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Fri, 20 Jun 2014 16:25:50 +0200
Subject: [PATCH 411/629] Language Manager removed from Plugin managers.
---
flag.services.yml | 4 ++--
src/ActionLinkPluginManager.php | 4 ++--
src/FlagTypePluginManager.php | 7 ++-----
3 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/flag.services.yml b/flag.services.yml
index d637bef..9ff8300 100644
--- a/flag.services.yml
+++ b/flag.services.yml
@@ -1,10 +1,10 @@
services:
plugin.manager.flag.flagtype:
class: Drupal\flag\FlagTypePluginManager
- arguments: ['@container.namespaces', '@cache.default', '@language_manager', '@module_handler']
+ arguments: ['@container.namespaces', '@cache.default', '@module_handler']
plugin.manager.flag.linktype:
class: Drupal\flag\ActionLinkPluginManager
- arguments: ['@container.namespaces', '@cache.default', '@language_manager', '@module_handler']
+ arguments: ['@container.namespaces', '@cache.default', '@module_handler']
flag:
class: Drupal\flag\FlagService
arguments: ['@module_handler']
diff --git a/src/ActionLinkPluginManager.php b/src/ActionLinkPluginManager.php
index 89ad00d..7e6bbec 100644
--- a/src/ActionLinkPluginManager.php
+++ b/src/ActionLinkPluginManager.php
@@ -20,10 +20,10 @@ class ActionLinkPluginManager extends DefaultPluginManager {
/**
* {@inheritdoc}
*/
- public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
+ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/ActionLink', $namespaces, $module_handler, 'Drupal\flag\Annotation\ActionLinkType');
$this->alterInfo('flag_link_type_info');
- $this->setCacheBackend($cache_backend, $language_manager, 'flag_link_type_plugins');
+ $this->setCacheBackend($cache_backend, 'flag_link_type_plugins');
}
public function getAllLinkTypes() {
diff --git a/src/FlagTypePluginManager.php b/src/FlagTypePluginManager.php
index 35ccadf..8485eaf 100644
--- a/src/FlagTypePluginManager.php
+++ b/src/FlagTypePluginManager.php
@@ -10,7 +10,6 @@
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
-use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Plugin\DefaultPluginManager;
class FlagTypePluginManager extends DefaultPluginManager {
@@ -23,16 +22,14 @@ class FlagTypePluginManager extends DefaultPluginManager {
* keyed by the corresponding namespace to look for plugin implementations,
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
- * @param \Drupal\Core\Language\LanguageManager $language_manager
- * The language manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke the alter hook with.
*/
- public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
+ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Flag', $namespaces, $module_handler, 'Drupal\flag\Annotation\FlagType');
//$this->alterInfo('flag_type_info');
- $this->setCacheBackend($cache_backend, $language_manager, 'flag');
+ $this->setCacheBackend($cache_backend, 'flag');
}
public function getAllFlagTypes() {
From fc079604ce1d7667f885b043885f0dc74535fad5 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 22 Jun 2014 00:26:41 -0500
Subject: [PATCH 412/629] Changed flag entity ID from flag_flag to just plain
'ol flag.
---
config/schema/flag.schema.yml | 2 +-
flag.module | 4 ++--
flag.routing.yml | 16 ++++++++--------
src/Entity/Flag.php | 18 +++++++++++-------
src/Entity/Flagging.php | 4 ++--
src/FlagService.php | 8 ++++----
src/Plugin/views/field/FlagViewsLinkField.php | 5 +++++
7 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/config/schema/flag.schema.yml b/config/schema/flag.schema.yml
index 8f6ec20..e5ab63f 100644
--- a/config/schema/flag.schema.yml
+++ b/config/schema/flag.schema.yml
@@ -1,4 +1,4 @@
-flag.flag_flag.*:
+flag.flag.*:
type: config_entity
label: 'Flag'
mapping:
diff --git a/flag.module b/flag.module
index 009bb16..223abf2 100644
--- a/flag.module
+++ b/flag.module
@@ -1444,7 +1444,7 @@ function flag_get_flag($name = NULL, $fid = NULL) {
}
function flag_load_by_id($id) {
- return entity_load('flag_flag', $id);
+ return entity_load('flag', $id);
}
/**
@@ -1465,7 +1465,7 @@ function flag_load_by_id($id) {
* An array of the structure [fid] = flag_object.
*/
function flag_get_flags($entity_type = NULL, $content_subtype = NULL, $account = NULL) {
- return entity_load_multiple('flag_flag');
+ return entity_load_multiple('flag');
/**
$flags = &drupal_static(__FUNCTION__);
diff --git a/flag.routing.yml b/flag.routing.yml
index a259e8c..8afef14 100644
--- a/flag.routing.yml
+++ b/flag.routing.yml
@@ -9,7 +9,7 @@ flag.add_page:
flag.list:
path: '/admin/structure/flags'
defaults:
- _entity_list: 'flag_flag'
+ _entity_list: 'flag'
_title: 'Flags'
requirements:
_permission: 'administer flags'
@@ -17,26 +17,26 @@ flag.list:
flag.add:
path: '/admin/structure/flags/add/{entity_type}'
defaults:
- _entity_form: flag_flag.add
+ _entity_form: flag.add
_title: 'Add New Flag'
requirements:
_permission: 'administer flags'
flag.edit:
- path: '/admin/structure/flags/manage/{flag_flag}'
+ path: '/admin/structure/flags/manage/{flag}'
defaults:
- _entity_form: flag_flag.edit
+ _entity_form: flag.edit
_title: 'Edit Flag'
requirements:
- _entity_access: 'flag_flag.update'
+ _entity_access: 'flag.update'
flag.delete:
- path: '/admin/structure/flags/manage/{flag_flag}/delete'
+ path: '/admin/structure/flags/manage/{flag}/delete'
defaults:
- _entity_form: flag_flag.delete
+ _entity_form: flag.delete
_title: 'Delete Flag'
requirements:
- _entity_access: 'flag_flag.update'
+ _entity_access: 'flag.update'
flag_link_flag.html:
path: '/flag/flag/{flag_id}/{entity_id}'
diff --git a/src/Entity/Flag.php b/src/Entity/Flag.php
index 4d4b6a6..3289944 100644
--- a/src/Entity/Flag.php
+++ b/src/Entity/Flag.php
@@ -23,7 +23,7 @@
* @package Drupal\flag\Entity
*
* @ConfigEntityType(
- * id = "flag_flag",
+ * id = "flag",
* label = @Translation("Flag"),
* admin_permission = "administer flags",
* controllers = {
@@ -185,11 +185,15 @@ class Flag extends ConfigEntityBase implements FlagInterface {
public function __construct(array $values, $entity_type) {
parent::__construct($values, $entity_type);
- $this->flagTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.flagtype'),
- $this->flag_type, $this->flagTypeConfig);
+ if ($this->flag_type) {
+ $this->flagTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.flagtype'),
+ $this->flag_type, $this->flagTypeConfig);
+ }
- $this->linkTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.linktype'),
- $this->link_type, $this->linkTypeConfig);
+ if ($this->link_type) {
+ $this->linkTypeBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.flag.linktype'),
+ $this->link_type, $this->linkTypeConfig);
+ }
}
public function enable() {
@@ -340,7 +344,7 @@ public function preSave(EntityStorageInterface $storage_controller) {
->getViewBuilder($this->getFlaggableEntityType())
->resetCache();
}
-/*
+
public function toArray() {
$properties = parent::toArray();
$names = array(
@@ -356,5 +360,5 @@ public function toArray() {
return $properties;
}
-*/
+
}
\ No newline at end of file
diff --git a/src/Entity/Flagging.php b/src/Entity/Flagging.php
index debe1a4..8ebe1ec 100644
--- a/src/Entity/Flagging.php
+++ b/src/Entity/Flagging.php
@@ -49,7 +49,7 @@ public function getFlagId() {
}
public function getFlag() {
- return entity_load('flag_flag', $this->getFlagId());
+ return entity_load('flag', $this->getFlagId());
}
public function getFlaggableType() {
@@ -91,7 +91,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['type'] = FieldDefinition::create('entity_reference')
->setLabel(t('Type'))
->setDescription(t('The flag type.'))
- ->setSetting('target_type', 'flag_flag')
+ ->setSetting('target_type', 'flag')
->setReadOnly(TRUE);
$fields['uid'] = FieldDefinition::create('entity_reference')
diff --git a/src/FlagService.php b/src/FlagService.php
index a8352e8..fe38a39 100644
--- a/src/FlagService.php
+++ b/src/FlagService.php
@@ -66,7 +66,7 @@ public function fetchDefinition($entity_type = NULL) {
* An array of the structure [fid] = flag_object.
*/
public function getFlags($entity_type = NULL, $bundle = NULL, AccountInterface $account = NULL) {
- $query = \Drupal::entityQuery('flag_flag');
+ $query = \Drupal::entityQuery('flag');
if($entity_type != NULL) {
$query->condition('entity_type', $entity_type);
@@ -78,7 +78,7 @@ public function getFlags($entity_type = NULL, $bundle = NULL, AccountInterface $
$result = $query->execute();
- $flags = entity_load_multiple('flag_flag', $result);
+ $flags = entity_load_multiple('flag', $result);
if ($account == NULL) {
return $flags;
@@ -115,7 +115,7 @@ public function getFlaggings(EntityInterface $entity, FlagInterface $flag, Accou
}
public function getFlagById($flag_id) {
- return entity_load('flag_flag', $flag_id);
+ return entity_load('flag', $flag_id);
}
public function getFlaggableById(FlagInterface $flag, $entity_id) {
@@ -128,7 +128,7 @@ public function flagByObject(FlagInterface $flag, EntityInterface $entity, Accou
}
$flagging = entity_create('flagging', array(
- 'type' => 'flag_flag',
+ 'type' => 'flag',
'uid' => $account->id(),
'fid' => $flag->id(),
'entity_id' => $entity->id(),
diff --git a/src/Plugin/views/field/FlagViewsLinkField.php b/src/Plugin/views/field/FlagViewsLinkField.php
index 182f71d..7d8e0c9 100644
--- a/src/Plugin/views/field/FlagViewsLinkField.php
+++ b/src/Plugin/views/field/FlagViewsLinkField.php
@@ -35,6 +35,9 @@ protected function defineOptions() {
'default' => '',
'translatable' => TRUE,
);
+
+ //$options['relationship'] = array('default' => 'none');
+
/*
$options['link_to_entity'] = array(
'default' => FALSE,
@@ -58,6 +61,8 @@ public function buildOptionsForm(&$form, &$form_state) {
);
parent::buildOptionsForm($form, $form_state);
+
+ $form['relationship']['#access'] = FALSE;
}
public function query() {
From ae33478c392b1025909b7400ec2ebe1bc249d75f Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 22 Jun 2014 00:55:53 -0500
Subject: [PATCH 413/629] Fix for flaggable types not being stored.
---
config/schema/flag.schema.yml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/config/schema/flag.schema.yml b/config/schema/flag.schema.yml
index e5ab63f..104ded9 100644
--- a/config/schema/flag.schema.yml
+++ b/config/schema/flag.schema.yml
@@ -11,6 +11,10 @@ flag.flag.*:
label:
type: label
label: 'Label'
+ types:
+ type: sequence
+ sequence:
+ - type: string
is_global:
type: boolean
label: 'Is flag global'
From b2b420240d6afb7eb313f75af70f57e78479c78d Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 22 Jun 2014 23:00:29 -0500
Subject: [PATCH 414/629] Fixed missing entity_type field in Flag config
schema.
---
config/schema/flag.schema.yml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/config/schema/flag.schema.yml b/config/schema/flag.schema.yml
index 104ded9..3e07818 100644
--- a/config/schema/flag.schema.yml
+++ b/config/schema/flag.schema.yml
@@ -15,6 +15,9 @@ flag.flag.*:
type: sequence
sequence:
- type: string
+ entity_type:
+ type: string
+ label: 'Flaggable Entity Type'
is_global:
type: boolean
label: 'Is flag global'
From c64417cb1e115b8f0977aeb1a87c0b0e54865bd8 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 22 Jun 2014 23:01:12 -0500
Subject: [PATCH 415/629] Fixed missing default flag selection in view
relationship.
---
.../relationship/FlagViewsRelationship.php | 24 +++++++++----------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/src/Plugin/views/relationship/FlagViewsRelationship.php b/src/Plugin/views/relationship/FlagViewsRelationship.php
index 05e4d28..b8349f5 100644
--- a/src/Plugin/views/relationship/FlagViewsRelationship.php
+++ b/src/Plugin/views/relationship/FlagViewsRelationship.php
@@ -19,35 +19,35 @@ class FlagViewsRelationship extends RelationshipPluginBase {
public function defineOptions() {
$options = parent::defineOptions();
- $options['flag'] = array('default' => NULL); // @todo load first defined flag for entity.
+ $options['flag'] = array('default' => NULL);
$options['required'] = array('default' => 1);
$options['user_scope'] = array('default' => 'current');
return $options;
}
public function buildOptionsForm(&$form, &$form_state) {
- $entity_type = $this->definition['flaggable'];
- //$form['label']['#description'] .= ' ' . t('The name of the selected flag makes a good label.');
+ parent::buildOptionsForm($form, $form_state);
- /*//////////////////////////////////////////////////////////////////////////
- @todo Add Flag selection form
+ $entity_type = $this->definition['flaggable'];
+ $form['label']['#description'] .= ' ' . t('The name of the selected flag makes a good label.');
- The Flag relationship relates a single flag to a single entity. Since
- multiple flags may be configured for the same entity type, we need to
- provide a form here that allows us to choose the flag.
- //////////////////////////////////////////////////////////////////////////*/
$flags = \Drupal::service('flag')->getFlags($entity_type);
+ $default_value = $this->options['flag'];
+ if (!empty($flags) ) {
+ $default_value = current(array_keys($flags));
+ }
+
$form['flag'] = array(
'#type' => 'radios',
'#title' => t('Flag'),
- // '#default_value' => current(array_keys($flags)),
+ '#default_value' => $default_value,
'#required' => TRUE,
);
foreach ($flags as $fid => $flag) {
if (!empty($flag)) {
- $form['flag']['#options'][$flag->label()] = $fid;
+ $form['flag']['#options'][$fid] = $flag->label();
}
}
@@ -69,8 +69,6 @@ public function buildOptionsForm(&$form, &$form_state) {
);
$form_state['no flags exist'] = TRUE;
}
-
- parent::buildOptionsForm($form, $form_state);
}
public function query() {
From da10302079cc9839f568514c713b3714ef2cc59d Mon Sep 17 00:00:00 2001
From: socketwench
Date: Mon, 23 Jun 2014 09:47:52 -0500
Subject: [PATCH 416/629] Set default relationship for FlagViewsLinkField.
---
src/Plugin/views/field/FlagViewsLinkField.php | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/src/Plugin/views/field/FlagViewsLinkField.php b/src/Plugin/views/field/FlagViewsLinkField.php
index 7d8e0c9..acb1e4b 100644
--- a/src/Plugin/views/field/FlagViewsLinkField.php
+++ b/src/Plugin/views/field/FlagViewsLinkField.php
@@ -36,15 +36,12 @@ protected function defineOptions() {
'translatable' => TRUE,
);
- //$options['relationship'] = array('default' => 'none');
-
-/*
- $options['link_to_entity'] = array(
- 'default' => FALSE,
- 'bool' => TRUE,
- );
-*/
- //@todo return link type
+ // Set the default relationship handler. The first instance of the
+ // FlagViewsRelationship should always have the id "flag_content_rel", so
+ // we set that as the default.
+ //if (!isset($this->options['relationship'])) {
+ $options['relationship'] = array('default' => 'flag_content_rel');
+ //}
return $options;
}
@@ -60,9 +57,9 @@ public function buildOptionsForm(&$form, &$form_state) {
'#default_value' => $this->options['text'],
);
- parent::buildOptionsForm($form, $form_state);
+ $form['relationship']['#default_value'] = $this->options['relationship'];
- $form['relationship']['#access'] = FALSE;
+ parent::buildOptionsForm($form, $form_state);
}
public function query() {
From 025dcf09f479087277f3f52ffa92396ea219e783 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Mon, 23 Jun 2014 20:34:45 -0500
Subject: [PATCH 417/629] Fixed default relationship for flagged field, link
field, and views filter.
---
src/Plugin/views/field/FlagViewsFlaggedField.php | 13 +++++++++++++
src/Plugin/views/field/FlagViewsLinkField.php | 2 --
src/Plugin/views/filter/FlagViewsFilter.php | 7 ++++++-
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/Plugin/views/field/FlagViewsFlaggedField.php b/src/Plugin/views/field/FlagViewsFlaggedField.php
index eb267c5..1835bf8 100644
--- a/src/Plugin/views/field/FlagViewsFlaggedField.php
+++ b/src/Plugin/views/field/FlagViewsFlaggedField.php
@@ -29,4 +29,17 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
// flag object, but a) we need to lift that from the relationship we're on
// and b) they will not necessarily make sense in a static context.
}
+
+ protected function defineOptions() {
+ $options = parent::defineOptions();
+ $options['relationship'] = array('default' => 'flag_content_rel');
+
+ return $options;
+ }
+
+ public function buildOptionsForm(&$form, &$form_state) {
+ $form['relationship']['#default_value'] = $this->options['relationship'];
+
+ parent::buildOptionsForm($form, $form_state);
+ }
}
\ No newline at end of file
diff --git a/src/Plugin/views/field/FlagViewsLinkField.php b/src/Plugin/views/field/FlagViewsLinkField.php
index acb1e4b..f261038 100644
--- a/src/Plugin/views/field/FlagViewsLinkField.php
+++ b/src/Plugin/views/field/FlagViewsLinkField.php
@@ -39,9 +39,7 @@ protected function defineOptions() {
// Set the default relationship handler. The first instance of the
// FlagViewsRelationship should always have the id "flag_content_rel", so
// we set that as the default.
- //if (!isset($this->options['relationship'])) {
$options['relationship'] = array('default' => 'flag_content_rel');
- //}
return $options;
}
diff --git a/src/Plugin/views/filter/FlagViewsFilter.php b/src/Plugin/views/filter/FlagViewsFilter.php
index c3fb36c..1f0afcb 100644
--- a/src/Plugin/views/filter/FlagViewsFilter.php
+++ b/src/Plugin/views/filter/FlagViewsFilter.php
@@ -18,11 +18,12 @@ class FlagViewsFilter extends BooleanOperator {
public function defineOptions() {
$options = parent::defineOptions();
$options['value'] = array('default' => 1);
+ $options['relationship'] = array('default' => 'flag_content_rel');
+
return $options;
}
public function buildOptionsForm(&$form, &$form_state) {
- parent::buildOptionsForm($form, $form_state);
$form['value']['#type'] = 'radios';
$form['value']['#title'] = t('Status');
$form['value']['#options'] = array(
@@ -33,6 +34,10 @@ public function buildOptionsForm(&$form, &$form_state) {
);
$form['value']['#default_value'] = empty($this->options['value']) ? '0' : $this->options['value'];
$form['value']['#description'] = '' . t('This filter is only needed if the relationship used has the "Include only flagged content" option unchecked. Otherwise, this filter is useless, because all records are already limited to flagged content.') . '
' . t('By choosing Not flagged, it is possible to create a list of content that is specifically not flagged.', array('@unflagged-url' => 'http://drupal.org/node/299335')) . '
';
+
+ $form['relationship']['#default_value'] = $this->options['relationship'];
+
+ parent::buildOptionsForm($form, $form_state);
}
From c8ed54509293df19658c5f5137ca31abd029b570 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Mon, 23 Jun 2014 21:58:56 -0500
Subject: [PATCH 418/629] Fixed broken Flag delete form, flagging confirm form,
and ConfirmForm link type plugin.
---
...lag.flag_flag.bookmark.yml => flag.flag.bookmark.yml} | 0
src/Form/FlagDeleteForm.php | 5 ++---
src/Form/FlaggingConfirmForm.php | 9 +++++----
src/Plugin/ActionLink/ConfirmForm.php | 6 ++----
4 files changed, 9 insertions(+), 11 deletions(-)
rename flag_bookmark/config/install/{flag.flag_flag.bookmark.yml => flag.flag.bookmark.yml} (100%)
diff --git a/flag_bookmark/config/install/flag.flag_flag.bookmark.yml b/flag_bookmark/config/install/flag.flag.bookmark.yml
similarity index 100%
rename from flag_bookmark/config/install/flag.flag_flag.bookmark.yml
rename to flag_bookmark/config/install/flag.flag.bookmark.yml
diff --git a/src/Form/FlagDeleteForm.php b/src/Form/FlagDeleteForm.php
index fb74c8b..87855e4 100644
--- a/src/Form/FlagDeleteForm.php
+++ b/src/Form/FlagDeleteForm.php
@@ -9,6 +9,7 @@
namespace Drupal\flag\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
+use Drupal\Core\Url;
class FlagDeleteForm extends EntityConfirmFormBase {
@@ -23,9 +24,7 @@ public function getConfirmText() {
}
public function getCancelRoute() {
- return array(
- 'route_name' => 'flag.list',
- );
+ return new URL('flag.list');
}
public function submit(array $form, array &$form_state) {
diff --git a/src/Form/FlaggingConfirmForm.php b/src/Form/FlaggingConfirmForm.php
index 2af1652..4c81d26 100644
--- a/src/Form/FlaggingConfirmForm.php
+++ b/src/Form/FlaggingConfirmForm.php
@@ -9,6 +9,7 @@
namespace Drupal\flag\Form;
use Drupal\Core\Form\ConfirmFormBase;
+use Drupal\Core\Url;
use Drupal\Core\Entity\EntityInterface;
use Drupal\flag\FlagInterface;
@@ -38,10 +39,8 @@ public function getQuestion() {
if ($this->isFlagged()) {
return $linkType->getUnflagQuestion();
}
- else {
- return $linkType->getFlagQuestion();
- }
+ return $linkType->getFlagQuestion();
}
public function getCancelRoute() {
@@ -50,7 +49,9 @@ public function getCancelRoute() {
return URL::createFromPath($destination);
}
- return $this->entity->urlInfo();
+ $route_name = $this->entity->urlInfo();
+
+ return new URL($route_name['canonical']);
}
public function getDescription() {
diff --git a/src/Plugin/ActionLink/ConfirmForm.php b/src/Plugin/ActionLink/ConfirmForm.php
index e3c45d2..9812f60 100644
--- a/src/Plugin/ActionLink/ConfirmForm.php
+++ b/src/Plugin/ActionLink/ConfirmForm.php
@@ -33,10 +33,8 @@ public function routeName($action = NULL) {
public function defaultConfiguration() {
$options = parent::defaultConfiguration();
- $options += array(
- 'flag_confirmation' => 'Flag this content?',
- 'unflag_confirmation' => 'Unflag this content?',
- );
+ $options['flag_confirmation'] = 'Flag this content?';
+ $options['unflag_confirmation'] = 'Unflag this content?';
return $options;
}
From 24edb5fd5a908c5fba51de1b4b4a107a15120b48 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Tue, 24 Jun 2014 13:48:58 +0200
Subject: [PATCH 419/629] Corrected the return of duplicate occurences of some
entity flag types.
---
src/FlagTypePluginManager.php | 15 ++++++---
src/Plugin/Derivative/EntityFlagType.php | 40 ++++++++++++++++++------
src/Plugin/Flag/CommentFlagType.php | 3 +-
src/Plugin/Flag/NodeFlagType.php | 3 +-
src/Plugin/Flag/UserFlagType.php | 5 +--
5 files changed, 48 insertions(+), 18 deletions(-)
diff --git a/src/FlagTypePluginManager.php b/src/FlagTypePluginManager.php
index 8485eaf..867a190 100644
--- a/src/FlagTypePluginManager.php
+++ b/src/FlagTypePluginManager.php
@@ -32,14 +32,21 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
$this->setCacheBackend($cache_backend, 'flag');
}
+ /**
+ * Gets all flag types.
+ *
+ * @return array
+ * Returns all flag types.
+ */
public function getAllFlagTypes() {
- $flagTypes = array();
+ $flag_types = array();
- foreach ($this->getDefinitions() as $pluginID => $pluginDef) {
- $flagTypes[$pluginID] = t($pluginDef['title']);
+ foreach ($this->getDefinitions() as $plugin_id => $plugin_def) {
+ $flag_types[$plugin_id] = $plugin_def['title'];
}
+ asort($flag_types);
- return $flagTypes;
+ return $flag_types;
}
}
\ No newline at end of file
diff --git a/src/Plugin/Derivative/EntityFlagType.php b/src/Plugin/Derivative/EntityFlagType.php
index 9fb25df..bb675e9 100644
--- a/src/Plugin/Derivative/EntityFlagType.php
+++ b/src/Plugin/Derivative/EntityFlagType.php
@@ -1,27 +1,47 @@
getDefinitions() as $entity_id => $entity_info) {
+ foreach (\Drupal::entityManager()->getDefinitions() as $entity_id => $entity_type) {
+ if (in_array($entity_id, $this->ignoredEntities)) {
+ continue;
+ }
$derivatives[$entity_id] = array(
- 'title' => $entity_id,
+ 'title' => $entity_type->getLabel(),
'entity_type' => $entity_id,
) + $base_plugin_def;
}
diff --git a/src/Plugin/Flag/CommentFlagType.php b/src/Plugin/Flag/CommentFlagType.php
index e8115f3..a223a67 100644
--- a/src/Plugin/Flag/CommentFlagType.php
+++ b/src/Plugin/Flag/CommentFlagType.php
@@ -19,7 +19,8 @@
* @FlagType(
* id = "flagtype_comment",
* title = @Translation("Comment"),
- * entity_type = "comment"
+ * entity_type = "comment",
+ * provider = "comment"
* )
*/
class CommentFlagType extends EntityFlagType {
diff --git a/src/Plugin/Flag/NodeFlagType.php b/src/Plugin/Flag/NodeFlagType.php
index 2fbd1ac..e97fe9b 100644
--- a/src/Plugin/Flag/NodeFlagType.php
+++ b/src/Plugin/Flag/NodeFlagType.php
@@ -19,7 +19,8 @@
* @FlagType(
* id = "flagtype_node",
* title = @Translation("Content"),
- * entity_type = "node"
+ * entity_type = "node",
+ * provider = "node"
* )
*/
class NodeFlagType extends EntityFlagType {
diff --git a/src/Plugin/Flag/UserFlagType.php b/src/Plugin/Flag/UserFlagType.php
index 014ef7d..975fca7 100644
--- a/src/Plugin/Flag/UserFlagType.php
+++ b/src/Plugin/Flag/UserFlagType.php
@@ -17,7 +17,8 @@
* @FlagType(
* id = "flagtype_user",
* title = @Translation("User"),
- * entity_type = "user"
+ * entity_type = "user",
+ * provider = "user"
* )
*/
class UserFlagType extends FlagTypeBase {
@@ -87,6 +88,6 @@ public function getAccessUidSetting() {
}
public function showOnProfile() {
- return this->configuration['show_on_profile'];
+ return $this->configuration['show_on_profile'];
}
}
\ No newline at end of file
From e6a2f367fb211bf24e2c51195ddf0a3ccdf6d50f Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Tue, 24 Jun 2014 14:04:00 +0200
Subject: [PATCH 420/629] Initial versio of basic tests.
---
flag.module | 2 +-
src/Tests/FlagSimpleTest.php | 107 +++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+), 1 deletion(-)
create mode 100644 src/Tests/FlagSimpleTest.php
diff --git a/flag.module b/flag.module
index 223abf2..a37ef0a 100644
--- a/flag.module
+++ b/flag.module
@@ -720,7 +720,7 @@ function _flag_entity_delete($entity_type, $entity_id, $fid = NULL) {
/**
* Implements hook_user_login().
*/
-function flag_user_login(&$edit, &$account) {
+function flag_user_login($account) {
// Migrate anonymous flags to this user's account.
if (module_exists('session_api') && ($sid = flag_get_sid(0))) {
// Get a list of flagging IDs that will be moved over.
diff --git a/src/Tests/FlagSimpleTest.php b/src/Tests/FlagSimpleTest.php
new file mode 100644
index 0000000..09d4112
--- /dev/null
+++ b/src/Tests/FlagSimpleTest.php
@@ -0,0 +1,107 @@
+ 'Flag form/s',
+ 'description' => 'Creates a flag, adds flag to node.',
+ 'group' => 'Flag',
+ );
+ }
+
+ /**
+ * Configures test base and executes test cases.
+ */
+ public function testFlagForm() {
+ // Create and log in our user.
+ $admin_user = $this->drupalCreateUser(array(
+ 'administer flags',
+ ));
+ $this->drupalLogin($admin_user);
+ $this->drupalCreateContentType(array('type' => 'article'));
+ $this->doTestFlagAdd();
+ }
+
+ /**
+ * Flag creation.
+ */
+ public function doTestFlagAdd() {
+ // First, test with minimal value requirement.
+ $edit = array(
+ 'label' => $this->label,
+ 'id' => $this->id,
+ );
+ $this->drupalPostForm('/admin/structure/flags/add', $edit, t('Continue'));
+ // Check for fieldset titles.
+ $this->assertText(t('Messages'));
+ $this->assertText(t('Flag access'));
+ $this->assertText(t('Display options'));
+
+ $edit = array(
+ 'types[' . $this->flaggableTypes . ']' => $this->flaggableTypes,
+ );
+ $this->drupalPostForm(NULL, $edit, t('Create Flag'));
+
+ $this->assertText(t('Flag @this_label has been added.', array('@this_label' => $this->label)));
+
+ }
+
+ /**
+ * Node creation and flagging.
+ */
+
+}
From 0a0e8860d5e75b08465e1dfbf0e31edd61e52d31 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Wed, 25 Jun 2014 10:18:13 +0200
Subject: [PATCH 421/629] Provided basic tests and added documentation for
changed code.
---
src/Entity/Flag.php | 16 +++++++++++--
src/FlagInterface.php | 16 +++++++++++++
src/FlaggingAccessController.php | 41 ++++++++++++++++++++------------
src/Tests/FlagSimpleTest.php | 27 +++++++++++++++++----
4 files changed, 79 insertions(+), 21 deletions(-)
diff --git a/src/Entity/Flag.php b/src/Entity/Flag.php
index 3289944..a883f4d 100644
--- a/src/Entity/Flag.php
+++ b/src/Entity/Flag.php
@@ -14,8 +14,6 @@
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
-use Drupal\Core\Entity\Annotation\EntityType;
-use Drupal\Core\Annotation\Translation;
use Drupal\flag\FlagInterface;
/**
@@ -308,6 +306,20 @@ function getPermissions() {
);
}
+ /**
+ * {@inheritdoc}.
+ */
+ public function hasActionAccess($action, AccountInterface $account = NULL) {
+ if ($action === 'flag' || $action === 'unflag') {
+ $account = $account ?: \Drupal::currentUser();
+ return $account->hasPermission($action . ' ' . $this->id);
+ }
+ else {
+ // @todo: Is this the correct response?
+ return FALSE;
+ }
+ }
+
public function isGlobal() {
return $this->is_global;
}
diff --git a/src/FlagInterface.php b/src/FlagInterface.php
index fafd458..a40a2ff 100644
--- a/src/FlagInterface.php
+++ b/src/FlagInterface.php
@@ -30,4 +30,20 @@ public function isGlobal();
public function setGlobal($isGlobal);
public function getPluginBags();
+
+ /**
+ * User access permission for flagging actions.
+ *
+ * Checks whether a user has permission to flag/unflag or not.
+ *
+ * @param string $action
+ * An indicator flag.
+ * @param AccountInterface $account
+ * (optional) An AccountInterface object.
+ *
+ * @return bool|null
+ * Returns a bool defining the users access permission for flagging action.
+ */
+ public function hasActionAccess($action, AccountInterface $account = NULL);
+
}
\ No newline at end of file
diff --git a/src/FlaggingAccessController.php b/src/FlaggingAccessController.php
index e2c0ce1..bc70b14 100644
--- a/src/FlaggingAccessController.php
+++ b/src/FlaggingAccessController.php
@@ -1,27 +1,33 @@
get('entity_id');
-
- if (user_access('flag' . $entity_id)) {
+ $flag = Flag::load($request->get('flag_id'));
+ if ($flag->hasActionAccess('flag')) {
return AccessInterface::ALLOW;
}
@@ -29,16 +35,21 @@ public function checkFlag(Request $request) {
}
/**
+ * Checks unflagging permission.
*
+ * @param Request $request
+ * The request object.
+ *
+ * @return string
+ * Returns indication value for unflagging access permission.
*/
public function checkUnflag(Request $request) {
- $entity_id = $request->get('entity_id');
-
- if (user_access('unflag' . $entity_id)) {
+ $flag = Flag::load($request->get('flag_id'));
+ if ($flag->hasActionAccess('unflag')) {
return AccessInterface::ALLOW;
}
return AccessInterface::DENY;
}
-}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/Tests/FlagSimpleTest.php b/src/Tests/FlagSimpleTest.php
index 09d4112..97d3bb4 100644
--- a/src/Tests/FlagSimpleTest.php
+++ b/src/Tests/FlagSimpleTest.php
@@ -33,7 +33,7 @@ class FlagSimpleTest extends WebTestBase {
/**
* @var string
*/
- protected $flaggableTypes = 'article';
+ protected $nodeType = 'article';
/**
* @var string
@@ -72,7 +72,6 @@ public function testFlagForm() {
'administer flags',
));
$this->drupalLogin($admin_user);
- $this->drupalCreateContentType(array('type' => 'article'));
$this->doTestFlagAdd();
}
@@ -80,7 +79,10 @@ public function testFlagForm() {
* Flag creation.
*/
public function doTestFlagAdd() {
- // First, test with minimal value requirement.
+ // Create content type.
+ $this->drupalCreateContentType(array('type' => $this->nodeType));
+
+ // Test with minimal value requirement.
$edit = array(
'label' => $this->label,
'id' => $this->id,
@@ -92,16 +94,33 @@ public function doTestFlagAdd() {
$this->assertText(t('Display options'));
$edit = array(
- 'types[' . $this->flaggableTypes . ']' => $this->flaggableTypes,
+ 'types[' . $this->nodeType . ']' => $this->nodeType,
);
$this->drupalPostForm(NULL, $edit, t('Create Flag'));
$this->assertText(t('Flag @this_label has been added.', array('@this_label' => $this->label)));
+ // Continue test process.
+ $this->doTestCreateNodeAndFlagIt();
}
/**
* Node creation and flagging.
*/
+ public function doTestCreateNodeAndFlagIt() {
+ $node = $this->drupalCreateNode(array('type' => $this->nodeType));
+ $node_id = $node->id();
+
+ // Now that permissions have been created for this node, create and login
+ // new user.
+ $node_user = $this->drupalCreateUser(array(
+ 'flag ' . $this->id,
+ 'unflag ' . $this->id,
+ ));
+ $this->drupalLogin($node_user);
+ $this->drupalGet('/node/' . $node_id);
+ $this->clickLink('Flag this item');
+ $this->clickLink('Unflag this item');
+ }
}
From f13675bd73f57a644af4bd46a1af08f9dc5a5587 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Wed, 25 Jun 2014 12:21:43 +0200
Subject: [PATCH 422/629] Fixed caching issue in basic tests, created
permission role instead of multiple permission settings.
---
flag.module | 29 +++++++++++++++++++++++++++++
src/Entity/Flag.php | 1 -
src/Entity/Flagging.php | 2 --
src/Tests/FlagSimpleTest.php | 34 +++++++++++++++++++++++++++-------
4 files changed, 56 insertions(+), 10 deletions(-)
diff --git a/flag.module b/flag.module
index a37ef0a..5c69e2d 100644
--- a/flag.module
+++ b/flag.module
@@ -10,6 +10,7 @@ define('FLAG_API_VERSION', 3);
define('FLAG_ADMIN_PATH', 'admin/structure/flags');
define('FLAG_ADMIN_PATH_START', 3);
+use Drupal\entity\Entity\EntityViewDisplay;
use Drupal\flag\Flag;
use Drupal\node\NodeInterface;
use Drupal\Core\Entity\EntityInterface;
@@ -600,6 +601,34 @@ function flag_entity_view(array &$build, EntityInterface $entity,
}
}
+/**
+ * Implements hook_entity_build_defaults_alter().
+ */
+function flag_entity_build_defaults_alter(array &$build, EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
+ // Get the corresponding display settings.
+ // $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
+ // Add the flag ID combined with the action to the cache key if render
+ // caching is enabled.
+ if (isset($build['#cache']) && isset($build['#cache']['keys'])) {
+
+ // Get all possible flags for this entity type.
+ $flag_service = \Drupal::service('flag');
+ $flags = $flag_service->getFlags($entity->getEntityTypeID(),
+ $entity->bundle());
+
+ foreach ($flags as $flag) {
+ $action = 'flag';
+
+ if ($flag->isFlagged($entity)) {
+ $action = 'unflag';
+ }
+
+ $build['#cache']['keys'][] = $flag->id . '-' . $action;
+ }
+ }
+ return $build;
+}
+
/**
* Implements hook_node_insert().
*/
diff --git a/src/Entity/Flag.php b/src/Entity/Flag.php
index a883f4d..02d4481 100644
--- a/src/Entity/Flag.php
+++ b/src/Entity/Flag.php
@@ -9,7 +9,6 @@
namespace Drupal\flag\Entity;
use Drupal\Core\Plugin\DefaultSinglePluginBag;
-use Drupal\Compontent\Plugin\ConfigurablePluginInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Config\Entity\ConfigEntityBase;
diff --git a/src/Entity/Flagging.php b/src/Entity/Flagging.php
index 8ebe1ec..fa6c70b 100644
--- a/src/Entity/Flagging.php
+++ b/src/Entity/Flagging.php
@@ -11,8 +11,6 @@
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityStorageControllerInterface;
-use Drupal\Core\Language\Language;
-use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Field\FieldDefinition;
use Drupal\flag\FlaggingInterface;
diff --git a/src/Tests/FlagSimpleTest.php b/src/Tests/FlagSimpleTest.php
index 97d3bb4..5a3c240 100644
--- a/src/Tests/FlagSimpleTest.php
+++ b/src/Tests/FlagSimpleTest.php
@@ -8,6 +8,7 @@
namespace Drupal\flag\Tests;
use Drupal\simpletest\WebTestBase;
+use Drupal\user\Entity\Role;
/**
@@ -111,16 +112,35 @@ public function doTestCreateNodeAndFlagIt() {
$node = $this->drupalCreateNode(array('type' => $this->nodeType));
$node_id = $node->id();
- // Now that permissions have been created for this node, create and login
- // new user.
- $node_user = $this->drupalCreateUser(array(
- 'flag ' . $this->id,
- 'unflag ' . $this->id,
- ));
- $this->drupalLogin($node_user);
+ // Grant the flag permissions to the authenticated role, so that both
+ // users have the same roles and share the render cache.
+ $role = Role::load(DRUPAL_AUTHENTICATED_RID);
+ $role->grantPermission('flag ' . $this->id);
+ $role->grantPermission('unflag ' . $this->id);
+ $role->save();
+
+ // Create and login a new user.
+ $user_1 = $this->drupalCreateUser();
+ $this->drupalLogin($user_1);
$this->drupalGet('/node/' . $node_id);
$this->clickLink('Flag this item');
+ $this->assertResponse(200);
+ $this->assertLink('Unflag this item');
+
+ // Switch user to check flagging link.
+ $user_2 = $this->drupalCreateUser();
+ $this->drupalLogin($user_2);
+ $this->drupalGet('/node/' . $node_id);
+ $this->assertResponse(200);
+ $this->assertLink('Flag this item');
+
+ // Switch back to first user and unflag.
+ $this->drupalLogin($user_1);
+ $this->drupalGet('/node/' . $node_id);
+
$this->clickLink('Unflag this item');
+ $this->assertResponse(200);
+ $this->assertLink('Flag this item');
}
}
From 94aadbf03e1ebd81897b321396d6ab91f71bdb14 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Wed, 25 Jun 2014 12:35:11 +0200
Subject: [PATCH 423/629] Removed unused Entity display.
---
flag.module | 3 ---
1 file changed, 3 deletions(-)
diff --git a/flag.module b/flag.module
index 5c69e2d..3d1987f 100644
--- a/flag.module
+++ b/flag.module
@@ -10,7 +10,6 @@ define('FLAG_API_VERSION', 3);
define('FLAG_ADMIN_PATH', 'admin/structure/flags');
define('FLAG_ADMIN_PATH_START', 3);
-use Drupal\entity\Entity\EntityViewDisplay;
use Drupal\flag\Flag;
use Drupal\node\NodeInterface;
use Drupal\Core\Entity\EntityInterface;
@@ -605,8 +604,6 @@ function flag_entity_view(array &$build, EntityInterface $entity,
* Implements hook_entity_build_defaults_alter().
*/
function flag_entity_build_defaults_alter(array &$build, EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
- // Get the corresponding display settings.
- // $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
// Add the flag ID combined with the action to the cache key if render
// caching is enabled.
if (isset($build['#cache']) && isset($build['#cache']['keys'])) {
From 1179d343d30ac2748eddaadd7dbd1c1977e2887c Mon Sep 17 00:00:00 2001
From: Andy Postnikov
Date: Wed, 25 Jun 2014 14:41:37 +0400
Subject: [PATCH 424/629] Clean-up Flag entity doc blocks
---
src/Entity/Flag.php | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/src/Entity/Flag.php b/src/Entity/Flag.php
index 3289944..4ed07f7 100644
--- a/src/Entity/Flag.php
+++ b/src/Entity/Flag.php
@@ -1,21 +1,16 @@
getFlagTypePlugin();
@@ -361,4 +356,4 @@ public function toArray() {
return $properties;
}
-}
\ No newline at end of file
+}
From be3b43f0cc07da605e4b8efcb241ce51ef234123 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Wed, 25 Jun 2014 16:56:38 +0200
Subject: [PATCH 425/629] Converted hook_help() paths to routes.
---
flag.module | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/flag.module b/flag.module
index 223abf2..4f323ab 100644
--- a/flag.module
+++ b/flag.module
@@ -14,6 +14,7 @@ use Drupal\flag\Flag;
use Drupal\node\NodeInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
+use Symfony\Component\HttpFoundation\Request;
// @todo: Implement flagging_view(). Not extremely useful. I already have it.
@@ -156,15 +157,18 @@ function flag_load($flag_name, $include_disabled = FALSE) {
/**
* Implements hook_help().
*/
-function flag_help($path, $arg) {
- switch ($path) {
- case FLAG_ADMIN_PATH:
+function flag_help($route_name, Request $request) {
+ switch ($route_name) {
+ case 'flag.list':
$output = '' . t('This page lists all the flags that are currently defined on this system.') . '
';
return $output;
- case FLAG_ADMIN_PATH . '/add':
+ case 'flag.add_page':
$output = '' . t('Select the type of flag to create. An individual flag can only affect one type of object. This cannot be changed once the flag is created.') . '
';
return $output;
- case FLAG_ADMIN_PATH . '/manage/%/fields':
+ case 'field_ui.overview_flagging':
+ // @todo: Doesn't make sense at the moment, implement when form
+ // functionality is available.
+ /*
// Get the existing link types that provide a flagging form.
$link_types = flag_get_link_types();
$form_link_types = array();
@@ -221,6 +225,7 @@ function flag_help($path, $arg) {
}
return $output;
+ */
}
}
From 0fbc2ae818547debcf0e40325c1a309afad7aaaa Mon Sep 17 00:00:00 2001
From: yanniboi
Date: Wed, 25 Jun 2014 16:19:23 +0100
Subject: [PATCH 426/629] Fixed a type on UserFlagType.
---
src/Plugin/Flag/UserFlagType.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Plugin/Flag/UserFlagType.php b/src/Plugin/Flag/UserFlagType.php
index 014ef7d..e2e5256 100644
--- a/src/Plugin/Flag/UserFlagType.php
+++ b/src/Plugin/Flag/UserFlagType.php
@@ -87,6 +87,6 @@ public function getAccessUidSetting() {
}
public function showOnProfile() {
- return this->configuration['show_on_profile'];
+ return $this->configuration['show_on_profile'];
}
-}
\ No newline at end of file
+}
From af75dc4f6522aba57abda7b628324d2f45fd4f28 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Thu, 26 Jun 2014 17:18:59 +0200
Subject: [PATCH 427/629] Added tests and now checks that cache key is only
added if flag is displayed.
---
flag.module | 49 +++++++++++++++------------
src/Entity/Flag.php | 3 ++
src/Tests/FlagSimpleTest.php | 65 ++++++++++++++++++++++++++++--------
3 files changed, 81 insertions(+), 36 deletions(-)
diff --git a/flag.module b/flag.module
index 3d1987f..2e94df3 100644
--- a/flag.module
+++ b/flag.module
@@ -10,6 +10,7 @@ define('FLAG_API_VERSION', 3);
define('FLAG_ADMIN_PATH', 'admin/structure/flags');
define('FLAG_ADMIN_PATH_START', 3);
+use Drupal\entity\Entity\EntityViewDisplay;
use Drupal\flag\Flag;
use Drupal\node\NodeInterface;
use Drupal\Core\Entity\EntityInterface;
@@ -323,11 +324,10 @@ function flag_flag_link($flag, $action, $entity_id) {
}
/**
- * Implements hook_field_extra_fields().
+ * Implements hook_entity_extra_field_info().
*/
-function flag_field_extra_fields() {
+function flag_entity_extra_field_info() {
$extra = array();
-
$flag_service = \Drupal::service('flag');
$flags = $flag_service->getFlags();
foreach ($flags as $flag) {
@@ -342,12 +342,12 @@ function flag_field_extra_fields() {
$extra[$flag->entity_type][$bundle_name]['form']['flag'] = array(
'label' => t('Flags'),
'description' => t('Checkboxes for toggling flags'),
- 'weight' => 10
+ 'weight' => 10,
);
}
if ($flagTypePlugin->showAsField()) {
- $extra[$flag->entity_type][$bundle_name]['display']['flag_' . $flag->label()] = array(
+ $extra[$flag->entity_type][$bundle_name]['display']['flag_' . $flag->id()] = array(
// It would be nicer to use % as the placeholder, but the label is
// run through check_plain() by field_ui_display_overview_form()
// (arguably incorrectly; see http://drupal.org/node/1991292).
@@ -571,32 +571,28 @@ function flag_field_attach_save($entity_type, $entity) {
* Implements hook_entity_view().
*
* Handles the 'show_in_links' and 'show_as_field' flag options.
- *
- * Note this is broken for taxonomy terms for version of Drupal core < 7.17.
*/
-function flag_entity_view(array &$build, EntityInterface $entity,
- EntityViewDisplayInterface $display,
- $view_mode, $langcode) {
-
-
- //@todo Check $type->getComponent('flag_whateverHookFieldExtraFieldsIS').
- // if not NULL, display it.
-
+function flag_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode) {
// Get all possible flags for this entity type.
$flag_service = \Drupal::service('flag');
- $flags = $flag_service->getFlags($entity->getEntityTypeID(),
- $entity->bundle());
+ $flags = $flag_service->getFlags($entity->getEntityTypeID(), $entity->bundle());
foreach ($flags as $flag) {
- $linkTypePlugin = $flag->getLinkTypePlugin();
- $action = 'flag';
+ $link_type_plugin = $flag->getLinkTypePlugin();
+ $flag_type_plugin = $flag->getFlagTypePlugin();
+
+ // Only add cache key if flag link is displayed.
+ if ($flag_type_plugin->showAsField() && !$display->getComponent('flag_' . $flag->id())) {
+ continue;
+ }
+ $action = 'flag';
if ($flag->isFlagged($entity)) {
$action = 'unflag';
}
- $link = $linkTypePlugin->renderLink($action, $flag, $entity);
- $build['flag_' . $flag->id] = $link;
+ $link = $link_type_plugin->renderLink($action, $flag, $entity);
+ $build['flag_' . $flag->id()] = $link;
}
}
@@ -613,9 +609,18 @@ function flag_entity_build_defaults_alter(array &$build, EntityInterface $entity
$flags = $flag_service->getFlags($entity->getEntityTypeID(),
$entity->bundle());
+ // Get the corresponding display settings.
+ $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
+
foreach ($flags as $flag) {
- $action = 'flag';
+ $flag_type_plugin = $flag->getFlagTypePlugin();
+
+ // Only add cache key if flag link is displayed.
+ if ($flag_type_plugin->showAsField() && !$display->getComponent('flag_' . $flag->id())) {
+ continue;
+ }
+ $action = 'flag';
if ($flag->isFlagged($entity)) {
$action = 'unflag';
}
diff --git a/src/Entity/Flag.php b/src/Entity/Flag.php
index 02d4481..69887bf 100644
--- a/src/Entity/Flag.php
+++ b/src/Entity/Flag.php
@@ -354,6 +354,9 @@ public function preSave(EntityStorageInterface $storage_controller) {
\Drupal::entityManager()
->getViewBuilder($this->getFlaggableEntityType())
->resetCache();
+ // Clear entity extra field caches.
+ \Drupal::entityManager()->clearCachedFieldDefinitions();
+
}
public function toArray() {
diff --git a/src/Tests/FlagSimpleTest.php b/src/Tests/FlagSimpleTest.php
index 5a3c240..a41c2db 100644
--- a/src/Tests/FlagSimpleTest.php
+++ b/src/Tests/FlagSimpleTest.php
@@ -32,26 +32,25 @@ class FlagSimpleTest extends WebTestBase {
protected $flagLinkType;
/**
+ *
+ *
* @var string
*/
protected $nodeType = 'article';
/**
- * @var string
- */
- protected $flag_confirmation = 'Are you sure you want to flag this content?';
-
- /**
- * @var string
+ * User object.
+ *
+ * @var \Drupal\user\Entity\User|false
*/
- protected $unflag_confirmation = 'Are you sure you want to unflag this content?';
+ protected $adminUser;
/**
* Modules to enable.
*
* @var array
*/
- public static $modules = array('flag', 'node');
+ public static $modules = array('views', 'flag', 'node', 'field_ui');
/**
* {@inheritdoc}
@@ -69,11 +68,15 @@ public static function getInfo() {
*/
public function testFlagForm() {
// Create and log in our user.
- $admin_user = $this->drupalCreateUser(array(
+ $this->adminUser = $this->drupalCreateUser(array(
'administer flags',
+ 'administer node display',
));
- $this->drupalLogin($admin_user);
+
+ $this->drupalLogin($this->adminUser);
+
$this->doTestFlagAdd();
+ $this->doTestHideFlagLinkFromTeaser();
}
/**
@@ -88,7 +91,7 @@ public function doTestFlagAdd() {
'label' => $this->label,
'id' => $this->id,
);
- $this->drupalPostForm('/admin/structure/flags/add', $edit, t('Continue'));
+ $this->drupalPostForm('admin/structure/flags/add', $edit, t('Continue'));
// Check for fieldset titles.
$this->assertText(t('Messages'));
$this->assertText(t('Flag access'));
@@ -123,7 +126,7 @@ public function doTestCreateNodeAndFlagIt() {
$user_1 = $this->drupalCreateUser();
$this->drupalLogin($user_1);
- $this->drupalGet('/node/' . $node_id);
+ $this->drupalGet('node/' . $node_id);
$this->clickLink('Flag this item');
$this->assertResponse(200);
$this->assertLink('Unflag this item');
@@ -131,16 +134,50 @@ public function doTestCreateNodeAndFlagIt() {
// Switch user to check flagging link.
$user_2 = $this->drupalCreateUser();
$this->drupalLogin($user_2);
- $this->drupalGet('/node/' . $node_id);
+ $this->drupalGet('node/' . $node_id);
$this->assertResponse(200);
$this->assertLink('Flag this item');
// Switch back to first user and unflag.
$this->drupalLogin($user_1);
- $this->drupalGet('/node/' . $node_id);
+ $this->drupalGet('node/' . $node_id);
$this->clickLink('Unflag this item');
$this->assertResponse(200);
$this->assertLink('Flag this item');
}
+
+ /**
+ * Node creation and flag link.
+ */
+ public function doTestHideFlagLinkFromTeaser() {
+ $this->drupalLogin($this->adminUser);
+
+ $node = $this->drupalCreateNode(array(
+ 'type' => $this->nodeType,
+ 'promote' => TRUE,
+ ));
+ $node_id = $node->id();
+ $node_title = $node->getTitle();
+
+ $this->drupalGet('node');
+ $this->assertText($node_title);
+ $this->assertLink('Flag this item');
+
+ // Set flag format to hidden for teaser display and post form.
+ $edit = array(
+ 'fields[flag_' . $this->id . '][type]' => 'hidden',
+ );
+
+ $this->drupalPostForm('admin/structure/types/manage/' . $this->nodeType . '/display/teaser', $edit, t('Save'));
+
+ // Check if form is saved successfully.
+ $this->assertText('Your settings have been saved.');
+
+ $this->drupalGet('node');
+ $this->assertText($node_title);
+ $this->assertNoLink('Flag this item');
+
+ $this->drupalGet('node/' . $node_id);
+ }
}
From 433d1ccc55f7b17d099b95b6189dde4e1d6d88fc Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Fri, 27 Jun 2014 12:45:37 +0200
Subject: [PATCH 428/629] Fixed error on/admin/structure/types/manage/page
(temporary solution, see @todo) and replaced non-existent functions
canFlag/canUnflag with hasActionAccess.
---
flag.module | 6 ++++--
src/FlagService.php | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/flag.module b/flag.module
index fb0dbd7..ab971cb 100644
--- a/flag.module
+++ b/flag.module
@@ -374,9 +374,11 @@ function flag_entity_extra_field_info() {
*/
function flag_form_node_type_form_alter(&$form, &$form_state, $form_id) {
global $user;
- $flags = \Drupal::service('flag')->getFlags('node', $form['#node_type']->type, $user);
+ $node_type = $form_state['controller']->getEntity();
+ $flags = \Drupal::service('flag')->getFlags('node', $node_type->id(), $user);
foreach ($flags as $flag) {
- if ($flag->show_on_form) {
+ // @todo: Revisit when form functionality is implemented.
+ if (!empty($flag->show_on_form)) {
// To be able to process node tokens in flag labels, we create a fake
// node and store it in the flag's cache for replace_tokens() to find,
// with a fake ID.
diff --git a/src/FlagService.php b/src/FlagService.php
index fe38a39..5b5f901 100644
--- a/src/FlagService.php
+++ b/src/FlagService.php
@@ -86,7 +86,7 @@ public function getFlags($entity_type = NULL, $bundle = NULL, AccountInterface $
$filtered_flags = array();
foreach ($flags as $flag) {
- if ($flag->canFlag($account) || $flag->canUnflag($account)) {
+ if ($flag->hasActionAccess('flag ' . $flag->id(), $account) || $flag->hasActionAccess('unflag ' . $flag->id(), $account)) {
$filtered_flags[] = $flag;
}
}
From c4b3cd17b82c2a9e62384cfbbe4ad06b4742b012 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Sun, 29 Jun 2014 21:35:53 -0500
Subject: [PATCH 429/629] Added basic events support for flag, unflag, and
delete.
---
src/Entity/Flag.php | 11 +++++++++++
src/Event/FlagDeleteEvent.php | 19 +++++++++++++++++++
src/Event/FlagEventBase.php | 23 +++++++++++++++++++++++
src/Event/FlagEvents.php | 22 ++++++++++++++++++++++
src/Event/FlaggingEvent.php | 27 +++++++++++++++++++++++++++
src/FlagService.php | 9 +++++++++
6 files changed, 111 insertions(+)
create mode 100644 src/Event/FlagDeleteEvent.php
create mode 100644 src/Event/FlagEventBase.php
create mode 100644 src/Event/FlagEvents.php
create mode 100644 src/Event/FlaggingEvent.php
diff --git a/src/Entity/Flag.php b/src/Entity/Flag.php
index fc52453..0d877f6 100644
--- a/src/Entity/Flag.php
+++ b/src/Entity/Flag.php
@@ -11,6 +11,8 @@
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\flag\Event\FlagDeleteEvent;
+use Drupal\flag\Event\FlagEvents;
use Drupal\flag\FlagInterface;
/**
@@ -357,6 +359,15 @@ public function preSave(EntityStorageInterface $storage) {
}
+ public static function preDelete(EntityStorageInterface $storage, array $entities) {
+ parent::preDelete($storage, $entities);
+
+ foreach ($entities as $entity) {
+ \Drupal::service('event_dispatcher')
+ ->dispatch(FlagEvents::FLAG_DELETED, new FlagDeleteEvent($entity));
+ }
+ }
+
public function toArray() {
$properties = parent::toArray();
$names = array(
diff --git a/src/Event/FlagDeleteEvent.php b/src/Event/FlagDeleteEvent.php
new file mode 100644
index 0000000..b1ba5cf
--- /dev/null
+++ b/src/Event/FlagDeleteEvent.php
@@ -0,0 +1,19 @@
+flag = $flag;
+ }
+
+}
\ No newline at end of file
diff --git a/src/Event/FlagEvents.php b/src/Event/FlagEvents.php
new file mode 100644
index 0000000..65a2709
--- /dev/null
+++ b/src/Event/FlagEvents.php
@@ -0,0 +1,22 @@
+entity = $entity;
+ $this->action = $action;
+ }
+
+}
\ No newline at end of file
diff --git a/src/FlagService.php b/src/FlagService.php
index 5b5f901..059f0be 100644
--- a/src/FlagService.php
+++ b/src/FlagService.php
@@ -10,6 +10,8 @@
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface;
+use Drupal\flag\Event\FlagEvents;
+use Drupal\flag\Event\FlaggingEvent;
use Drupal\flag\FlagInterface;
use Drupal\Core\Entity\EntityInterface;
@@ -143,6 +145,9 @@ public function flagByObject(FlagInterface $flag, EntityInterface $entity, Accou
$entity,
));
+ \Drupal::service('event_dispatcher')
+ ->dispatch(FlagEvents::ENTITY_FLAGGED, new FlaggingEvent($flag, $entity, 'flag'));
+
return $flagging;
}
@@ -190,6 +195,10 @@ public function unflag($flag_id, $entity_id, AccountInterface $account = NULL) {
public function unflagByObject(FlagInterface $flag,
EntityInterface $entity,
AccountInterface $account = NULL) {
+
+ \Drupal::service('event_dispatcher')
+ ->dispatch(FlagEvents::ENTITY_UNFLAGGED, new FlaggingEvent($flag, $entity, 'unflag'));
+
$out = array();
$flaggings = $this->getFlaggings($entity, $flag);
foreach ($flaggings as $flagging) {
From 6a258e7cbc5978abffa7b767e07bf83fe014fa5f Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Wed, 2 Jul 2014 09:53:52 +0200
Subject: [PATCH 430/629] Added permission check for flag link.
---
flag.module | 4 ++++
src/Tests/FlagSimpleTest.php | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/flag.module b/flag.module
index ab971cb..6ba3ed8 100644
--- a/flag.module
+++ b/flag.module
@@ -597,6 +597,10 @@ function flag_entity_view(array &$build, EntityInterface $entity, EntityViewDisp
if ($flag->isFlagged($entity)) {
$action = 'unflag';
}
+ //
+ if(!$flag->hasActionAccess($action)){
+ continue;
+ }
$link = $link_type_plugin->renderLink($action, $flag, $entity);
$build['flag_' . $flag->id()] = $link;
diff --git a/src/Tests/FlagSimpleTest.php b/src/Tests/FlagSimpleTest.php
index a41c2db..79ff128 100644
--- a/src/Tests/FlagSimpleTest.php
+++ b/src/Tests/FlagSimpleTest.php
@@ -145,6 +145,10 @@ public function doTestCreateNodeAndFlagIt() {
$this->clickLink('Unflag this item');
$this->assertResponse(200);
$this->assertLink('Flag this item');
+
+ $this->drupalLogout();
+ $this->drupalGet('node/' . $node_id);
+ $this->assertNoLink('Flag this item');
}
/**
From 0c0b471f14a621c348a44803ee7ab34955c7f620 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Wed, 2 Jul 2014 15:50:21 +0200
Subject: [PATCH 431/629] Fixed flag (and flag count) deletion when node is
deleted. Fixed saving/updating/deleting flag counts.
---
flag.install | 4 +--
flag.module | 5 ++-
src/FlagService.php | 81 ++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 81 insertions(+), 9 deletions(-)
diff --git a/flag.install b/flag.install
index 3e7100b..9992e0b 100644
--- a/flag.install
+++ b/flag.install
@@ -15,8 +15,8 @@ function flag_schema() {
'description' => 'The number of times an item has been flagged.',
'fields' => array(
'fid' => array(
- 'type' => 'int',
- 'size' => 'small',
+ 'type' => 'varchar',
+ 'size' => '255',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
diff --git a/flag.module b/flag.module
index ab971cb..8b6889e 100644
--- a/flag.module
+++ b/flag.module
@@ -696,12 +696,11 @@ function flag_entity_delete($entity, $type) {
*/
function flag_node_delete($node) {
foreach (flag_get_flags('node') as $flag) {
+ // @todo: Update comments below and perhaps also flag_node_translation_change?
// If the flag is being tracked by translation set and the node is part
// of a translation set, don't delete the flagging record.
// Instead, data will be updated in hook_node_translation_change(), below.
- if (!$flag->i18n || empty($node->tnid)) {
- _flag_entity_delete('node', $node->nid, $flag->fid);
- }
+ _flag_entity_delete('node', $node->id());
}
}
diff --git a/src/FlagService.php b/src/FlagService.php
index 059f0be..759126b 100644
--- a/src/FlagService.php
+++ b/src/FlagService.php
@@ -10,6 +10,8 @@
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface;
+use Drupal\flag\Entity\Flag;
+use Drupal\flag\Entity\Flagging;
use Drupal\flag\Event\FlagEvents;
use Drupal\flag\Event\FlaggingEvent;
use Drupal\flag\FlagInterface;
@@ -116,10 +118,16 @@ public function getFlaggings(EntityInterface $entity, FlagInterface $flag, Accou
return $flaggings;
}
+ /**
+ * @todo Should not work like this, instead of the ID, the object itself should be passed along!
+ */
public function getFlagById($flag_id) {
return entity_load('flag', $flag_id);
}
+ /**
+ * @todo Should not work like this, instead of the ID, the object itself should be passed along!
+ */
public function getFlaggableById(FlagInterface $flag, $entity_id) {
return entity_load($flag->getFlaggableEntityType(), $entity_id);
}
@@ -139,6 +147,8 @@ public function flagByObject(FlagInterface $flag, EntityInterface $entity, Accou
$flagging->save();
+ $this->incrementFlagCounts($flag, $entity);
+
\Drupal::entityManager()
->getViewBuilder($entity->getEntityTypeId())
->resetCache(array(
@@ -188,14 +198,13 @@ public function unflag($flag_id, $entity_id, AccountInterface $account = NULL) {
$flag = $this->getFlagById($flag_id);
$entity = $this->getFlaggableById($flag, $entity_id);
+ $this->decrementFlagCounts($flag, $entity);
+
return $this->unflagByObject($flag, $entity, $account);
}
- public function unflagByObject(FlagInterface $flag,
- EntityInterface $entity,
- AccountInterface $account = NULL) {
-
+ public function unflagByObject(FlagInterface $flag, EntityInterface $entity, AccountInterface $account = NULL) {
\Drupal::service('event_dispatcher')
->dispatch(FlagEvents::ENTITY_UNFLAGGED, new FlaggingEvent($flag, $entity, 'unflag'));
@@ -212,4 +221,68 @@ public function unflagByFlagging(FlaggingInterface $flagging) {
$flagging->delete();
}
+ /**
+ * Increments count of flagged entities.
+ *
+ * @param FlagInterface $flag
+ * @param EntityInterface $entity
+ */
+ protected function incrementFlagCounts(FlagInterface $flag, EntityInterface $entity) {
+ $count_result = db_select('flag_counts')
+ ->fields(NULL, array('fid', 'entity_id', 'entity_type', 'count'))
+ ->condition('fid', $flag->id())
+ ->condition('entity_id', $entity->id())
+ ->condition('entity_type', $entity->getEntityTypeId())
+ ->execute()
+ ->fetchAll();
+ var_dump($count_result);
+ if (count($count_result) == 1) {
+ db_update('flag_counts')
+ ->expression('count', 'count + 1')
+ ->condition('fid', $flag->id())
+ ->condition('entity_id', $entity->id())
+ ->execute();
+ }
+ else {
+ db_insert('flag_counts')
+ ->fields(array(
+ 'fid' => $flag->id(),
+ 'entity_id' => $entity->id(),
+ 'entity_type' => $entity->getEntityTypeId(),
+ 'count' => 1,
+ ))
+ ->execute();
+ }
+ }
+
+ /**
+ * Reverts incrementation of count of flagged entities.
+ *
+ * @param FlagInterface $flag
+ * @param EntityInterface $entity
+ */
+ protected function decrementFlagCounts(FlagInterface $flag, EntityInterface $entity) {
+ $count_result = db_select('flag_counts')
+ ->fields(NULL, array('fid', 'entity_id', 'entity_type', 'count'))
+ ->condition('fid', $flag->id())
+ ->condition('entity_id', $entity->id())
+ ->condition('entity_type', $entity->getEntityTypeId())
+ ->execute()
+ ->fetchAll();
+ var_dump($count_result);
+ if (count($count_result) == 1) {
+ db_delete('flag_counts')
+ ->condition('fid', $flag->id())
+ ->condition('entity_id', $entity->id())
+ ->execute();
+ }
+ else {
+ db_update('flag_counts')
+ ->expression('count', 'count - 1')
+ ->condition('fid', $flag->id())
+ ->condition('entity_id', $entity->id())
+ ->execute();
+ }
+ }
+
}
\ No newline at end of file
From fa23e8ac15bf0c5ae4b40a22a304d6cf3e879d73 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Wed, 2 Jul 2014 09:53:52 +0200
Subject: [PATCH 432/629] Added permission check for flag link.
---
flag.module | 4 +++-
src/Tests/FlagSimpleTest.php | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/flag.module b/flag.module
index 6ba3ed8..3576f63 100644
--- a/flag.module
+++ b/flag.module
@@ -597,7 +597,9 @@ function flag_entity_view(array &$build, EntityInterface $entity, EntityViewDisp
if ($flag->isFlagged($entity)) {
$action = 'unflag';
}
- //
+
+ // If does not have permission for this action, stop here and go to next
+ // foreach loop.
if(!$flag->hasActionAccess($action)){
continue;
}
diff --git a/src/Tests/FlagSimpleTest.php b/src/Tests/FlagSimpleTest.php
index 79ff128..d7acde0 100644
--- a/src/Tests/FlagSimpleTest.php
+++ b/src/Tests/FlagSimpleTest.php
@@ -146,6 +146,8 @@ public function doTestCreateNodeAndFlagIt() {
$this->assertResponse(200);
$this->assertLink('Flag this item');
+ // Checks that an anonymous user does not have permission to see the
+ // flag/unflag link.
$this->drupalLogout();
$this->drupalGet('node/' . $node_id);
$this->assertNoLink('Flag this item');
From 451b67079394ba28997740fefd78be21f90d3fd7 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Wed, 2 Jul 2014 17:56:37 +0200
Subject: [PATCH 433/629] Updated commenting.
---
src/Tests/FlagSimpleTest.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Tests/FlagSimpleTest.php b/src/Tests/FlagSimpleTest.php
index d7acde0..497c2e3 100644
--- a/src/Tests/FlagSimpleTest.php
+++ b/src/Tests/FlagSimpleTest.php
@@ -146,8 +146,8 @@ public function doTestCreateNodeAndFlagIt() {
$this->assertResponse(200);
$this->assertLink('Flag this item');
- // Checks that an anonymous user does not have permission to see the
- // flag/unflag link.
+ // Check that the anonymous user, who does not have the necessary
+ // permissions, does not see the flag link.
$this->drupalLogout();
$this->drupalGet('node/' . $node_id);
$this->assertNoLink('Flag this item');
From d8140972e7ae255fbf524b984a2e0ed7828f12f6 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Wed, 2 Jul 2014 18:02:13 +0200
Subject: [PATCH 434/629] Updated commenting.
---
flag.module | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/flag.module b/flag.module
index 3576f63..de6751d 100644
--- a/flag.module
+++ b/flag.module
@@ -598,8 +598,8 @@ function flag_entity_view(array &$build, EntityInterface $entity, EntityViewDisp
$action = 'unflag';
}
- // If does not have permission for this action, stop here and go to next
- // foreach loop.
+ // If the user does not have permission, go to the next foreach loop and
+ // don't display this flag.
if(!$flag->hasActionAccess($action)){
continue;
}
From 07e27184946f19847f9fd87e898931750ef4588a Mon Sep 17 00:00:00 2001
From: Arild
Date: Wed, 2 Jul 2014 18:02:46 +0200
Subject: [PATCH 435/629] flag_help() should use RouteMatchInterface, not
Request
This is to reflect updates made to hook_help(). Note that the implementation is still @todo.
---
flag.module | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/flag.module b/flag.module
index ab971cb..ad8ff15 100644
--- a/flag.module
+++ b/flag.module
@@ -15,7 +15,7 @@ use Drupal\flag\Flag;
use Drupal\node\NodeInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
-use Symfony\Component\HttpFoundation\Request;
+use Drupal\Core\Routing\RouteMatchInterface;
// @todo: Implement flagging_view(). Not extremely useful. I already have it.
@@ -158,7 +158,7 @@ function flag_load($flag_name, $include_disabled = FALSE) {
/**
* Implements hook_help().
*/
-function flag_help($route_name, Request $request) {
+function flag_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'flag.list':
$output = '' . t('This page lists all the flags that are currently defined on this system.') . '
';
From f4e2e5bd44d91b227c8af459490c63fd35646892 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Thu, 3 Jul 2014 11:06:10 +0200
Subject: [PATCH 436/629] Replaced conditional row creation/update with
db_merge().
---
src/FlagService.php | 43 +++++++++++++++++--------------------------
1 file changed, 17 insertions(+), 26 deletions(-)
diff --git a/src/FlagService.php b/src/FlagService.php
index 759126b..c8d9f73 100644
--- a/src/FlagService.php
+++ b/src/FlagService.php
@@ -228,31 +228,21 @@ public function unflagByFlagging(FlaggingInterface $flagging) {
* @param EntityInterface $entity
*/
protected function incrementFlagCounts(FlagInterface $flag, EntityInterface $entity) {
- $count_result = db_select('flag_counts')
- ->fields(NULL, array('fid', 'entity_id', 'entity_type', 'count'))
- ->condition('fid', $flag->id())
- ->condition('entity_id', $entity->id())
- ->condition('entity_type', $entity->getEntityTypeId())
- ->execute()
- ->fetchAll();
- var_dump($count_result);
- if (count($count_result) == 1) {
- db_update('flag_counts')
- ->expression('count', 'count + 1')
- ->condition('fid', $flag->id())
- ->condition('entity_id', $entity->id())
- ->execute();
- }
- else {
- db_insert('flag_counts')
- ->fields(array(
- 'fid' => $flag->id(),
- 'entity_id' => $entity->id(),
- 'entity_type' => $entity->getEntityTypeId(),
- 'count' => 1,
- ))
- ->execute();
- }
+ db_merge('flag_counts')
+ ->key(array(
+ 'fid' => $flag->id(),
+ 'entity_id' => $entity->id(),
+ 'entity_type' => $entity->getEntityTypeId(),
+ 'last_updated' => time(),
+ ))
+ ->fields(array(
+ 'fid' => $flag->id(),
+ 'entity_id' => $entity->id(),
+ 'entity_type' => $entity->getEntityTypeId(),
+ 'count' => 1
+ ))
+ ->expression('count', 'count + :inc', array(':inc' => 1))
+ ->execute();
}
/**
@@ -269,11 +259,11 @@ protected function decrementFlagCounts(FlagInterface $flag, EntityInterface $ent
->condition('entity_type', $entity->getEntityTypeId())
->execute()
->fetchAll();
- var_dump($count_result);
if (count($count_result) == 1) {
db_delete('flag_counts')
->condition('fid', $flag->id())
->condition('entity_id', $entity->id())
+ ->condition('entity_type', $entity->getEntityTypeId())
->execute();
}
else {
@@ -281,6 +271,7 @@ protected function decrementFlagCounts(FlagInterface $flag, EntityInterface $ent
->expression('count', 'count - 1')
->condition('fid', $flag->id())
->condition('entity_id', $entity->id())
+ ->condition('entity_id', $entity->id())
->execute();
}
}
From 59a6f6a396b43c720fb3b00a032a94e9e4b6c55f Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Thu, 3 Jul 2014 11:28:26 +0200
Subject: [PATCH 437/629] Added test that flags a node using different user
accounts and checks flag counts.
---
src/Tests/FlagSimpleTest.php | 74 ++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/src/Tests/FlagSimpleTest.php b/src/Tests/FlagSimpleTest.php
index a41c2db..01a2875 100644
--- a/src/Tests/FlagSimpleTest.php
+++ b/src/Tests/FlagSimpleTest.php
@@ -180,4 +180,78 @@ public function doTestHideFlagLinkFromTeaser() {
$this->drupalGet('node/' . $node_id);
}
+
+ /**
+ * Flags a node using different user accounts and checks flag counts.
+ */
+ public function doTestFlagCounts() {
+ $node = $this->drupalCreateNode(array('type' => $this->nodeType));
+ $node_id = $node->id();
+
+ // Create and login user 1.
+ $user_1 = $this->drupalCreateUser();
+ $this->drupalLogin($user_1);
+
+ // Flag node (first count).
+ $this->drupalGet('node/' . $node_id);
+ $this->clickLink('Flag this item');
+ $this->assertResponse(200);
+ $this->assertLink('Unflag this item');
+
+ // Check for 1 flag count.
+ $count_flags_before = \Drupal::entityQuery('flag_counts')
+ ->condition('fid', $this->id)
+ ->condition('entity_type', $node->getEntityTypeId())
+ ->condition('entity_id', $node_id)
+ ->count()
+ ->execute();
+ $this->assertTrue(1, $count_flags_before);
+
+ // Logout user 1, create and login user 2.
+ $user_2 = $this->drupalCreateUser();
+ $this->drupalLogin($user_2);
+
+ // Flag node (second count).
+ $this->drupalGet('node/' . $node_id);
+ $this->clickLink('Flag this item');
+ $this->assertResponse(200);
+ $this->assertLink('Unflag this item');
+
+ // Check for 2 flag counts.
+ $count_flags_after = \Drupal::entityQuery('flag_counts')
+ ->condition('fid', $this->id)
+ ->condition('entity_type', $node->getEntityTypeId())
+ ->condition('entity_id', $node_id)
+ ->count()
+ ->execute();
+ $this->assertTrue(2, $count_flags_after);
+
+ // Unflag the node again.
+ $this->drupalGet('node/' . $node_id);
+ $this->clickLink('Unflag this item');
+ $this->assertResponse(200);
+ $this->assertLink('Flag this item');
+
+ // Check for 1 flag count.
+ $count_flags_before = \Drupal::entityQuery('flag_counts')
+ ->condition('fid', $this->id)
+ ->condition('entity_type', $node->getEntityTypeId())
+ ->condition('entity_id', $node_id)
+ ->count()
+ ->execute();
+ $this->assertTrue(1, $count_flags_before);
+
+ // Delete user 1.
+ $user_1->delete();
+
+ // Check for 0 flag counts, user deletion should lead to count decrement
+ // or row deletion.
+ $count_flags_before = \Drupal::entityQuery('flag_counts')
+ ->condition('fid', $this->id)
+ ->condition('entity_type', $node->getEntityTypeId())
+ ->condition('entity_id', $node_id)
+ ->count()
+ ->execute();
+ $this->assertTrue(0, $count_flags_before);
+ }
}
From 3af54ea325ab2ff86978e36da586cb11dbc5674c Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Mon, 7 Jul 2014 13:55:46 +0200
Subject: [PATCH 438/629] Fixed hook requirements to enable successful
installation.
---
flag.install | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/flag.install b/flag.install
index 3e7100b..677b461 100644
--- a/flag.install
+++ b/flag.install
@@ -76,9 +76,9 @@ function flag_uninstall() {
* Implements hook_requirements().
*/
function flag_requirements($phase) {
- /*
- $requirements = array();
+ $requirements = array();
+ /*
if ($phase == 'runtime') {
if (module_exists('translation') && !module_exists('translation_helpers')) {
$requirements['flag_translation'] = array(
@@ -107,6 +107,6 @@ function flag_requirements($phase) {
}
}
}
- return $requirements;
*/
+ return $requirements;
}
From 4f724fe55132947a77694a88dcc0be30fa2f9820 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher
Date: Tue, 8 Jul 2014 13:57:31 +0200
Subject: [PATCH 439/629] Fix and simplify flag_counts schema
---
flag.install | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/flag.install b/flag.install
index 9992e0b..572606b 100644
--- a/flag.install
+++ b/flag.install
@@ -16,40 +16,29 @@ function flag_schema() {
'fields' => array(
'fid' => array(
'type' => 'varchar',
- 'size' => '255',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
+ 'length' => '32',
),
'entity_type' => array(
'description' => 'The flag type, usually one of "node", "comment", "user".',
'type' => 'varchar',
'length' => '128',
- 'not null' => TRUE,
- 'default' => '',
),
'entity_id' => array(
'description' => 'The unique ID of the content, usually either the {cid}, {uid}, or {nid}.',
'type' => 'int',
'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
'disp-width' => '10',
),
'count' => array(
'description' => 'The number of times this object has been flagged for this flag.',
'type' => 'int',
'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
'disp-width' => '10',
),
'last_updated' => array(
'description' => 'The UNIX time stamp representing when the flag was last updated.',
'type' => 'int',
'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
'disp-size' => 11,
)
),
From f72df551ce0c600f30fb2e574900985a4cc109d3 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Fri, 11 Jul 2014 16:42:48 +0200
Subject: [PATCH 440/629] Removed getInfo() and deleted unused/missplaced test
including it's parent folder structure.
---
src/Tests/FlagSimpleTest.php | 15 +++------------
tests/src/FlagTestBase.php | 16 ----------------
2 files changed, 3 insertions(+), 28 deletions(-)
delete mode 100644 tests/src/FlagTestBase.php
diff --git a/src/Tests/FlagSimpleTest.php b/src/Tests/FlagSimpleTest.php
index a41c2db..9f4b70e 100644
--- a/src/Tests/FlagSimpleTest.php
+++ b/src/Tests/FlagSimpleTest.php
@@ -12,7 +12,9 @@
/**
- * Tests the Flag forms (add/edit/delete).
+ * Tests the Flag form actions (add/edit/delete).
+ *
+ * @group Flag
*/
class FlagSimpleTest extends WebTestBase {
@@ -52,17 +54,6 @@ class FlagSimpleTest extends WebTestBase {
*/
public static $modules = array('views', 'flag', 'node', 'field_ui');
- /**
- * {@inheritdoc}
- */
- public static function getInfo() {
- return array(
- 'name' => 'Flag form/s',
- 'description' => 'Creates a flag, adds flag to node.',
- 'group' => 'Flag',
- );
- }
-
/**
* Configures test base and executes test cases.
*/
diff --git a/tests/src/FlagTestBase.php b/tests/src/FlagTestBase.php
deleted file mode 100644
index 7bdb96c..0000000
--- a/tests/src/FlagTestBase.php
+++ /dev/null
@@ -1,16 +0,0 @@
-
Date: Fri, 11 Jul 2014 18:23:57 +0200
Subject: [PATCH 441/629] module_invoke_all() has been removed
---
flag.module | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/flag.module b/flag.module
index ad8ff15..619edc5 100644
--- a/flag.module
+++ b/flag.module
@@ -249,7 +249,7 @@ function flag_fetch_definition($entity_type = NULL) {
$definitions = $cache->data;
}
else {
- $definitions = module_invoke_all('flag_type_info');
+ $definitions = \Drupal::moduleHandler()->invokeAll('flag_type_info');
drupal_alter('flag_type_info', $definitions);
\Drupal::cache()->set('flag_type_info', $definitions);
@@ -1881,7 +1881,7 @@ function flag_reset_flag($flag, $entity_id = NULL) {
foreach ($result as $row) {
$rows[] = $row;
}
- module_invoke_all('flag_reset', $flag, $entity_id, $rows);
+ \Drupal::moduleHandler()->invokeAll('flag_reset', array($flag, $entity_id, $rows));
$query = db_delete('flagging')->condition('fid' , $flag->fid);
// Update the flag_counts table.
From 53e12cf4b5402ae9ae6c28f86752a08feba4e6c3 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher
Date: Fri, 11 Jul 2014 19:37:36 +0200
Subject: [PATCH 442/629] entity_type argument to hook_entity_delete() was
removed.
---
flag.module | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/flag.module b/flag.module
index ad8ff15..f6ab5be 100644
--- a/flag.module
+++ b/flag.module
@@ -681,10 +681,10 @@ function flag_node_save($node) {
/**
* Implements hook_entity_delete().
*/
-function flag_entity_delete($entity, $type) {
+function flag_entity_delete(EntityInterface $entity) {
// Node and user flags handle things through the entity type delete hooks.
// @todo: make this configurable in the flag type definition?
- if ($type == 'node' || $type == 'user') {
+ if ($entity->getEntityTypeId() == 'node' || $entity->getEntityTypeId() == 'user') {
return;
}
From 66c00b0095f0fe2420a8eee032404b0eede575a8 Mon Sep 17 00:00:00 2001
From: Jibran Ijaz
Date: Sat, 12 Jul 2014 00:27:36 +0500
Subject: [PATCH 443/629] Added travis support.
---
.travis.yml | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
create mode 100644 .travis.yml
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..6d8954c
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,64 @@
+language: php
+
+php:
+ - 5.4
+ - 5.5
+
+mysql:
+ database: flag
+ username: root
+ encoding: utf8
+
+before_install:
+ - sudo apt-get update > /dev/null
+ # Always update Composer to the recent version, otherwise the drush
+ # installation fails.
+ - composer selfupdate
+
+install:
+ # Install php packages required for running a web server from drush.
+ - sudo apt-get install -y --force-yes php5-cgi php5-mysql
+
+ # Add composer's global bin directory to the path.
+ # @see: https://github.com/drush-ops/drush#install---composer
+ - export PATH="$HOME/.composer/vendor/bin:$PATH"
+
+ # install drush globally
+ - composer global require drush/drush:dev-master
+ - composer global require youngj/httpserver:dev-master
+
+before_script:
+ # Remember the current flag test directory for later use in the Drupal
+ # installation.
+ - TESTDIR=$(pwd)
+ # Navigate out of module directory to prevent blown stack by recursive module
+ # lookup.
+ - cd ..
+
+ # Create new site, stubbing sendmail path with true to prevent delivery errors
+ # and manually resolving drush path.
+ - mysql -e 'create database flag'
+ # Download Drupal 8 core.
+ - wget -q -O - http://ftp.drupal.org/files/projects/drupal-8.x-dev.tar.gz | tar xz
+ - cd drupal-8.x-dev
+ # Install Drupal.
+ - php -d sendmail_path=`which true` ~/.composer/vendor/bin/drush.php --yes site-install --db-url=mysql://root:@127.0.0.1/flag testing
+
+ # Reference and enable flag in build site.
+ - ln -s $TESTDIR modules/flag
+ - drush --yes pm-enable simpletest flag
+
+ # Switch to core directory where we will execute PHPUnit.
+ - cd core
+
+ # Start a web server on port 8080, run in the background; wait for
+ # initialization. This is temporarly disabled since there are no web tests
+ # yet.
+ #- drush runserver 127.0.0.1:8080 &
+ #- until netstat -an 2>/dev/null | grep '8080.*LISTEN'; do true; done
+
+script:
+ # Run the Simpletests for flag.
+ - drush test-run 'flag' --uri=http://127.0.0.1:8080
+ # Run the PHPUnit tests.
+# - ./vendor/phpunit/phpunit/phpunit ../modules/flag
From 55413ea1a000062a96ef23eb82d28c633f8cf431 Mon Sep 17 00:00:00 2001
From: Jibran Ijaz
Date: Sun, 13 Jul 2014 07:33:59 +0500
Subject: [PATCH 444/629] Added PHPCS to .travis.yml and Updated simpetest
script.
---
.travis.yml | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 6d8954c..93e30c4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -26,8 +26,12 @@ install:
# install drush globally
- composer global require drush/drush:dev-master
- composer global require youngj/httpserver:dev-master
+ - composer global require squizlabs/php_codesniffer:2.0.*@dev
+ - composer global require drupal/coder:dev-8.x-2.x
before_script:
+ # Create a Drupal coding standard reference in PHPCS coding standards.
+ - ln -s ~/.composer/vendor/drupal/coder/coder_sniffer/Drupal ~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards
# Remember the current flag test directory for later use in the Drupal
# installation.
- TESTDIR=$(pwd)
@@ -48,9 +52,6 @@ before_script:
- ln -s $TESTDIR modules/flag
- drush --yes pm-enable simpletest flag
- # Switch to core directory where we will execute PHPUnit.
- - cd core
-
# Start a web server on port 8080, run in the background; wait for
# initialization. This is temporarly disabled since there are no web tests
# yet.
@@ -58,7 +59,9 @@ before_script:
#- until netstat -an 2>/dev/null | grep '8080.*LISTEN'; do true; done
script:
- # Run the Simpletests for flag.
- - drush test-run 'flag' --uri=http://127.0.0.1:8080
+ # Run the Coder sniffer for Flag.
+ - phpcs --report=full --standard=Drupal ./modules/flag
+ # Run the Simpletests for Flag.
+ - php ./core/scripts/run-tests.sh --php `which php` --concurrency 12 --url http://127.0.0.1:8080 --verbose --color "flag"
# Run the PHPUnit tests.
-# - ./vendor/phpunit/phpunit/phpunit ../modules/flag
+ - ./core/vendor/phpunit/phpunit/phpunit -c ./core/phpunit.xml.dist ./modules/flag
From 723b2067d4f93e0c12b20d23a03db2bb691fe940 Mon Sep 17 00:00:00 2001
From: Jibran Ijaz
Date: Sun, 13 Jul 2014 19:45:38 +0500
Subject: [PATCH 445/629] Updated .travis.yml.
---
.travis.yml | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 93e30c4..d636141 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,10 +5,19 @@ php:
- 5.5
mysql:
- database: flag
+ database: drupal
username: root
encoding: utf8
+env:
+ global:
+ - MODULE_NAME='flag'
+ - MODULE_TEST_GROUP='flag'
+ - DRUPAL_REPO='git://drupalcode.org/project/drupal.git'
+ - DRUPAL_VERSION='8.x'
+ - PHPCS_VERSION='2.0.*@dev'
+ - CODER_VERSION='dev-8.x-2.x'
+
before_install:
- sudo apt-get update > /dev/null
# Always update Composer to the recent version, otherwise the drush
@@ -26,8 +35,8 @@ install:
# install drush globally
- composer global require drush/drush:dev-master
- composer global require youngj/httpserver:dev-master
- - composer global require squizlabs/php_codesniffer:2.0.*@dev
- - composer global require drupal/coder:dev-8.x-2.x
+ - composer global require squizlabs/php_codesniffer:$PHPCS_VERSION
+ - composer global require drupal/coder:$CODER_VERSION
before_script:
# Create a Drupal coding standard reference in PHPCS coding standards.
@@ -41,27 +50,27 @@ before_script:
# Create new site, stubbing sendmail path with true to prevent delivery errors
# and manually resolving drush path.
- - mysql -e 'create database flag'
+ - mysql -e 'create database drupal'
# Download Drupal 8 core.
- - wget -q -O - http://ftp.drupal.org/files/projects/drupal-8.x-dev.tar.gz | tar xz
- - cd drupal-8.x-dev
+ - git clone --branch $DRUPAL_VERSION $DRUPAL_REPO drupal
+ - cd drupal
# Install Drupal.
- - php -d sendmail_path=`which true` ~/.composer/vendor/bin/drush.php --yes site-install --db-url=mysql://root:@127.0.0.1/flag testing
+ - php -d sendmail_path=`which true` ~/.composer/vendor/bin/drush.php --yes site-install --db-url=mysql://root:@127.0.0.1/drupal testing
# Reference and enable flag in build site.
- - ln -s $TESTDIR modules/flag
- - drush --yes pm-enable simpletest flag
+ - ln -s $TESTDIR modules/$MODULE_NAME
+ - drush --yes pm-enable simpletest $MODULE_NAME
# Start a web server on port 8080, run in the background; wait for
# initialization. This is temporarly disabled since there are no web tests
# yet.
- #- drush runserver 127.0.0.1:8080 &
- #- until netstat -an 2>/dev/null | grep '8080.*LISTEN'; do true; done
+ - drush runserver 127.0.0.1:8080 &
+ - until netstat -an 2>/dev/null | grep '8080.*LISTEN'; do true; done
script:
# Run the Coder sniffer for Flag.
- - phpcs --report=full --standard=Drupal ./modules/flag
+ - phpcs --report=full --standard=Drupal ./modules/$MODULE_NAME
# Run the Simpletests for Flag.
- - php ./core/scripts/run-tests.sh --php `which php` --concurrency 12 --url http://127.0.0.1:8080 --verbose --color "flag"
+ - php ./core/scripts/run-tests.sh --php `which php` --concurrency 12 --url http://127.0.0.1:8080 --verbose --color "$MODULE_TEST_GROUP"
# Run the PHPUnit tests.
- - ./core/vendor/phpunit/phpunit/phpunit -c ./core/phpunit.xml.dist ./modules/flag
+ - ./core/vendor/phpunit/phpunit/phpunit -c ./core/phpunit.xml.dist ./modules/$MODULE_NAME
From edd3afbd743321c4bf39751e1e1fcbfe5826890f Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher
Date: Mon, 14 Jul 2014 12:14:51 +0200
Subject: [PATCH 446/629] Fix and simplify merge query
---
src/FlagService.php | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/src/FlagService.php b/src/FlagService.php
index c8d9f73..c459a49 100644
--- a/src/FlagService.php
+++ b/src/FlagService.php
@@ -233,13 +233,10 @@ protected function incrementFlagCounts(FlagInterface $flag, EntityInterface $ent
'fid' => $flag->id(),
'entity_id' => $entity->id(),
'entity_type' => $entity->getEntityTypeId(),
- 'last_updated' => time(),
))
->fields(array(
- 'fid' => $flag->id(),
- 'entity_id' => $entity->id(),
- 'entity_type' => $entity->getEntityTypeId(),
- 'count' => 1
+ 'last_updated' => REQUEST_TIME,
+ 'count' => 1,
))
->expression('count', 'count + :inc', array(':inc' => 1))
->execute();
@@ -276,4 +273,4 @@ protected function decrementFlagCounts(FlagInterface $flag, EntityInterface $ent
}
}
-}
\ No newline at end of file
+}
From c42d4a932f3fb283ca56e683875f4c451677aee5 Mon Sep 17 00:00:00 2001
From: Jibran Ijaz
Date: Tue, 15 Jul 2014 09:59:19 +0500
Subject: [PATCH 447/629] Updated .travis.yml.
---
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index d636141..c204734 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -52,7 +52,7 @@ before_script:
# and manually resolving drush path.
- mysql -e 'create database drupal'
# Download Drupal 8 core.
- - git clone --branch $DRUPAL_VERSION $DRUPAL_REPO drupal
+ - git clone --depth 1 --branch $DRUPAL_VERSION $DRUPAL_REPO drupal
- cd drupal
# Install Drupal.
- php -d sendmail_path=`which true` ~/.composer/vendor/bin/drush.php --yes site-install --db-url=mysql://root:@127.0.0.1/drupal testing
From 8ba4715d698d9472f49fca3b0b029f7559423e06 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Tue, 15 Jul 2014 12:29:05 +0200
Subject: [PATCH 448/629] Updated label to label().
---
src/Controller/FlagListController.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Controller/FlagListController.php b/src/Controller/FlagListController.php
index 44aaede..5879ce5 100644
--- a/src/Controller/FlagListController.php
+++ b/src/Controller/FlagListController.php
@@ -34,7 +34,7 @@ protected function getFlagRoles(FlagInterface $flag) {
$roles = user_roles(FALSE, $perm);
foreach ($roles as $rid => $role) {
- $allRoles[$rid] = $role->label;
+ $allRoles[$rid] = $role->label();
}
}
From a2be0915a1ef3461171fdbf82dccc537da6f40e0 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher
Date: Fri, 18 Jul 2014 16:06:26 +0200
Subject: [PATCH 449/629] Fixed case of Url class
---
src/ActionLinkTypeBase.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/ActionLinkTypeBase.php b/src/ActionLinkTypeBase.php
index 55ff42a..21749d6 100644
--- a/src/ActionLinkTypeBase.php
+++ b/src/ActionLinkTypeBase.php
@@ -8,7 +8,7 @@
namespace Drupal\flag;
-use Drupal\Core\URL;
+use Drupal\Core\Url;
use Drupal\Core\Entity\EntityInterface;
use \Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Component\Plugin\PluginBase;
@@ -52,7 +52,7 @@ public function buildLink($action, FlagInterface $flag, EntityInterface $entity)
'entity_id' => $entity->id(),
);
- return new URL($this->routeName($action), $parameters);
+ return new Url($this->routeName($action), $parameters);
}
public function renderLink($action, FlagInterface $flag, EntityInterface $entity) {
@@ -149,4 +149,4 @@ public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
-}
\ No newline at end of file
+}
From ad0e87ffad4d1c5a42ca34e7d1b4334d000e55e4 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Fri, 18 Jul 2014 11:43:42 -0500
Subject: [PATCH 450/629] Changed YAML file names due to
https://www.drupal.org/node/2302893
---
flag.local_actions.yml => flag.links.action.yml | 0
flag.menu_links.yml => flag.links.menu.yml | 0
2 files changed, 0 insertions(+), 0 deletions(-)
rename flag.local_actions.yml => flag.links.action.yml (100%)
rename flag.menu_links.yml => flag.links.menu.yml (100%)
diff --git a/flag.local_actions.yml b/flag.links.action.yml
similarity index 100%
rename from flag.local_actions.yml
rename to flag.links.action.yml
diff --git a/flag.menu_links.yml b/flag.links.menu.yml
similarity index 100%
rename from flag.menu_links.yml
rename to flag.links.menu.yml
From 6d119bf04c7bfbb126ccbf9b175d7ea7d052d48a Mon Sep 17 00:00:00 2001
From: socketwench
Date: Fri, 18 Jul 2014 11:47:28 -0500
Subject: [PATCH 451/629] Fixed broken FlagListController due to
module_exists() going away.
---
src/Controller/FlagListController.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/Controller/FlagListController.php b/src/Controller/FlagListController.php
index 5879ce5..a821f57 100644
--- a/src/Controller/FlagListController.php
+++ b/src/Controller/FlagListController.php
@@ -67,7 +67,7 @@ public function render() {
$output = "";
//@todo Move this too hook_help()?
- if (!module_exists('views')) {
+ if (!\Drupal::moduleHandler()->moduleExists('views')) {
$output .= '' . t('The Views module is not installed, or not enabled. It is recommended that you install the Views module to be able to easily produce lists of flagged content.', array('@views-url' => url('http://drupal.org/project/views'))) . '
';
}
else {
@@ -80,14 +80,14 @@ public function render() {
$output .= '';
}
- if (!module_exists('flag_actions')) {
+ if (!\Drupal::moduleHandler()->moduleExists('flag_actions')) {
$output .= '' . t('Flagging an item may trigger actions. However, you don\'t have the Flag actions module enabled, so you won\'t be able to enjoy this feature.', array('@actions-url' => url(FLAG_ADMIN_PATH . '/actions'), '@modules-url' => url('admin/modules'))) . '
';
}
else {
$output .= '' . t('Flagging an item may trigger actions.', array('@actions-url' => url(FLAG_ADMIN_PATH . '/actions'))) . '
';
}
- if (!module_exists('rules')) {
+ if (!\Drupal::moduleHandler()->moduleExists('rules')) {
$output .= '' . t('Flagging an item may trigger rules. However, you don\'t have the Rules module enabled, so you won\'t be able to enjoy this feature. The Rules module is a more extensive solution than Flag actions.', array('@rules-url' => url('http://drupal.org/node/407070'))) . '
';
}
else {
From 15d623bf2c00892c4bb67a882711333221d2abd8 Mon Sep 17 00:00:00 2001
From: socketwench
Date: Fri, 18 Jul 2014 12:20:53 -0500
Subject: [PATCH 452/629] Removed trigger module references.
---
flag.module | 83 -----------------------------------------------------
1 file changed, 83 deletions(-)
diff --git a/flag.module b/flag.module
index ba9864f..1f2f494 100644
--- a/flag.module
+++ b/flag.module
@@ -930,89 +930,6 @@ function flag_field_attach_delete_bundle($entity_type, $bundle, $instances) {
));
}
-/**
- * Flags or unflags an item.
- *
- * @param $action
- * Either 'flag' or 'unflag'.
- * @param $flag_name
- * The name of the flag to use.
- * @param $entity_id
- * The ID of the item to flag or unflag.
- * @param $account
- * (optional) The user on whose behalf to flag. Omit for the current user.
- * @param permissions_check
- * (optional) A boolean indicating whether to skip permissions.
- *
- * @return
- * FALSE if some error occured (e.g., user has no permission, flag isn't
- * applicable to the item, etc.), TRUE otherwise.
- */
-function flag($action, $flag_name, $entity_id, $account = NULL, $permissions_check = FALSE) {
- if (!($flag = flag_get_flag($flag_name))) {
- // Flag does not exist.
- return FALSE;
- }
- return $flag->flag($action, $entity_id, $account, $permissions_check);
-}
-
-/**
- * Implements hook_flag_flag().
- */
-function flag_flag_flag($flag, $entity_id, $account, $flagging) {
- if (module_exists('trigger')) {
- flag_flag_trigger('flag', $flag, $entity_id, $account, $flagging);
- }
-}
-
-/**
- * Implements hook_flag_unflag().
- */
-function flag_flag_unflag($flag, $entity_id, $account, $flagging) {
- if (module_exists('trigger')) {
- flag_flag_trigger('unflag', $flag, $entity_id, $account, $flagging);
- }
-}
-
-/**
- * Trigger actions if any are available. Helper for hook_flag_(un)flag().
- *
- * @param $op
- * The operation being performed: one of 'flag' or 'unflag'.
- * @param $flag
- * The flag object.
- * @param $entity_id
- * The id of the entity the flag is on.
- * @param $account
- * The user account performing the action.
- * @param $flagging_id
- * The flagging entity.
- */
-function flag_flag_trigger($action, $flag, $entity_id, $account, $flagging) {
- $context['hook'] = 'flag';
- $context['account'] = $account;
- $context['flag'] = $flag;
- $context['op'] = $action;
- // We add to the $context all the objects we know about:
- $context = array_merge($flag->get_relevant_action_objects($entity_id), $context);
- // The primary object the actions work on.
- $object = $flag->fetch_entity($entity_id);
-
- // Generic "all flags" actions.
- foreach (trigger_get_assigned_actions('flag_' . $action) as $aid => $action_info) {
- // The 'if ($aid)' is a safeguard against http://drupal.org/node/271460#comment-886564
- if ($aid) {
- actions_do($aid, $object, $context);
- }
- }
- // Actions specifically for this flag.
- foreach (trigger_get_assigned_actions('flag_' . $action . '_' . $flag->name) as $aid => $action_info) {
- if ($aid) {
- actions_do($aid, $object, $context);
- }
- }
-}
-
/**
* Implements hook_flag_access().
*/
From 8027ef968bac403beb6b47139a78df39878e8129 Mon Sep 17 00:00:00 2001
From: James Cazzetta
Date: Tue, 15 Jul 2014 14:17:29 +0200
Subject: [PATCH 453/629] Fixed deprecated function module_exists(), tests
working again.
---
flag.install | 4 ++--
flag.module | 14 +++++++-------
flag.tokens.inc | 2 +-
src/Form/FlagFormBase.php | 2 +-
src/Plugin/Flag/EntityFlagType.php | 2 +-
src/Plugin/Flag/NodeFlagType.php | 2 +-
6 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/flag.install b/flag.install
index e3fcc94..2af50ac 100644
--- a/flag.install
+++ b/flag.install
@@ -69,7 +69,7 @@ function flag_requirements($phase) {
$requirements = array();
/*
if ($phase == 'runtime') {
- if (module_exists('translation') && !module_exists('translation_helpers')) {
+ if (\Drupal::moduleHandler()->moduleExists('translation') && !\Drupal::moduleHandler()->moduleExists('translation_helpers')) {
$requirements['flag_translation'] = array(
'title' => t('Flag'),
'severity' => REQUIREMENT_ERROR,
@@ -77,7 +77,7 @@ function flag_requirements($phase) {
'value' => t('Translation helpers module not found.'),
);
}
- if (module_exists('session_api')) {
+ if (\Drupal::moduleHandler()->moduleExists('session_api')) {
if (file_exists('./robots.txt')) {
$flag_path = url('flag') . '/';
// We don't use url() because this may return an absolute URL when
diff --git a/flag.module b/flag.module
index 1f2f494..d5e9512 100644
--- a/flag.module
+++ b/flag.module
@@ -94,7 +94,7 @@ function flag_admin_menu_map() {
),
);
- if (module_exists('field_ui')) {
+ if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
foreach (entity_get_info() as $obj_type => $info) {
if ($obj_type == 'flagging') {
foreach ($info['bundles'] as $bundle_name => $bundle_info) {
@@ -198,7 +198,7 @@ function flag_help($route_name, RouteMatchInterface $route_match) {
$output .= t("Field values may be edited when flaggings are created because this flag's link type shows a form for the flagging. However, to edit field values on existing flaggings, you will need to set your flag to use the Flagging form link type. This is provided by the Flagging Form module.", array(
'!flagging-form-url' => 'http://drupal.org/project/flagging_form',
));
- if (!module_exists('flagging_form')) {
+ if (!\Drupal::moduleHandler()->moduleExists('flagging_form')) {
$output .= ' '
. t("You do not currently have this module enabled.")
. '';
@@ -217,7 +217,7 @@ function flag_help($route_name, RouteMatchInterface $route_match) {
$output .= '' . t("Additionally, to edit field values on existing flaggings, you will need to set your flag to use the Flagging form link type. This is provided by the Flagging Form module.", array(
'!flagging-form-url' => 'http://drupal.org/project/flagging_form',
));
- if (!module_exists('flagging_form')) {
+ if (!\Drupal::moduleHandler()->moduleExists('flagging_form')) {
$output .= ' '
. t("You do not currently have this module enabled.")
. '';
@@ -250,7 +250,7 @@ function flag_fetch_definition($entity_type = NULL) {
}
else {
$definitions = \Drupal::moduleHandler()->invokeAll('flag_type_info');
- drupal_alter('flag_type_info', $definitions);
+ \Drupal::moduleHandler()->alter('flag_type_info', $definitions);
\Drupal::cache()->set('flag_type_info', $definitions);
}
@@ -307,7 +307,7 @@ function flag_permission() {
* anonymous users when Session API module is not enabled.
*/
function flag_form_user_admin_permissions_alter(&$form, &$form_state, $form_id) {
- if (!module_exists('session_api')) {
+ if (!\Drupal::moduleHandler()->moduleExists('session_api')) {
$flags = \Drupal::service('flag')->getFlags();
// Disable flag and unflag permission checkboxes for anonymous users.
foreach ($flags as $flag_name => $flag) {
@@ -759,7 +759,7 @@ function _flag_entity_delete($entity_type, $entity_id, $fid = NULL) {
*/
function flag_user_login($account) {
// Migrate anonymous flags to this user's account.
- if (module_exists('session_api') && ($sid = flag_get_sid(0))) {
+ if (\Drupal::moduleHandler()->moduleExists('session_api') && ($sid = flag_get_sid(0))) {
// Get a list of flagging IDs that will be moved over.
$duplicate_flaggings = array();
$flaggings = db_select('flagging', 'fc')
@@ -1903,7 +1903,7 @@ function flag_set_sid($uid = NULL, $create = TRUE) {
// Set the sid if none has been set yet. If the caller specified to create an
// sid and we have an invalid one (-1), create it.
if (!isset($sids[$uid]) || ($sids[$uid] == -1 && $create)) {
- if (module_exists('session_api') && session_api_available() && $uid == 0) {
+ if (\Drupal::moduleHandler()->moduleExists('session_api') && session_api_available() && $uid == 0) {
// This returns one of the following:
// - -1. This indicates that no session exists and none was created.
// - A positive integer with the Session ID when it does exist.
diff --git a/flag.tokens.inc b/flag.tokens.inc
index d25967d..59f7c17 100644
--- a/flag.tokens.inc
+++ b/flag.tokens.inc
@@ -186,7 +186,7 @@ function theme_flag_tokens_browser($variables) {
$types = $variables['types'];
$global_types = $variables['global_types'];
- if (module_exists('token')) {
+ if (\Drupal::moduleHandler()->moduleExists('token')) {
return theme('token_tree', array('token_types' => $types, 'global_types' => $global_types));
}
else {
diff --git a/src/Form/FlagFormBase.php b/src/Form/FlagFormBase.php
index f50b0e9..8c9a53b 100644
--- a/src/Form/FlagFormBase.php
+++ b/src/Form/FlagFormBase.php
@@ -300,7 +300,7 @@ public function save(array $form, array &$form_state) {
}
}
/*
- foreach (array_keys(user_roles(!module_exists('session_api'))) as $rid) {
+ foreach (array_keys(user_roles(!\Drupal::moduleHandler()->moduleExists('session_api'))) as $rid) {
// Create an array of permissions, based on the checkboxes element name.
$permissions = array(
"flag $flag->name" => $flag->roles['flag'][$rid],
diff --git a/src/Plugin/Flag/EntityFlagType.php b/src/Plugin/Flag/EntityFlagType.php
index 339d879..1f085f8 100644
--- a/src/Plugin/Flag/EntityFlagType.php
+++ b/src/Plugin/Flag/EntityFlagType.php
@@ -102,7 +102,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
'#title' => t('Display in contextual links'),
'#default_value' => $this->showContextualLink(),
'#description' => t('Note that not all entity types support contextual links.'),
- '#access' => module_exists('contextual'),
+ '#access' => \Drupal::moduleHandler()->moduleExists('contextual'),
'#weight' => 10,
);
diff --git a/src/Plugin/Flag/NodeFlagType.php b/src/Plugin/Flag/NodeFlagType.php
index e97fe9b..5430fd1 100644
--- a/src/Plugin/Flag/NodeFlagType.php
+++ b/src/Plugin/Flag/NodeFlagType.php
@@ -63,7 +63,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
),
//'#default_value' => $this->i18n,
'#description' => t('Flagging translations as a group effectively allows users to flag the original piece of content regardless of the translation they are viewing. Changing this setting will not update content that has been flagged already.'),
- '#access' => module_exists('translation_helpers'),
+ '#access' => \Drupal::moduleHandler()->moduleExists('translation_helpers'),
'#weight' => 5,
);
From 3e8c82bead93046fcde06a5692c0513d8f88e91b Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher
Date: Fri, 18 Jul 2014 20:43:47 +0200
Subject: [PATCH 454/629] Fix test group
---
src/Tests/FlagSimpleTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Tests/FlagSimpleTest.php b/src/Tests/FlagSimpleTest.php
index 97d65bf..adf50ed 100644
--- a/src/Tests/FlagSimpleTest.php
+++ b/src/Tests/FlagSimpleTest.php
@@ -14,7 +14,7 @@
/**
* Tests the Flag form actions (add/edit/delete).
*
- * @group Flag
+ * @group flag
*/
class FlagSimpleTest extends WebTestBase {
From 3345ca37132fb775f2971ff203f5b9b9b18b5c3b Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher
Date: Mon, 14 Jul 2014 11:47:35 +0200
Subject: [PATCH 455/629] Fix redirect on reload controller.
---
src/Controller/ReloadLinkController.php | 30 ++++++++++++-------------
src/FlaggingInterface.php | 10 ++++++++-
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/src/Controller/ReloadLinkController.php b/src/Controller/ReloadLinkController.php
index b4dc711..e8d0999 100644
--- a/src/Controller/ReloadLinkController.php
+++ b/src/Controller/ReloadLinkController.php
@@ -19,27 +19,27 @@
class ReloadLinkController extends ControllerBase {
public function flag(Request $request, $flag_id, $entity_id) {
-
+ /* @var \Drupal\flag\FlaggingInterface $flagging */
$flagging = \Drupal::service('flag')->flag($flag_id, $entity_id);
- // Get the destination.
- $destination = $request->get('destination', $flagging->getFlaggable()->url());
-
- //@todo SECURITY HOLE. Please fix!
- return new RedirectResponse($destination);
+ // Redirect back to the entity. A passed in destination query parameter
+ // will automatically override this.
+ $url_info = $flagging->getFlaggable()->urlInfo();
+ return $this->redirect($url_info->getRouteName(), $url_info->getRouteParameters());
}
public function unflag(Request $request, $flag_id, $entity_id) {
- $flagService = \Drupal::service('flag');
- $flagService->unflag($flag_id, $entity_id);
-
- $flag = $flagService->getFlagById($flag_id);
- $entity = $flagService->getFlaggableById($flag, $entity_id);
+ /* @var \Drupal\flag\FlagService $flag_service */
+ $flag_service = \Drupal::service('flag');
+ $flag_service->unflag($flag_id, $entity_id);
- $destination = \Drupal::request()->get('destination', $entity->url());
+ $flag = $flag_service->getFlagById($flag_id);
+ $entity = $flag_service->getFlaggableById($flag, $entity_id);
- //@todo SECURITY HOLE. Please fix!
- return new RedirectResponse($destination);
+ // Redirect back to the entity. A passed in destination query parameter
+ // will automatically override this.
+ $url_info = $entity->urlInfo();
+ return $this->redirect($url_info->getRouteName(), $url_info->getRouteParameters());
}
-}
\ No newline at end of file
+}
diff --git a/src/FlaggingInterface.php b/src/FlaggingInterface.php
index e75dc72..6fbe5b9 100644
--- a/src/FlaggingInterface.php
+++ b/src/FlaggingInterface.php
@@ -14,4 +14,12 @@ interface FlaggingInterface extends ContentEntityInterface {
public function getFlag();
-}
\ No newline at end of file
+ /**
+ * Returns the flaggable entity.
+ *
+ * @return \Drupal\Core\Entity\EntityInterface
+ * The entity object.
+ */
+ public function getFlaggable();
+
+}
From f6d736ac7edcbc48bc6a445bafb666ba614717e3 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher