Example #1
0
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     $uid = $row->getDestinationProperty('uid');
     $module = $row->getDestinationProperty('module');
     $key = $row->getDestinationProperty('key');
     $this->userData->set($module, $uid, $key, $row->getDestinationProperty('settings'));
     return [$uid, $module, $key];
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $consumer_key = user_password(32);
     $consumer_secret = user_password(32);
     $key_hash = sha1($consumer_key);
     $uid = $form_state->getValue('uid');
     $consumer = array('consumer_secret' => $consumer_secret, 'key_hash' => $key_hash);
     $this->user_data->set('oauth', $uid, $consumer_key, $consumer);
     drupal_set_message($this->t('Added a new consumer.'));
     Cache::invalidateTags(['oauth:' . $uid]);
     $form_state->setRedirect('oauth.user_consumer', array('user' => $uid));
 }
 /**
  * Returns the list of consumers for a user.
  *
  * @param \Drupal\user\UserInterface $user
  *   A user account object.
  *
  * @return string
  *   A HTML-formatted string with the list of OAuth consumers.
  */
 public function consumers(UserInterface $user)
 {
     $list = array();
     $list['#cache']['tags'] = array('oauth:' => $user->id());
     $list['heading']['#markup'] = $this->linkGenerator->generate($this->t('Add consumer'), Url::fromRoute('oauth.user_consumer_add', array('user' => $user->id())));
     // Get the list of consumers.
     $result = $this->user_data->get('oauth', $user->id());
     // Define table headers.
     $list['table'] = array('#theme' => 'table', '#header' => array('consumer_key' => array('data' => $this->t('Consumer key')), 'consumer_secret' => array('data' => $this->t('Consumer secret')), 'operations' => array('data' => $this->t('Operations'))), '#rows' => array());
     // Add existing consumers to the table.
     foreach ($result as $key => $consumer) {
         $list['table']['#rows'][] = array('data' => array('consumer_key' => $key, 'consumer_secret' => $consumer['consumer_secret'], 'operations' => array('data' => array('#type' => 'operations', '#links' => array('delete' => array('title' => $this->t('Delete'), 'url' => Url::fromRoute('oauth.user_consumer_delete', array('user' => $user->id(), 'key' => $key))))))));
     }
     $list['table']['#empty'] = $this->t('There are no OAuth consumers.');
     return $list;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     $key = $values['key'];
     $uid = $values['uid'];
     $this->user_data->delete('oauth', $uid, $key);
     drupal_set_message($this->t('OAuth consumer deleted.'));
     Cache::invalidateTags(['oauth:' . $uid]);
     $form_state->setRedirect('oauth.user_consumer', array('user' => $form_state->getValue('uid')));
 }