Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohutai committed Oct 12, 2023
1 parent 662b1df commit c8fffb4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
32 changes: 4 additions & 28 deletions src/Controller/Backend/Async/SelectOptionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,24 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use Tightenco\Collect\Support\Collection;
use Bolt\Cache\SelectOptionsCacher;

/**
* @Security("is_granted('upload')")
*/
class SelectOptionsController extends AbstractController implements AsyncZoneInterface
{
// use CsrfTrait;

/** @var Config */
private $config;

/** @var Request */
private $request;

/** @var FieldExtension */
private $fieldExtension;


public function __construct(Config $config,
RequestStack $requestStack,
SelectOptionsCacher $selectOptionsCacher)
public function __construct(Config $config, FieldExtension $fieldExtension)
{
$this->config = $config;
$this->request = $requestStack->getCurrentRequest();
$this->fieldExtension = $selectOptionsCacher;
$this->fieldExtension = $fieldExtension;
}

/**
Expand All @@ -48,8 +37,6 @@ public function __construct(Config $config,
*/
public function handleSelectOptions(Request $request): JsonResponse
{
// TODO: Need to get a field definition somewhere ...

[ $contentTypeSlug, $format ] = explode('/', $request->get('values'));

if (empty($maxAmount = $request->get('limit'))) {
Expand Down Expand Up @@ -80,19 +67,8 @@ public function handleSelectOptions(Request $request): JsonResponse

$field = $this->fieldExtension->fieldFactory($request->get('name'));

$options = array_merge($options, $this->fieldExtension->selectOptionsHelper($contentTypeSlug, $params, $field, $format)); // is this part cached?
$options = array_merge($options, $this->fieldExtension->selectOptionsHelper($contentTypeSlug, $params, $field, $format));

$response = new JsonResponse(new Collection($options));
/* -- This does NOT seem to work, we want to store responses so we won't DDOS ourselves.
$response->setCache([
'must_revalidate' => false,
'no_cache' => false,
'max_age' => 36000,
]);
*/

return $response;
return new JsonResponse(new Collection($options));
}


}
4 changes: 0 additions & 4 deletions src/Twig/FieldExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ public function selectOptionsUrl(Field\SelectField $field): String
'values' => $field->getDefinition()->get('values'),
'limit' => $field->getDefinition()->get('limit', ''),
'order' => $field->getDefinition()->get('order', ''),

]);
}

Expand Down Expand Up @@ -315,7 +314,6 @@ public function selectOptionsHelper(string $contentTypeSlug, array $params, Fiel
// If we use `cache/list_format`, delegate it to that Helper
if ($this->config->get('general/caching/list_format')) {
$options = $this->listFormatHelper->getSelect($contentTypeSlug, $params);
// dump($options);
return $options;
}

Expand All @@ -339,8 +337,6 @@ public function selectOptionsHelper(string $contentTypeSlug, array $params, Fiel
}
}

// dump($options);

return $options;
}
}

0 comments on commit c8fffb4

Please sign in to comment.