Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/main/i6328 improved localization #69

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions CustomBlockManagerPlugin.inc.php
Expand Up @@ -14,9 +14,13 @@
*
*/

use APP\core\Application;
use APP\template\TemplateManager;
use PKP\linkAction\LinkAction;
use PKP\plugins\GenericPlugin;
use PKP\linkAction\request\AjaxModal;
use PKP\plugins\GenericPlugin;
use PKP\plugins\HookRegistry;
use PKP\plugins\PluginRegistry;

class CustomBlockManagerPlugin extends GenericPlugin
{
Expand Down Expand Up @@ -47,7 +51,7 @@ public function register($category, $path, $mainContextId = null)
// If the system isn't installed, or is performing an upgrade, don't
// register hooks. This will prevent DB access attempts before the
// schema is installed.
if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) {
if (Application::isUnderMaintenance()) {
return true;
}

Expand Down Expand Up @@ -92,7 +96,7 @@ public function register($category, $path, $mainContextId = null)
/**
* Permit requests to the custom block grid handler
*
* @param $hookName string The name of the hook being invoked
* @param string $hookName The name of the hook being invoked
*/
public function setupGridHandler($hookName, $params)
{
Expand Down Expand Up @@ -148,7 +152,7 @@ public function manage($args, $request)
'customBlockGridUrlGridContainer',
$dispatcher->url(
$request,
PKPApplication::ROUTE_COMPONENT,
Application::ROUTE_COMPONENT,
null,
'plugins.generic.customBlockManager.controllers.grid.CustomBlockGridHandler',
'fetchGrid'
Expand All @@ -164,7 +168,7 @@ public function manage($args, $request)
*
* @see PluginGridRow::_canEdit()
*
* @return boolean
* @return bool
*/
public function isSitePlugin()
{
Expand Down
12 changes: 8 additions & 4 deletions CustomBlockPlugin.inc.php
Expand Up @@ -16,6 +16,10 @@

import('lib.pkp.classes.plugins.BlockPlugin');

use APP\core\Application;
use PKP\facades\Locale;
use PKP\plugins\BlockPlugin;

class CustomBlockPlugin extends BlockPlugin
{
/** @var string Name of this block plugin */
Expand All @@ -27,8 +31,8 @@ class CustomBlockPlugin extends BlockPlugin
/**
* Constructor
*
* @param $blockName string Name of this block plugin.
* @param $parentPlugin CustomBlockManagerPlugin Custom block plugin management plugin.
* @param string $blockName Name of this block plugin.
* @param CustomBlockManagerPlugin $parentPlugin Custom block plugin management plugin.
*/
public function __construct($blockName, $parentPlugin)
{
Expand Down Expand Up @@ -88,7 +92,7 @@ public function getHideManagement()
*/
public function getEnabled($contextId = null)
{
if (!Config::getVar('general', 'installed')) {
if (!Application::isInstalled()) {
return true;
}
return parent::getEnabled($contextId);
Expand Down Expand Up @@ -123,7 +127,7 @@ public function getContents($templateMgr, $request = null)
// Get the block contents.
$customBlockTitle = $this->getSetting($contextId, 'blockTitle');
$customBlockContent = $this->getSetting($contextId, 'blockContent');
$currentLocale = AppLocale::getLocale();
$currentLocale = Locale::getLocale();
$contextPrimaryLocale = $context ? $context->getPrimaryLocale() : $request->getSite()->getPrimaryLocale();

$divCustomBlockId = 'customblock-' . preg_replace('/\W+/', '-', $this->getName());
Expand Down
29 changes: 15 additions & 14 deletions controllers/grid/CustomBlockGridHandler.inc.php
Expand Up @@ -13,12 +13,14 @@
* @brief Handle custom block manager grid requests.
*/

use PKP\controllers\grid\GridColumn;
use PKP\controllers\grid\GridHandler;
use PKP\security\Role;
use PKP\core\JSONMessage;
use PKP\db\DAO;
use PKP\db\DAORegistry;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\core\JSONMessage;
use PKP\controllers\grid\GridColumn;
use PKP\security\Role;

import('plugins.generic.customBlockManager.controllers.grid.CustomBlockGridRow');

Expand Down Expand Up @@ -131,8 +133,8 @@ public function getRowInstance()
/**
* An action to add a new custom block
*
* @param $args array Arguments to the request
* @param $request PKPRequest Request object
* @param array $args Arguments to the request
* @param PKPRequest $request Request object
*/
public function addCustomBlock($args, $request)
{
Expand All @@ -144,8 +146,8 @@ public function addCustomBlock($args, $request)
/**
* An action to edit a custom block
*
* @param $args array Arguments to the request
* @param $request PKPRequest Request object
* @param array $args Arguments to the request
* @param PKPRequest $request Request object
*
* @return string Serialized JSON object
*/
Expand Down Expand Up @@ -176,8 +178,8 @@ public function editCustomBlock($args, $request)
/**
* Update a custom block
*
* @param $args array
* @param $request PKPRequest
* @param array $args
* @param PKPRequest $request
*
* @return string Serialized JSON object
*/
Expand Down Expand Up @@ -208,17 +210,16 @@ public function updateCustomBlock($args, $request)
// Save the results
$customBlockForm->execute();
return DAO::getDataChangedEvent();
} else {
// Present any errors
return new JSONMessage(true, $customBlockForm->fetch($request));
}
// Present any errors
return new JSONMessage(true, $customBlockForm->fetch($request));
}

/**
* Delete a custom block
*
* @param $args array
* @param $request PKPRequest
* @param array $args
* @param PKPRequest $request
*
* @return string Serialized JSON object
*/
Expand Down
2 changes: 1 addition & 1 deletion controllers/grid/CustomBlockGridRow.inc.php
Expand Up @@ -13,8 +13,8 @@
* @brief Handle custom blocks grid row requests.
*/

use PKP\linkAction\request\AjaxModal;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\linkAction\request\RemoteActionConfirmationModal;

// FIXME: add namespacing
Expand Down
19 changes: 10 additions & 9 deletions controllers/grid/form/CustomBlockForm.inc.php
Expand Up @@ -14,7 +14,11 @@
*
*/

use APP\template\TemplateManager;
use PKP\facades\Locale;
use PKP\form\Form;
use PKP\plugins\PluginRegistry;
use Stringy\Stringy;

class CustomBlockForm extends Form
{
Expand All @@ -27,9 +31,9 @@ class CustomBlockForm extends Form
/**
* Constructor
*
* @param $template string the path to the form template file
* @param $contextId int
* @param $plugin CustomBlockPlugin
* @param string $template the path to the form template file
* @param int $contextId
* @param CustomBlockPlugin $plugin
*/
public function __construct($template, $contextId, $plugin = null)
{
Expand Down Expand Up @@ -86,18 +90,15 @@ public function execute(...$functionArgs)
$plugin = $this->plugin;
$contextId = $this->contextId;
if (!$plugin) {
$locale = AppLocale::getLocale();
$locale = Locale::getLocale();

// Add the custom block to the list of the custom block plugins in the
// custom block manager plugin
$customBlockManagerPlugin = PluginRegistry::getPlugin('generic', CUSTOMBLOCKMANAGER_PLUGIN_NAME);
$blocks = $customBlockManagerPlugin->getSetting($contextId, 'blocks');
if (!isset($blocks)) {
$blocks = [];
}
$blocks = $customBlockManagerPlugin->getSetting($contextId, 'blocks') ?? [];


$blockName = \Stringy\Stringy::create($this->getData('blockTitle')[$locale])->toLowerCase()->dasherize()->regexReplace('[^a-z0-9\-\_.]', '');
$blockName = Stringy::create($this->getData('blockTitle')[$locale])->toLowerCase()->dasherize()->regexReplace('[^a-z0-9\-\_.]', '');
if (in_array($blockName, $blocks)) {
$blockName = uniqid($blockName);
}
Expand Down