/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$config = $this->configFactory->get('youtube.settings');
$form['text'] = array('#type' => 'markup', '#markup' => '<p>' . t('The following settings will be used as default
values on all YouTube video fields. Many of these settings can be
overridden on a per-field basis.') . '</p>');
$form['youtube_global'] = array('#type' => 'fieldset', '#title' => t('Video parameters'));
$form['youtube_global']['youtube_suggest'] = array('#type' => 'checkbox', '#title' => t('Show suggested videos when the video finishes'), '#default_value' => $config->get('youtube_suggest'));
$form['youtube_global']['youtube_modestbranding'] = array('#type' => 'checkbox', '#title' => t('Do not show YouTube logo on video player control bar
(modestbranding).'), '#default_value' => $config->get('youtube_modestbranding'));
$form['youtube_global']['youtube_theme'] = array('#type' => 'checkbox', '#title' => t('Use a light colored control bar for video player controls
(theme).'), '#default_value' => $config->get('youtube_theme'));
$form['youtube_global']['youtube_color'] = array('#type' => 'checkbox', '#title' => t('Use a white colored video progress bar (color).'), '#default_value' => $config->get('youtube_color'), '#description' => t('Note: the modestbranding parameter will be ignored
when this is in use.'));
$form['youtube_global']['youtube_enablejsapi'] = array('#type' => 'checkbox', '#title' => t('Enable use of the IFrame API (enablejsapi, origin).'), '#default_value' => $config->get('youtube_enablejsapi'), '#description' => t('For more information on the IFrame API and how to use
it, see the <a href="@api_reference">IFrame API documentation</a>.', array('@api_reference' => 'https://developers.google.com/youtube/iframe_api_reference')));
$form['youtube_global']['youtube_wmode'] = array('#type' => 'checkbox', '#title' => t('Fix overlay problem on IE8 and lower'), '#default_value' => $config->get('youtube_wmode'), '#description' => t('Checking this will fix the issue of a YouTube video
showing above a modal window (including Drupal\'s Overlay). This is
needed if you have Overlay users in IE or have modal windows throughout
your site.'));
$form['youtube_thumbs'] = array('#type' => 'fieldset', '#title' => t('Thumbnails'));
$form['youtube_thumbs']['youtube_thumb_dir'] = array('#type' => 'textfield', '#title' => t('YouTube thumbnail directory'), '#field_prefix' => Settings::get('file_public_path', \Drupal::service('kernel')->getSitePath() . '/files') . '/', '#field_suffix' => '/thumbnail.jpg', '#description' => t('Location, within the files directory, where you would
like the YouTube thumbnails stored.'), '#default_value' => $config->get('youtube_thumb_dir'));
$form['youtube_thumbs']['youtube_thumb_hires'] = array('#type' => 'checkbox', '#title' => t('Save higher resolution thumbnail images'), '#description' => t('This will save thumbnails larger than the default
size, 480x360, to the thumbnails directory specified above.'), '#default_value' => $config->get('youtube_thumb_hires'));
$form['youtube_thumbs']['youtube_thumb_token_image_style'] = array('#type' => 'select', '#options' => image_style_options(TRUE), '#title' => t('Default token image style'), '#description' => t('Default image style for the output of a
youtube_image_url token.'), '#default_value' => $config->get('youtube_thumb_token_image_style'));
$form['youtube_thumbs']['youtube_thumb_delete_all'] = array('#type' => 'submit', '#value' => t('Refresh existing thumbnail image files'), '#submit' => array('youtube_thumb_delete_all'));
$form['youtube_privacy'] = array('#type' => 'checkbox', '#title' => t('Enable privacy-enhanced mode'), '#default_value' => $config->get('youtube_privacy'), '#description' => t('Checking this box will prevent YouTube from setting
cookies in your site visitors browser.'));
$form['youtube_player_class'] = array('#type' => 'textfield', '#title' => t('YouTube player class'), '#default_value' => $config->get('youtube_player_class'), '#description' => t('The iframe of every player will be given this class.
They will also be given IDs based off of this value.'));
return parent::buildForm($form, $form_state);
}
/**
* Returns a list of image style replacement options.
*
* @return array
* An option list suitable for the form select '#options'.
*/
protected function getReplacementOptions()
{
if (!isset($this->replacementOptions)) {
$this->replacementOptions = array_diff_key(image_style_options(), [$this->getEntity()->id() => '']);
}
return $this->replacementOptions;
}
/**
* Test creating an image style with a numeric name and ensuring it can be
* applied to an image.
*/
function testNumericStyleName()
{
$style_name = rand();
$style_label = $this->randomString();
$edit = array('name' => $style_name, 'label' => $style_label);
$this->drupalPostForm('admin/config/media/image-styles/add', $edit, t('Create new style'));
$this->assertRaw(t('Style %name was created.', array('%name' => $style_label)));
$options = image_style_options();
$this->assertTrue(array_key_exists($style_name, $options), format_string('Array key %key exists.', array('%key' => $style_name)));
}
/**
* {inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form['#form_horizontal'] = true;
$form['interface'] = ['#type' => 'fieldset', '#title' => $this->t("User interface")];
$form['interface'][APB_VAR_USER_PAGER_LIMIT] = ['#type' => 'select', '#title' => $this->t("User notification page limit"), '#options' => drupal_map_assoc([5, 10, 20, 30, 50, 100]), '#description' => $this->t("Number of notifications being displayed per page in user notification page."), '#default_value' => variable_get(APB_VAR_USER_PAGER_LIMIT, APB_DEF_USER_PAGER_LIMIT)];
$form['interface'][APB_VAR_USER_BLOCK_LIMIT] = ['#type' => 'select', '#title' => $this->t("User notification block limit"), '#options' => drupal_map_assoc([3, 5, 8, 10, 13, 15, 20]), '#description' => $this->t("Number of notifications being displayed per in the user notification block."), '#default_value' => variable_get(APB_VAR_USER_BLOCK_LIMIT, APB_DEF_USER_BLOCK_LIMIT)];
$form['interface'][APB_VAR_IMG_STYLE] = ['#type' => 'select', '#title' => $this->t("Notification image style"), '#empty_option' => $this->t("Do not display image"), '#options' => image_style_options(true), '#description' => $this->t("Number of notifications being displayed per page in user notification page."), '#default_value' => variable_get(APB_VAR_IMG_STYLE, APB_DEF_IMG_STYLE)];
$form['advanced'] = ['#type' => 'fieldset', '#title' => $this->t("Advanced / Performance")];
$form['advanced'][APB_VAR_ENABLE_PROD] = ['#type' => 'checkbox', '#title' => $this->t("Enable production mode"), '#description' => $this->t("Will suppress some warnings, errors and exceptions. Always check this option on a production site."), '#default_value' => variable_get(APB_VAR_ENABLE_PROD, APB_DEF_ENABLE_PROD)];
$form['advanced'][APB_VAR_ENABLE_FORMATTED_CONTENT] = ['#type' => 'checkbox', '#title' => $this->t("Store content inside messages"), '#description' => $this->t("If checked, formatted messages will be sent in the message contents instead of being formatted at view time. This will bypass translation but allows you to display those notifications outside of the originating website. If checked generated links inside formatted notifications will all be absolute. Note that if you change this setting and data has already been sent some notifications might not be displayed correctly."), '#default_value' => variable_get(APB_VAR_ENABLE_FORMATTED_CONTENT, APB_DEF_ENABLE_FORMATTED_CONTENT)];
return system_settings_form($form);
}
/**
* Overrides Drupal\Core\Entity\EntityForm::form().
*
* @param array $form
* A nested array form elements comprising the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* The array containing the complete form.
*/
public function form(array $form, FormStateInterface $form_state)
{
if ($this->operation == 'duplicate') {
$form['#title'] = $this->t('<em>Duplicate responsive image style</em> @label', array('@label' => $this->entity->label()));
$this->entity = $this->entity->createDuplicate();
}
if ($this->operation == 'edit') {
$form['#title'] = $this->t('<em>Edit responsive image style</em> @label', array('@label' => $this->entity->label()));
}
/** @var \Drupal\responsive_image\ResponsiveImageStyleInterface $responsive_image_style */
$responsive_image_style = $this->entity;
$form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $responsive_image_style->label(), '#description' => $this->t("Example: 'Hero image' or 'Author image'."), '#required' => TRUE);
$form['id'] = array('#type' => 'machine_name', '#default_value' => $responsive_image_style->id(), '#machine_name' => array('exists' => '\\Drupal\\responsive_image\\Entity\\ResponsiveImageStyle::load', 'source' => array('label')), '#disabled' => (bool) $responsive_image_style->id() && $this->operation != 'duplicate');
$image_styles = image_style_options(TRUE);
$image_styles[RESPONSIVE_IMAGE_ORIGINAL_IMAGE] = $this->t('- None (original image) -');
$image_styles[RESPONSIVE_IMAGE_EMPTY_IMAGE] = $this->t('- empty image -');
if ((bool) $responsive_image_style->id() && $this->operation != 'duplicate') {
$description = $this->t('Select a breakpoint group from the installed themes and modules. Below you can select which breakpoints to use from this group. You can also select which image style or styles to use for each breakpoint you use.') . ' ' . $this->t("Warning: if you change the breakpoint group you lose all your image style selections for each breakpoint.");
} else {
$description = $this->t('Select a breakpoint group from the installed themes and modules.');
}
$form['breakpoint_group'] = array('#type' => 'select', '#title' => $this->t('Breakpoint group'), '#default_value' => $responsive_image_style->getBreakpointGroup() ?: 'responsive_image', '#options' => $this->breakpointManager->getGroups(), '#required' => TRUE, '#description' => $description, '#ajax' => array('callback' => '::breakpointMappingFormAjax', 'wrapper' => 'responsive-image-style-breakpoints-wrapper'));
$form['keyed_styles'] = array('#type' => 'container', '#attributes' => array('id' => 'responsive-image-style-breakpoints-wrapper'));
// By default, breakpoints are ordered from smallest weight to largest:
// the smallest weight is expected to have the smallest breakpoint width,
// while the largest weight is expected to have the largest breakpoint
// width. For responsive images, we need largest breakpoint widths first, so
// we need to reverse the order of these breakpoints.
$breakpoints = array_reverse($this->breakpointManager->getBreakpointsByGroup($responsive_image_style->getBreakpointGroup()));
foreach ($breakpoints as $breakpoint_id => $breakpoint) {
foreach ($breakpoint->getMultipliers() as $multiplier) {
$label = $multiplier . ' ' . $breakpoint->getLabel() . ' [' . $breakpoint->getMediaQuery() . ']';
$form['keyed_styles'][$breakpoint_id][$multiplier] = array('#type' => 'details', '#title' => $label);
$image_style_mapping = $responsive_image_style->getImageStyleMapping($breakpoint_id, $multiplier);
if (\Drupal::moduleHandler()->moduleExists('help')) {
$description = $this->t('See the <a href=":responsive_image_help">Responsive Image help page</a> for information on the sizes attribute.', array(':responsive_image_help' => \Drupal::url('help.page', array('name' => 'responsive_image'))));
} else {
$description = $this->t('Enable the Help module for more information on the sizes attribute.');
}
$form['keyed_styles'][$breakpoint_id][$multiplier]['image_mapping_type'] = array('#title' => $this->t('Type'), '#type' => 'radios', '#options' => array('sizes' => $this->t('Select multiple image styles and use the sizes attribute.'), 'image_style' => $this->t('Select a single image style.'), '_none' => $this->t('Do not use this breakpoint.')), '#default_value' => isset($image_style_mapping['image_mapping_type']) ? $image_style_mapping['image_mapping_type'] : '_none', '#description' => $description);
$form['keyed_styles'][$breakpoint_id][$multiplier]['image_style'] = array('#type' => 'select', '#title' => $this->t('Image style'), '#options' => $image_styles, '#default_value' => isset($image_style_mapping['image_mapping']) && is_string($image_style_mapping['image_mapping']) ? $image_style_mapping['image_mapping'] : '', '#description' => $this->t('Select an image style for this breakpoint.'), '#states' => array('visible' => array(':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'image_style'))));
$form['keyed_styles'][$breakpoint_id][$multiplier]['sizes'] = array('#type' => 'textfield', '#title' => $this->t('Sizes'), '#default_value' => isset($image_style_mapping['image_mapping']['sizes']) ? $image_style_mapping['image_mapping']['sizes'] : '100vw', '#description' => $this->t('Enter the value for the sizes attribute, for example: %example_sizes.', ['%example_sizes' => '(min-width:700px) 700px, 100vw']), '#states' => array('visible' => array(':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'sizes')), 'required' => array(':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'sizes'))));
$form['keyed_styles'][$breakpoint_id][$multiplier]['sizes_image_styles'] = array('#title' => $this->t('Image styles'), '#type' => 'checkboxes', '#options' => array_diff_key($image_styles, array('' => '')), '#description' => $this->t('Select image styles with widths that range from the smallest amount of space this image will take up in the layout to the largest, bearing in mind that high resolution screens will need images 1.5x to 2x larger.'), '#default_value' => isset($image_style_mapping['image_mapping']['sizes_image_styles']) ? $image_style_mapping['image_mapping']['sizes_image_styles'] : array(), '#states' => array('visible' => array(':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'sizes')), 'required' => array(':input[name="keyed_styles[' . $breakpoint_id . '][' . $multiplier . '][image_mapping_type]"]' => array('value' => 'sizes'))));
// Expand the details if "do not use this breakpoint" was not selected.
if ($form['keyed_styles'][$breakpoint_id][$multiplier]['image_mapping_type']['#default_value'] != '_none') {
$form['keyed_styles'][$breakpoint_id][$multiplier]['#open'] = TRUE;
}
}
}
$form['fallback_image_style'] = array('#title' => $this->t('Fallback image style'), '#type' => 'select', '#default_value' => $responsive_image_style->getFallbackImageStyle(), '#options' => $image_styles, '#required' => TRUE, '#description' => t('Select the smallest image style you expect to appear in this space. The fallback image style should only appear on the site if an error occurs.'));
$form['#tree'] = TRUE;
return parent::form($form, $form_state, $responsive_image_style);
}
请发表评论