-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |