Skip to content

Commit

Permalink
Added entry versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
Mosnar committed Sep 13, 2018
1 parent 839cb50 commit 2b30533
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/controllers/BulkEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@
*/
class BulkEditController extends Controller
{

// Protected Properties
// =========================================================================


// Public Methods
// =========================================================================

/**
* Return the file preview for an Asset.
*
Expand Down Expand Up @@ -135,6 +127,8 @@ public function actionGetEditScreen(): Response {
$baseEntry = null;
$view = \Craft::$app->getView();

// $baseElements = BulkEdit::$plugin->bulkEdit->getBaseElementForFieldIds($fieldIds);

$modalHtml = $view->renderTemplate('bulkedit/elementactions/BulkEdit/_edit', [
'fields' => $fieldModels,
'elementIds' => $elementIds,
Expand Down Expand Up @@ -175,7 +169,7 @@ public function actionSaveContext(): Response
$fieldId = $field->id;
}
}
if (!$fieldId) {
if ($fieldId === null) {
throw new \Exception('Failed to locate field');
}
$keyedFieldValues[$fieldId] = $value;
Expand Down
22 changes: 22 additions & 0 deletions src/services/BulkEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
namespace venveo\bulkedit\services;

use Craft;
use craft\base\Field;
use craft\elements\actions\Edit;
use craft\elements\Category;
use craft\elements\Entry;
use craft\models\FieldGroup;
use craft\records\Element;
use craft\records\FieldLayout;
use venveo\bulkedit\BulkEdit as Plugin;
Expand Down Expand Up @@ -59,6 +63,15 @@ public function getFieldLayoutsForElementIds($elementIds)
return $layouts;
}

public function getBaseElementForFieldIds($fieldIds) {
$elements = [];
//
// foreach($fieldIds as $fieldId) {
//
//// \Craft::$app->elements->getPlaceholderElement()
// }
}

public function getBulkEditContextFromId($id) {
return EditContext::findOne($id);
}
Expand Down Expand Up @@ -116,6 +129,15 @@ public function processHistoryItemsForElement($historyItems, \craft\base\Element
Craft::info('Saved history item', __METHOD__);
}
\Craft::$app->elements->saveElement($element, false);

switch (get_class($element)) {
case Entry::class:
\Craft::$app->entryRevisions->saveVersion($element);
break;
default:
break;
}

Craft::info('Saved element', __METHOD__);
$transaction->commit();
return $element;
Expand Down

0 comments on commit 2b30533

Please sign in to comment.