Skip to content
Snippets Groups Projects
Commit ca0af577 authored by George's avatar George
Browse files

Clean up code. Rename settings form class. Add scheme constant. Remove debug flag/config.

parent 932ed5be
No related branches found
No related tags found
No related merge requests found
az_blob_fs.settings_form:
path: '/admin/config/media/az_blob_fs'
defaults:
_form: '\Drupal\az_blob_fs\Form\SettingsForm'
_form: '\Drupal\az_blob_fs\Form\AzBlobFsSettingsForm'
_title: 'Azure Blob Storage File System'
requirements:
_permission: 'access administration pages'
_permission: 'administer az_blob_fs'
options:
_admin_route: TRUE
......
az_blob_debug: 0
az_blob_account_name: ''
az_blob_container_name: ''
az_blob_local_ip: ''
......
......@@ -3,9 +3,6 @@ az_blob_fs.settings:
type: config_object
label: 'Azure Blog Storage config settings'
mapping:
az_blob_debug:
type: integer
label: 'Debug Mode'
az_blob_account_name:
type: string
label: 'Account Name'
......
......@@ -6,9 +6,9 @@ use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class SettingsForm.
* Class AzBlobFsSettingsForm.
*/
class SettingsForm extends ConfigFormBase {
class AzBlobFsSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
......@@ -35,13 +35,6 @@ class SettingsForm extends ConfigFormBase {
$form['#prefix'] = '<div id="azblob-form-wrapper">';
$form['#suffix'] = '</div>';
$form['az_blob_debug'] = [
'#type' => 'checkbox',
'#title' => $this->t('Debugging'),
'#description' => $this->t('Enable/disable debugging of stream wrapper. Generates more logs in watchdog log.'),
'#default_value' => !empty($config->get('az_blob_debug')) ? $config->get('az_blob_debug') : 0,
];
$form['az_blob_account_name'] = [
'#type' => 'textfield',
'#title' => $this->t('Account Name'),
......@@ -164,7 +157,6 @@ class SettingsForm extends ConfigFormBase {
$account_key = $form_state->getValue('az_blob_account_key');
$config
->set('az_blob_debug', $form_state->getValue('az_blob_debug'))
->set('az_blob_account_name', $form_state->getValue('az_blob_account_name'))
->set('az_blob_container_name', $form_state->getValue('az_blob_container_name'))
->set('az_blob_local_ip', $form_state->getValue('az_blob_local_ip'))
......@@ -175,6 +167,7 @@ class SettingsForm extends ConfigFormBase {
if (!empty($account_key) && strpos($account_key, '*', 0) === FALSE)
$config->set('az_blob_account_key', $form_state->getValue('az_blob_account_key'));
// Save config
$config->save();
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\az_blob_fs\PathProcessor;
use Drupal\az_blob_fs\Constants\AzBlobFsConstants;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;
......@@ -25,30 +26,25 @@ use Symfony\Component\HttpFoundation\Request;
*/
class AzBlobFsPathProcessorImageStyles implements InboundPathProcessorInterface {
const IMAGE_STYLE_PATH_PREFIX = '/azblob/files/styles/';
const IMAGE_STYLE_PATH_PREFIX = '/' . AzBlobFsConstants::SCHEME . '/files/styles/';
/**
* {@inheritdoc}
*/
public function processInbound($path, Request $request) {
if ($this->isImageStylePath($path)) {
// Strip out path prefix.
$rest = preg_replace('|^' . preg_quote(static::IMAGE_STYLE_PATH_PREFIX, '|') . '|', '', $path);
// Get the image style, scheme and path.
if (substr_count($rest, '/') >= 2) {
list($image_style, $scheme, $file) = explode('/', $rest, 3);
if ($this->isValidScheme($scheme)) {
// Set the file as query parameter.
$request->query->set('file', $file);
$path = static::IMAGE_STYLE_PATH_PREFIX . $image_style . '/' . $scheme;
}
}
}
return $path;
}
......@@ -74,7 +70,7 @@ class AzBlobFsPathProcessorImageStyles implements InboundPathProcessorInterface
* TRUE if azblob will generate image styles, FALSE otherwise.
*/
private function isValidScheme($scheme) {
return in_array($scheme, ['public', 'azblob']);
return in_array($scheme, ['public', AzBlobFsConstants::SCHEME]);
}
}
......@@ -2,6 +2,7 @@
namespace Drupal\az_blob_fs\Routing;
use Drupal\az_blob_fs\Constants\AzBlobFsConstants;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -49,7 +50,7 @@ class AzBlobFsImageStyleRoutes implements ContainerInjectionInterface {
// Only add route for image styles if image module is enabled.
if ($this->moduleHandler->moduleExists('image')) {
$routes['az_blob_fs.image_styles'] = new Route(
'/azblob/files/styles/{image_style}/{scheme}',
'/' . AzBlobFsConstants::SCHEME . '/files/styles/{image_style}/{scheme}',
[
'_controller' => 'Drupal\az_blob_fs\Controller\AzBlobFsImageStyleDownloadController::deliver',
],
......
......@@ -3,6 +3,7 @@
namespace Drupal\az_blob_fs\StreamWrapper;
use ArrayObject;
use Drupal\az_blob_fs\Constants\AzBlobFsConstants;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
......@@ -121,8 +122,8 @@ class AzBlobFsStream extends AzBlobFsStreamWrapper implements StreamWrapperInter
// Handle image styles
if (strpos($target, 'styles/') === 0) {
// If the style derivative does not exist yet, we return to our custom image style path handler.
if (!file_exists('azblob://' . $target)) {
return $GLOBALS['base_url'] . '/azblob/files/' . UrlHelper::encodePath($target);
if (!file_exists(AzBlobFsConstants::SCHEME . '://' . $target)) {
return $GLOBALS['base_url'] . '/' . AzBlobFsConstants::SCHEME . '/files/' . UrlHelper::encodePath($target);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment