extendOrOverwriteCore example


    public static function exceptionDataProvider(): iterable
    {
        yield SnippetException::SNIPPET_DUPLICATED_FIRST_LEVEL_KEY_EXCEPTION => [
            'exception' => SnippetException::duplicatedFirstLevelKey(['id1', 'id2', 'id3']),
            'statusCode' => Response::HTTP_CONFLICT,
            'errorCode' => SnippetException::SNIPPET_DUPLICATED_FIRST_LEVEL_KEY_EXCEPTION,
            'message' => 'The following keys on the first level are duplicated and can not be overwritten: id1, id2, id3',
        ];

        yield SnippetException::SNIPPET_EXTEND_OR_OVERWRITE_CORE_EXCEPTION => [
            'exception' => SnippetException::extendOrOverwriteCore(['id1', 'id2', 'id3']),
            'statusCode' => Response::HTTP_CONFLICT,
            'errorCode' => SnippetException::SNIPPET_EXTEND_OR_OVERWRITE_CORE_EXCEPTION,
            'message' => 'The following keys extend or overwrite the core snippets which is not allowed: id1, id2, id3',
        ];

        yield SnippetException::SNIPPET_DEFAULT_LANGUAGE_NOT_GIVEN_EXCEPTION => [
            'exception' => SnippetException::defaultLanguageNotGiven('languageId'),
            'statusCode' => Response::HTTP_BAD_REQUEST,
            'errorCode' => SnippetException::SNIPPET_DEFAULT_LANGUAGE_NOT_GIVEN_EXCEPTION,
            'message' => 'The following snippet file must always be provided when providing snippets: languageId',
        ];
    }
$newOrUpdatedSnippets = [];
        $existingSnippets = $this->getExistingSnippets($app->getId()$context);
        $coreSnippets = $this->getCoreAdministrationSnippets();

        $firstLevelSnippetKeys = [];
        foreach ($snippets as $snippetString) {
            $decodedSnippets = json_decode($snippetString, true, 512, \JSON_THROW_ON_ERROR);
            $firstLevelSnippetKeys = array_keys($decodedSnippets);
        }

        if ($duplicatedKeys = array_values(array_intersect(array_keys($coreSnippets)$firstLevelSnippetKeys))) {
            throw SnippetException::extendOrOverwriteCore($duplicatedKeys);
        }

        // only throw exception if snippets are given but not en-GB         if (!\array_key_exists('en-GB', $snippets) && !empty($snippets)) {
            throw SnippetException::defaultLanguageNotGiven('en-GB');
        }

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsAnyFilter('code', array_keys($snippets)));
        $localeIds = $this->localeRepository->search($criteria$context)->getEntities()->getElements();
        $localeIds = array_column($localeIds, 'id', 'code');

        
Home | Imprint | This part of the site doesn't use cookies.