Skip to content

Commit

Permalink
Edit this content type button
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Valchev committed Jun 16, 2020
1 parent 450e421 commit c827a53
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/EditPageWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace IvoValchev\EditThisPageExtension;

use Bolt\Widget\BaseWidget;
use Bolt\Widget\Injector\RequestZone;
use Bolt\Widget\Injector\Target;
use Bolt\Widget\StopwatchAwareInterface;
use Bolt\Widget\StopwatchTrait;
use Bolt\Widget\TwigAwareInterface;

class EditPageWidget extends BaseWidget implements TwigAwareInterface, StopwatchAwareInterface
{
use StopwatchTrait;

protected $name = 'Edit This Page Widget';
protected $target = Target::END_OF_BODY;
protected $priority = 300;
protected $template = '@edit-this-page-widget/edit-button.html.twig';
protected $zone = RequestZone::FRONTEND;
protected $cacheDuration = 0;

public function run(array $params = []): ?string
{
$content = isset($this->getTwig()->getGlobals()['record']) ? $this->getTwig()->getGlobals()['record'] : null;

return parent::run(['content' => $content]);
}

}
18 changes: 18 additions & 0 deletions src/Extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace IvoValchev\EditThisPageExtension;

use Bolt\Extension\BaseExtension;

class Extension extends BaseExtension
{
public function getName(): string
{
return 'Edit This Page Extension';
}

public function initialize(): void
{
$this->addWidget(new EditPageWidget());
}
}
13 changes: 13 additions & 0 deletions templates/edit-button.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% if content is not null and content|edit_link %}
<form action="{{ content|edit_link }}" class="bolt-edit-this-page">
<button type="submit">Edit {{ content.definition.singular_name|default(content.definition.singular_slug) }}</button>
</form>
<style>
.bolt-edit-this-page {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
}
</style>
{% endif %}

0 comments on commit c827a53

Please sign in to comment.