Example #1
0
 public function flickr_photos(\Drupal\user\UserInterface $user = NULL)
 {
     global $pager_page_array, $pager_total, $pager_total_items;
     // Set this to something else if you want multiple pagers.
     $element = 0;
     $pager_page_array[$element] = empty($_GET['page']) ? 0 : (int) $_GET['page'];
     if ($user === NULL) {
         // @FIXME
         // Could not extract the default value because it is either indeterminate, or
         // not scalar. You'll need to provide a default value in
         // config/install/flickr.settings.yml and config/schema/flickr.schema.yml.
         $nsid = \Drupal::config('flickr.settings')->get('flickr_default_userid');
         if (!$nsid) {
             drupal_set_message(t('No default Flickr user id has been set.'));
             return FALSE;
         }
         $uid = 0;
     } else {
         $account = $user;
         if ($account->flickr['nsid']) {
             $nsid = $account->flickr['nsid'];
         } else {
             drupal_set_message(t('%user does not have a Flickr account', ['%user' => $account->name]), 'error');
             return FALSE;
         }
         $uid = $account->uid;
     }
     $nsid = flickr_user_find_by_identifier($nsid);
     $photos = flickr_photos_search($nsid, $pager_page_array[$element] + 1);
     if (!$photos) {
         drupal_set_message(t('No accessible photos found for Flickr %userid', ['%userid' => $nsid]), 'warning');
         return FALSE;
     }
     // Set pager information we just acquired.
     $pager_total[$element] = $photos['pages'];
     $pager_total_items[$element] = $photos['total'];
     // @FIXME
     // theme() has been renamed to _theme() and should NEVER be called directly.
     // Calling _theme() directly can alter the expected output and potentially
     // introduce security issues (see https://www.drupal.org/node/2195739). You
     // should use renderable arrays instead.
     //
     //
     // @see https://www.drupal.org/node/2195739
     // return theme('flickr_photos', array('uid' => $uid, 'photos' => $photos));
 }
 public function _submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state)
 {
     // Uncollapse the preview. Likely we want to see the changes we just made.
     \Drupal::configFactory()->getEditable('flickr.settings')->set('flickr_preview_collapsed', FALSE)->save();
     if (\Drupal::config('flickr.settings')->get('flickr_css') && \Drupal::moduleHandler()->moduleExists('style_settings')) {
         // Concatenate the caption font-size value and unit.
         \Drupal::configFactory()->getEditable('flickr.settings')->set('flickr_capsize', $form_state->getValue(['flickr_capsize_value']) . $form_state->getValue(['flickr_capsize_unit']))->save();
         // Concatenate the caption font-size value and unit.
         \Drupal::configFactory()->getEditable('flickr.settings')->set('flickr_sswidth', $form_state->getValue(['flickr_sswidth_value']) . $form_state->getValue(['flickr_sswidth_unit']))->save();
         $ssratio = $form_state->getValue(['flickr_sswidth_value']) * $form_state->getValue(['flickr_sshratio']) / $form_state->getValue(['flickr_sswratio']);
         $ssratio = $ssratio > 100 ? $ssratio . 'px' : $ssratio . '%';
         \Drupal::configFactory()->getEditable('flickr.settings')->set('flickr_slideshow_ratio', $ssratio)->save();
         // IMAGE URL: Reset to default if empty.
         if (\Drupal::moduleHandler()->moduleExists('flickrstyle')) {
             if (trim($form_state->getValue(['flickrstyle_magnifier_image'])) == '') {
                 $form_state->setValue(['flickrstyle_magnifier_image'], '/' . drupal_get_path('module', 'flickrstyle') . '/img/magnifier.png');
                 drupal_set_message(t('The image URL has been reset to the default.'), 'warning', FALSE);
             }
         }
     }
     // Reset to the default preview template if it is found empty.
     $trimmed = trim($form_state->getValue(['flickr_preview_html', 'value']));
     $form_state->setValue(['flickr_preview_html'], empty($trimmed) ? \Drupal::configFactory()->getEditable('flickr.settings')->set('flickr_preview_html', ['value' => '[flickr-user:id=lolandese1, size=q, num=2, sort=views]', 'format' => 'full_html'])->save() : $form_state->getValue(['flickr_preview_html']));
     // Optionally make changes visible after form submit.
     if ($form_state->getValue(['flickr_cc'])) {
         drupal_flush_all_caches();
         drupal_set_message(t('All caches are flushed.'), 'status', FALSE);
     } elseif (\Drupal::config('flickr.settings')->get('flickr_css') && \Drupal::moduleHandler()->moduleExists('style_settings')) {
         _drupal_flush_css_js();
     }
     // Clean up the data.
     $form_state->setValue(['flickr_api_key'], trim($form_state->getValue(['flickr_api_key'])));
     $form_state->setValue(['flickr_api_secret'], trim($form_state->getValue(['flickr_api_secret'])));
     $form_state->setValue(['flickr_photos_per_page'], trim($form_state->getValue(['flickr_photos_per_page'])));
     $form_state->setValue(['flickr_default_userid'], trim($form_state->getValue(['flickr_default_userid'])));
     // Replace the usernames with a uid.
     // As emails or usernames might change, replace them with a unique nsid.
     if (!flickr_is_nsid($form_state->getValue(['flickr_default_userid']))) {
         $userid = $form_state->getValue(['flickr_default_userid']);
         if (empty($userid)) {
             return;
         }
         if ($user = flickr_user_find_by_identifier($userid)) {
             drupal_set_message(t("The Flickr user associated with '%userid' has internally been replaced with the corresponding Flickr ID '%uid'.", ['%userid' => $form_state->getValue(['flickr_default_userid']), '%uid' => $user]));
             $form_state->setValue(['flickr_default_userid'], $user);
         }
     } else {
         $info = flickr_people_getinfo($form_state->getValue(['flickr_default_userid']));
         drupal_set_message(t("The Flickr user associated with '%uid' will be shown to you as Flickr user '%userid'.", ['%uid' => $form_state->getValue(['flickr_default_userid']), '%userid' => $info['username']['_content']]));
     }
 }