Skip to content
Permalink
Browse files

Added an AbstractPickerProvider::getInsertTagChunks() to prevent repe…

…ated code
  • Loading branch information...
Toflar committed May 2, 2019
1 parent 1b2ac18 commit dc5d0b436f2a125c21f5c3173f6e371cf2aaefd6
@@ -47,9 +47,7 @@ public function supportsContext($context): bool
*/
public function supportsValue(PickerConfig $config): bool
{
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
return false !== strpos($config->getValue(), $insertTagChunks[0]);
return false !== strpos($config->getValue(), $this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG)[0]);
}
/**
@@ -72,9 +70,11 @@ public function getDcaAttributes(PickerConfig $config): array
}
if ($this->supportsValue($config)) {
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
$attributes['value'] = str_replace($insertTagChunks, '', $config->getValue());
$attributes['value'] = str_replace(
$this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG),
'',
$config->getValue()
);
}
return $attributes;
@@ -99,13 +99,13 @@ protected function getRouteParameters(PickerConfig $config = null): array
return $params;
}
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
$insertTagChunks = $this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG);
if (false === strpos($config->getValue(), $insertTagChunks[0])) {
return $params;
}
$value = str_replace($insertTagChunks, '', $config->getValue());
$value = str_replace($insertTagChunks, '', $config->getValue());
if (null !== ($calendarId = $this->getCalendarId($value))) {
$params['table'] = 'tl_calendar_events';
@@ -131,6 +131,15 @@ protected function getInsertTag(PickerConfig $config, string $default): string
return $default;
}
/**
* Provides a shortcut get the "insertTag" extra value for child classes and
* split them at the placeholder (%s).
*/
protected function getInsertTagChunks(PickerConfig $config, string $default): string
{
explode('%s', $this->getInsertTag($config, $default), 2);
}
/**
* Returns the routing parameters for the back end picker.
*
@@ -37,9 +37,7 @@ public function supportsContext($context): bool
*/
public function supportsValue(PickerConfig $config): bool
{
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
return false !== strpos($config->getValue(), $insertTagChunks[0]);
return false !== strpos($config->getValue(), $this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG)[0]);
}
/**
@@ -62,9 +60,11 @@ public function getDcaAttributes(PickerConfig $config): array
}
if ($this->supportsValue($config)) {
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
$attributes['value'] = str_replace($insertTagChunks, '', $config->getValue());
$attributes['value'] = str_replace(
$this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG),
'',
$config->getValue()
);
}
return $attributes;
@@ -66,9 +66,8 @@ public function supportsValue(PickerConfig $config): bool
return Validator::isUuid($value);
}
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
return false !== strpos($config->getValue(), $insertTagChunks[0]) || 0 === strpos($value, $this->uploadPath);
return false !== strpos($config->getValue(), $this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG)[0])
|| 0 === strpos($value, $this->uploadPath);
}
/**
@@ -105,7 +104,6 @@ public function convertDcaValue(PickerConfig $config, $value): string
$filesModel = $filesAdapter->findByPath(rawurldecode($value));
if ($filesModel instanceof FilesModel) {
return sprintf($this->getInsertTag($config, self::DEFAULT_INSERTTAG), StringUtil::binToUuid($filesModel->uuid));
}
@@ -185,8 +183,7 @@ private function getLinkDcaAttributes(PickerConfig $config): array
$value = $config->getValue();
if ($value) {
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
$insertTagChunks = $this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG);
if (false !== strpos($value, $insertTagChunks[0])) {
$value = str_replace($insertTagChunks, '', $value);
@@ -41,9 +41,7 @@ public function supportsValue(PickerConfig $config): bool
return is_numeric($config->getValue());
}
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
return false !== strpos($config->getValue(), $insertTagChunks[0]);
return false !== strpos($config->getValue(), $this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG)[0]);
}
/**
@@ -86,7 +84,7 @@ public function getDcaAttributes(PickerConfig $config): array
return $attributes;
}
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
$insertTagChunks = $this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG);
if ($value && false !== strpos($value, $insertTagChunks[0])) {
$attributes['value'] = str_replace($insertTagChunks, '', $value);
@@ -47,9 +47,7 @@ public function supportsContext($context): bool
*/
public function supportsValue(PickerConfig $config): bool
{
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
return false !== strpos($config->getValue(), $insertTagChunks[0]);
return false !== strpos($config->getValue(), $this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG)[0]);
}
/**
@@ -72,10 +70,11 @@ public function getDcaAttributes(PickerConfig $config): array
}
if ($this->supportsValue($config)) {
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
$attributes['value'] = str_replace($insertTagChunks, '', $config->getValue());
$attributes['value'] = str_replace(
$this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG),
'',
$config->getValue()
);
}
return $attributes;
@@ -96,11 +95,11 @@ protected function getRouteParameters(PickerConfig $config = null): array
{
$params = ['do' => 'faq'];
if (null === $config ||!$config->getValue()) {
if (null === $config || !$config->getValue()) {
return $params;
}
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
$insertTagChunks = $this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG);
if (false === strpos($config->getValue(), $insertTagChunks[0])) {
return $params;
@@ -47,9 +47,7 @@ public function supportsContext($context): bool
*/
public function supportsValue(PickerConfig $config): bool
{
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
return false !== strpos($config->getValue(), $insertTagChunks[0]);
return false !== strpos($config->getValue(), $this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG)[0]);
}
/**
@@ -72,9 +70,11 @@ public function getDcaAttributes(PickerConfig $config): array
}
if ($this->supportsValue($config)) {
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
$attributes['value'] = str_replace($insertTagChunks, '', $config->getValue());
$attributes['value'] = str_replace(
$this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG),
'',
$config->getValue()
);
}
return $attributes;
@@ -99,7 +99,7 @@ protected function getRouteParameters(PickerConfig $config = null): array
return $params;
}
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);
$insertTagChunks = $this->getInsertTagChunks($config, self::DEFAULT_INSERTTAG);
if (false === strpos($config->getValue(), $insertTagChunks[0])) {
return $params;

0 comments on commit dc5d0b4

Please sign in to comment.
You can’t perform that action at this time.