/** * Autocomplete the label of an entity. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object that contains the typed tags. * @param string $target_type * The ID of the target entity type. * @param string $selection_handler * The plugin ID of the entity reference selection handler. * @param string $selection_settings_key * The hashed key of the key/value entry that holds the selection handler * settings. * * @return \Symfony\Component\HttpFoundation\JsonResponse * The matched entity labels as a JSON response. * * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException * Thrown if the selection settings key is not found in the key/value store * or if it does not match the stored data. */ public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key) { $matches = array(); // Get the typed string from the URL, if it exists. if ($input = $request->query->get('q')) { $typed_string = Tags::explode($input); $typed_string = Unicode::strtolower(array_pop($typed_string)); // Selection settings are passed in as a hashed key of a serialized array // stored in the key/value store. $selection_settings = $this->keyValue->get($selection_settings_key, FALSE); if ($selection_settings !== FALSE) { $selection_settings_hash = Crypt::hmacBase64(serialize($selection_settings) . $target_type . $selection_handler, Settings::getHashSalt()); if ($selection_settings_hash !== $selection_settings_key) { // Disallow access when the selection settings hash does not match the // passed-in key. throw new AccessDeniedHttpException('Invalid selection settings key.'); } } else { // Disallow access when the selection settings key is not found in the // key/value store. throw new AccessDeniedHttpException(); } $matches = $this->matcher->getMatches($target_type, $selection_handler, $selection_settings, $typed_string); } return new JsonResponse($matches); }
/** * Filters out already executed update functions by module. * * @param string $module * The module name. */ public function filterOutInvokedUpdatesByModule($module) { $existing_update_functions = $this->keyValue->get('existing_updates', []); $remaining_update_functions = array_filter($existing_update_functions, function ($function_name) use($module) { return strpos($function_name, "{$module}_{$this->updateType}_") !== 0; }); $this->keyValue->set('existing_updates', array_values($remaining_update_functions)); }
/** * Executes a callback. * * @param \Drupal\feeds\FeedInterface $feeds_feed * The Feed we are executing a job for. * @param \Symfony\Component\HttpFoundation\Request $request * The request object to grab POST params from. * * @todo Configure a time limit. * @todo Really awesome error handling. */ public function execute(FeedInterface $feeds_feed, Request $request) { $cid = 'feeds_feed:' . $feeds_feed->id(); if ($token = $request->request->get('token') && ($job = $this->state->get($cid))) { if ($job['token'] == $token && ($lock = $this->lockBackend->acquire($cid))) { $method = $job['method']; $this->state->delete($cid); ignore_user_abort(TRUE); set_time_limit(0); while ($feeds_feed->{$method}() != StateInterface::BATCH_COMPLETE) { // Reset static caches in between runs to avoid memory leaks. drupal_reset_static(); } $this->lockBackend->release($cid); } } }
/** * {@inheritdoc} */ public function getLastInstalledFieldStorageDefinitions($entity_type_id) { return $this->installedDefinitions->get($entity_type_id . '.field_storage_definitions', array()); }