/** * {@inheritdoc} */ public function setKeyValue(KeyInterface $key, $key_value) { $name = $key->id(); $label = $key->label(); $encoded = $this->getConfiguration()['encoded'] ?: NULL; $client = Lockr::key()->encrypted(); try { $encoded = $client->set($name, $key_value, $label, $encoded); } catch (ClientException $e) { $body = $e->getMessage(); $data = json_decode($body, TRUE); if (isset($data['title']) && $data['title'] === 'Not paid') { drupal_set_message($this->t('NOTE: Key was not set. ' . 'Please go to <a href="@link">Lockr</a> and add a payment method.', ['@link' => 'https://lockr.io/user/add-card']), 'error'); } return FALSE; } catch (\Exception $e) { return FALSE; } $this->setConfiguration(['encoded' => $encoded]); return TRUE; }