-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#174 Ajout du FileManager aux formulaires des contenus.
- Loading branch information
Showing
4 changed files
with
140 additions
and
2 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
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,99 @@ | ||
<?php | ||
|
||
namespace SoosyzeCore\Node\Services; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Soosyze\Components\Form\FormBuilder; | ||
|
||
class HookFileManager | ||
{ | ||
private $core; | ||
|
||
private $hasFileManager; | ||
|
||
/** | ||
* @var \Soosyze\Components\Router\Router | ||
*/ | ||
private $router; | ||
|
||
public function __construct($core, $module, $router) | ||
{ | ||
$this->core = $core; | ||
$this->router = $router; | ||
|
||
$this->hasFileManager = $module->has('FileManager'); | ||
} | ||
|
||
public function hookNodeCreateForm(FormBuilder &$form, $content, $type) | ||
{ | ||
if (!$this->hasFileManager) { | ||
return; | ||
} | ||
|
||
$form->append('fields-fieldset', function ($form) { | ||
$form->group('files-fieldset', 'div', function ($form) { | ||
$response = '<div class="col-md-12">' | ||
. '<div class="alert alert-info">' | ||
. t('NOTE: You cannot add media files until you save the page. Just click \'Save\' on top') | ||
. '</div>' | ||
. '</div>'; | ||
|
||
$form->legend('files-legend', t('Files')) | ||
->html('key', '<div:attr>:_content</div>', [ | ||
'_content' => $response, | ||
'class' => 'row', | ||
'id' => 'filemanager' | ||
]); | ||
}); | ||
}); | ||
} | ||
|
||
public function hookNodeEditForm(FormBuilder &$form, $content) | ||
{ | ||
if (!$this->hasFileManager) { | ||
return; | ||
} | ||
|
||
$request = $this->router->getRequestByRoute('filemanager.show', [ | ||
':path' => "/node/{$content[ 'type' ]}/{$content[ 'id' ]}" | ||
]); | ||
$this->getFileManager($form, $request); | ||
} | ||
|
||
public function hookEntityForm(FormBuilder &$form, $content, $node, $entity) | ||
{ | ||
if (!$this->hasFileManager) { | ||
return; | ||
} | ||
|
||
$request = $this->router->getRequestByRoute('filemanager.show', [ | ||
':path' => "/node/{$node[ 'type' ]}/{$node[ 'id' ]}/$entity" | ||
]); | ||
$this->getFileManager($form, $request); | ||
} | ||
|
||
protected function getFileManager(FormBuilder &$form, $request) | ||
{ | ||
$response = '<div class="col-md-12">' | ||
. '<div class="alert alert-info">' | ||
. t('You do not have the necessary permissions to use the file manager') | ||
. '</div>' | ||
. '</div>'; | ||
|
||
if ($this->core->callHook('app.granted.route', [ $request ])) { | ||
$route = $this->router->parse($request); | ||
$response = $this->router->execute($route, $request); | ||
} | ||
|
||
$form->append('fields-fieldset', function ($form) use ($response) { | ||
$form->group('files-fieldset', 'div', function ($form) use ($response) { | ||
$form->legend('files-legend', t('Files')) | ||
->html('key', '<div:attr>:_content</div>', [ | ||
'_content' => $response, | ||
'class' => 'row', | ||
'id' => 'filemanager' | ||
]); | ||
}); | ||
}); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,14 +1,29 @@ | ||
|
||
<?php echo $node_submenu; ?> | ||
<?php if (!empty($node_submenu)): ?> | ||
<?php echo $node_submenu; ?> | ||
<?php endif; ?> | ||
|
||
<div class="row"> | ||
<?php if (!empty($node_fieldset_submenu)): ?> | ||
<div class="col-md-3 sticky"> | ||
<?php echo $node_fieldset_submenu; ?> | ||
</div> | ||
|
||
<div class="col-md-9"> | ||
<div class="tab-content"> | ||
<?php echo $form; ?> | ||
</div> | ||
</div> | ||
<?php else: ?> | ||
<div class="col-md-12"> | ||
<div class="tab-content"> | ||
<?php echo $form; ?> | ||
</div> | ||
</div> | ||
<?php endif; ?> | ||
|
||
<div id="modal_filemanager" class="modal" role="dialog" aria-label="<?php echo t('File actions window'); ?>"> | ||
<div class="modal-dialog modal-lg" role="document"> | ||
<div class="modal-content"></div> | ||
</div> | ||
</div> | ||
</div> |