Chris@0: getImageUploadSettings(); Chris@0: $image_upload += [ Chris@0: 'status' => FALSE, Chris@0: 'scheme' => file_default_scheme(), Chris@0: 'directory' => 'inline-images', Chris@0: 'max_size' => '', Chris@0: 'max_dimensions' => ['width' => '', 'height' => ''], Chris@0: ]; Chris@0: Chris@0: $form['status'] = [ Chris@0: '#type' => 'checkbox', Chris@0: '#title' => t('Enable image uploads'), Chris@0: '#default_value' => $image_upload['status'], Chris@0: '#attributes' => [ Chris@0: 'data-editor-image-upload' => 'status', Chris@0: ], Chris@0: ]; Chris@0: $show_if_image_uploads_enabled = [ Chris@0: 'visible' => [ Chris@0: ':input[data-editor-image-upload="status"]' => ['checked' => TRUE], Chris@0: ], Chris@0: ]; Chris@0: Chris@0: // Any visible, writable wrapper can potentially be used for uploads, Chris@0: // including a remote file system that integrates with a CDN. Chris@0: $options = \Drupal::service('stream_wrapper_manager')->getDescriptions(StreamWrapperInterface::WRITE_VISIBLE); Chris@0: if (!empty($options)) { Chris@0: $form['scheme'] = [ Chris@0: '#type' => 'radios', Chris@0: '#title' => t('File storage'), Chris@0: '#default_value' => $image_upload['scheme'], Chris@0: '#options' => $options, Chris@0: '#states' => $show_if_image_uploads_enabled, Chris@0: '#access' => count($options) > 1, Chris@0: ]; Chris@0: } Chris@0: // Set data- attributes with human-readable names for all possible stream Chris@0: // wrappers, so that drupal.ckeditor.drupalimage.admin's summary rendering Chris@0: // can use that. Chris@0: foreach (\Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::WRITE_VISIBLE) as $scheme => $name) { Chris@0: $form['scheme'][$scheme]['#attributes']['data-label'] = t('Storage: @name', ['@name' => $name]); Chris@0: } Chris@0: Chris@0: $form['directory'] = [ Chris@0: '#type' => 'textfield', Chris@0: '#default_value' => $image_upload['directory'], Chris@0: '#title' => t('Upload directory'), Chris@0: '#description' => t("A directory relative to Drupal's files directory where uploaded images will be stored."), Chris@0: '#states' => $show_if_image_uploads_enabled, Chris@0: ]; Chris@0: Chris@18: $default_max_size = format_size(Environment::getUploadMaxSize()); Chris@0: $form['max_size'] = [ Chris@0: '#type' => 'textfield', Chris@0: '#default_value' => $image_upload['max_size'], Chris@0: '#title' => t('Maximum file size'), Chris@0: '#description' => t('If this is left empty, then the file size will be limited by the PHP maximum upload size of @size.', ['@size' => $default_max_size]), Chris@0: '#maxlength' => 20, Chris@0: '#size' => 10, Chris@0: '#placeholder' => $default_max_size, Chris@0: '#states' => $show_if_image_uploads_enabled, Chris@0: ]; Chris@0: Chris@0: $form['max_dimensions'] = [ Chris@0: '#type' => 'item', Chris@0: '#title' => t('Maximum dimensions'), Chris@0: '#field_prefix' => '
', Chris@0: '#field_suffix' => '
', Chris@0: '#description' => t('Images larger than these dimensions will be scaled down.'), Chris@0: '#states' => $show_if_image_uploads_enabled, Chris@0: ]; Chris@0: $form['max_dimensions']['width'] = [ Chris@0: '#title' => t('Width'), Chris@0: '#title_display' => 'invisible', Chris@0: '#type' => 'number', Chris@0: '#default_value' => (empty($image_upload['max_dimensions']['width'])) ? '' : $image_upload['max_dimensions']['width'], Chris@0: '#size' => 8, Chris@0: '#maxlength' => 8, Chris@0: '#min' => 1, Chris@0: '#max' => 99999, Chris@0: '#placeholder' => t('width'), Chris@0: '#field_suffix' => ' x ', Chris@0: '#states' => $show_if_image_uploads_enabled, Chris@0: ]; Chris@0: $form['max_dimensions']['height'] = [ Chris@0: '#title' => t('Height'), Chris@0: '#title_display' => 'invisible', Chris@0: '#type' => 'number', Chris@0: '#default_value' => (empty($image_upload['max_dimensions']['height'])) ? '' : $image_upload['max_dimensions']['height'], Chris@0: '#size' => 8, Chris@0: '#maxlength' => 8, Chris@0: '#min' => 1, Chris@0: '#max' => 99999, Chris@0: '#placeholder' => t('height'), Chris@0: '#field_suffix' => t('pixels'), Chris@0: '#states' => $show_if_image_uploads_enabled, Chris@0: ]; Chris@0: Chris@0: return $form; Chris@0: }