Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
<?php
namespace Wgg\MailchimpBundle\Util;
use Pimcore\Cache;
use Pimcore\Model\DataObject\ClassDefinition\DynamicOptionsProvider\MultiSelectOptionsProviderInterface;
use Pimcore\Model\DataObject\ClassDefinition\DynamicOptionsProvider\SelectOptionsProviderInterface;
use Wgg\MailchimpBundle\WggMailchimpBundle;
use function implode;
use function md5;
class ListOptionsProvider implements MultiSelectOptionsProviderInterface, SelectOptionsProviderInterface
{
private ApiClient $apiClient;
public function __construct(ApiClient $apiClient)
{
$this->apiClient = $apiClient;
}
/**
* {@inheritdoc}
*/
public function getOptions($context, $fieldDefinition): array
{
return $this->getRawOptions();
}
/**
* {@inheritdoc}
*/
public function hasStaticOptions($context, $fieldDefinition): bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function getDefaultValue($context, $fieldDefinition)
{
return null;
}
/**
* @return array<array{key: string, value: string}>
*/
public function getRawOptions(): array
{
$data = [];
$listIds = $this->apiClient->getListIds();
if ($listIds) {
$cacheKey = $this->getCacheKey($listIds);
if (!$data = Cache::load($cacheKey)) {
Cache::clearTag(WggMailchimpBundle::CACHE_TAG);
foreach ($listIds as $listId) {
$list = $this->apiClient->lists->getList($listId, 'name,id');
$data[] = [
'key' => $list->name,
'value' => $list->id,
];
}
Cache::save($data, $cacheKey, [WggMailchimpBundle::CACHE_TAG]);
}
}
return $data;
}
private function getCacheKey(array $listIds): string
{
return md5(implode('|', $listIds));
}
}