Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F804030
D253.id764.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 26, 9:04 AM
Size
6 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 9:04 AM (57 m, 46 s)
Engine
blob
Format
Raw Data
Handle
576745
Attached To
D253: INP-1590 - Add sub-item support to "AdminEditButton" tag
D253.id764.diff
View Options
Index: core/kernel/db/cat_event_handler.php
===================================================================
--- core/kernel/db/cat_event_handler.php
+++ core/kernel/db/cat_event_handler.php
@@ -155,8 +155,8 @@
*/
function _getMassPermissionEvents()
{
- return Array (
- 'OnEdit', 'OnSave', 'OnMassDelete', 'OnMassApprove',
+ return array(
+ 'OnStoreSelected', 'OnEdit', 'OnSave', 'OnMassDelete', 'OnMassApprove',
'OnMassDecline', 'OnMassMoveUp', 'OnMassMoveDown',
'OnCut',
);
Index: core/kernel/db/db_event_handler.php
===================================================================
--- core/kernel/db/db_event_handler.php
+++ core/kernel/db/db_event_handler.php
@@ -1602,6 +1602,10 @@
$this->_update($event);
$event->SetRedirectParam('opener', 'u');
+
+ if ( $event->status == kEvent::erSUCCESS ) {
+ $this->saveChangesToLiveTable($event->Prefix);
+ }
}
/**
@@ -1639,6 +1643,26 @@
}
/**
+ * Automatically saves data to live table after sub-item was updated in Content Mode.
+ *
+ * @param string $prefix Prefix.
+ *
+ * @return void
+ */
+ protected function saveChangesToLiveTable($prefix)
+ {
+ $parent_prefix = $this->Application->getUnitOption($prefix, 'ParentPrefix');
+
+ if ( $parent_prefix === false ) {
+ return;
+ }
+
+ if ( $this->Application->GetVar('admin') && $this->Application->IsTempMode($parent_prefix) ) {
+ $this->Application->HandleEvent(new kEvent($parent_prefix . ':OnSave'));
+ }
+ }
+
+ /**
* Delete's kDBItem object
*
* @param kEvent $event
Index: core/kernel/db/db_tag_processor.php
===================================================================
--- core/kernel/db/db_tag_processor.php
+++ core/kernel/db/db_tag_processor.php
@@ -2596,8 +2596,29 @@
$button_title = $this->Application->Phrase($button_title, false, true);
}
+ if ( !isset($params['pass']) ) {
+ $params['pass'] = 'm,' . $item_prefix;
+ }
+
+ $edit_prefix = $item_prefix;
+ list($parent_prefix, $parent_id) = $this->getParentPrefixAndId($object);
+
+ if ( $parent_prefix !== false ) {
+ $edit_prefix = $parent_prefix;
+ $params[$parent_prefix . '_id'] = $parent_id;
+ $params['pass'] = $parent_prefix . ',' . $params['pass'];
+ }
+
$icon_url = $this->Application->BaseURL() . 'core/admin_templates/img/top_frame/icons/' . $button_icon;
- $button_onclick = '$form_name = ' . json_encode($form_name) . '; std_edit_item(' . json_encode($item_prefix) . ', ' . json_encode($template) . '); return false;';
+
+ if ( !isset($params['temp_mode']) || (isset($params['temp_mode']) && $params['temp_mode']) ) {
+ $edit_function = 'std_edit_item';
+ }
+ else {
+ $edit_function = 'std_edit_temp_item';
+ }
+
+ $button_onclick = '$form_name = ' . json_encode($form_name) . '; ' . $edit_function . '(' . json_encode($edit_prefix) . ', ' . json_encode($template) . '); return false;';
$button_code = '<button
style="background-image: url(' . $icon_url . ');"
@@ -2606,18 +2627,8 @@
kUtil::escape($button_title, kUtil::ESCAPE_HTML) . '
</button>';
- if ( !isset($params['pass']) ) {
- $params['pass'] = 'm,' . $item_prefix;
- }
-
$params['m_opener'] = 'd';
$params[$item_prefix . '_id'] = $object->GetID();
-
- if ( !isset($params['temp_mode']) || (isset($params['temp_mode']) && $params['temp_mode']) ) {
- $params[$item_prefix . '_mode'] = 't';
- $params[$item_prefix . '_event'] = 'OnEdit';
- }
-
$params['front'] = 1; // to make opener stack work properly
$params['__NO_REWRITE__'] = 1; // since admin link
@@ -2640,6 +2651,55 @@
}
/**
+ * Returns parent record ID.
+ *
+ * @param kDBBase $object Object.
+ *
+ * @return array
+ */
+ protected function getParentPrefixAndId(kDBBase $object)
+ {
+ static $parent_mapping = array();
+
+ $parent_prefix = $this->Application->getUnitOption($object->Prefix, 'ParentPrefix');
+
+ if ( $parent_prefix === false ) {
+ return array(false, null);
+ }
+
+ $foreign_key = $this->Application->getUnitOption($object->Prefix, 'ForeignKey');
+ $foreign_key = is_array($foreign_key) ? $foreign_key[$parent_prefix] : $foreign_key;
+
+ $parent_table_key = $this->Application->getUnitOption($object->Prefix, 'ParentTableKey');
+ $parent_table_key = is_array($parent_table_key) ? $parent_table_key[$parent_prefix] : $parent_table_key;
+
+ $parent_id_field = $this->Application->getUnitOption($parent_prefix, 'IDField');
+ $parent_id = $object->GetDBField($foreign_key);
+
+ if ( $parent_table_key != $parent_id_field ) {
+ $cache_key = $object->getPrefixSpecial();
+
+ if ( !isset($parent_mapping[$cache_key]) ) {
+ $foreign_key_values = array_unique($object->GetCol($foreign_key));
+
+ $sql = 'SELECT ' . $parent_id_field . ', ' . $parent_table_key . '
+ FROM ' . $this->Application->getUnitOption($parent_prefix, 'TableName') . '
+ WHERE ' . $parent_table_key . ' IN (' . implode(',', $foreign_key_values) . ')';
+ $parent_mapping[$cache_key] = $this->Conn->GetCol($sql, $parent_table_key);
+ }
+
+ // Parent record was deleted, but child record is still referencing it.
+ if ( !isset($parent_mapping[$cache_key][$parent_id]) ) {
+ return array(false, null);
+ }
+
+ $parent_id = $parent_mapping[$cache_key][$parent_id];
+ }
+
+ return array($parent_prefix, $parent_id);
+ }
+
+ /**
* Calls OnNew event from template, when no other event submitted
*
* @param Array $params
Index: core/units/categories/categories_event_handler.php
===================================================================
--- core/units/categories/categories_event_handler.php
+++ core/units/categories/categories_event_handler.php
@@ -149,8 +149,8 @@
*/
function _getMassPermissionEvents()
{
- return Array (
- 'OnEdit', 'OnSave', 'OnMassDelete', 'OnMassApprove',
+ return array(
+ 'OnStoreSelected', 'OnEdit', 'OnSave', 'OnMassDelete', 'OnMassApprove',
'OnMassDecline', 'OnMassMoveUp', 'OnMassMoveDown',
'OnCut',
);
Index: core/units/content/content_tp.php
===================================================================
--- core/units/content/content_tp.php
+++ core/units/content/content_tp.php
@@ -29,11 +29,6 @@
return '';
}
- /** @var kDBItem $object */
- $object = $this->getObject($params);
-
- $params['pass'] = 'm,c,content';
- $params['c_id'] = $object->GetDBField('PageId');
$params['admin'] = 1;
$params['temp_mode'] = 0;
@@ -50,4 +45,5 @@
return parent::AdminEditButton($params);
}
-}
\ No newline at end of file
+
+}
Event Timeline
Log In to Comment