MethodBackgroundControls

 
 
 
 

Overview

Image and video background management with media upload, resolution selection, position alignment, display sizing, repeat options, and parallax toggle.

  • File: lib/blocks/components/MethodBackgroundControls.js
  • Panel context: Typically rendered inside a “Background Media” PanelBody

Props

PropTypeDefaultDescription
breakpointstring(required)The responsive breakpoint: base, mobile, tablet, or wide
attributesobject(required)The block’s full attributes object
setAttributesfunction(required)WordPress setAttributes function
isImgbooleanfalseWhen true, switches to image‑fitting mode (cover/contain only, no position/repeat/parallax)
includeVideobooleanfalseWhen true, shows the background video URL field
includeFeaturedImagebooleanfalseWhen true, offers the Use Featured Image checkbox (base breakpoint) and the per-breakpoint Preferred Image Size select; see Featured Image as Background
limitedbooleanfalseWhen true, image selection and resolution only — no display size, alignment, offset, repeat, parallax or video options (Fluid Video’s poster)

Controls

Image Selection (base breakpoint only)

  • UI: MediaUpload with Select/Change/Reset buttons and image thumbnail preview.
  • Attribute: bgImg (top‑level object, not inside responsiveSettings)

When an image is selected, the component builds a bgImg object containing all available WordPress image sizes with their URLs and dimensions:

JSON
{
  id: 123,
  full: { url: '...', width: 1920, height: 1080 },
  large: { url: '...', width: 1024, height: 576 },
  medium: { url: '...', width: 300, height: 169 },
  // ...additional registered sizes
}

Size variants that are the same dimensions or URL as full are excluded. After selection, bgImgSize is auto‑set to large if available, otherwise full.


Featured Image as Background

  • UI: CheckboxControl “Use Featured Image” at the base breakpoint (only with includeFeaturedImage), then a CustomSelectControl “Preferred Image Size” in every enabled breakpoint. While the checkbox is on, the Select / Change Image buttons are hidden.
  • Attributes: useFeaturedImage (top-level boolean) and responsiveSettings.{breakpoint}.featuredImageSize — the size can differ per tier.
  • Options: Every registered image size, labelled with “(Uncropped)” when the size is not cropped, from methodGlobalData‘s image size and dimension lists.

Checking the box clears bgImg and seeds featuredImageSize with large in the current tier. hasImage — which gates the alignment, size and repeat controls — counts a featured image as an image, so the rest of the panel works as it does for a selected image.

Resolution happens on both sides: in the editor, MethodStyleTag takes postId / postType props and reads the post’s featured media through useFeaturedImageSizes() (lib/blocks/components/MethodUseFeaturedImage.js, a { size: url } map built from core.getMedia()), picking each tier’s featuredImageSize and falling back to full; on the page, method_get_block_responsive_styles() threads $post_id down to method_get_block_css_declarations(), which calls get_the_post_thumbnail_url( $post_id, $size ) per tier. In a query loop or archive template the result is one background per post.

The same file exports useFeaturedImage( postId, postType, size ), a single URL, and lib/blocks/components/MethodFeaturedImage.js wraps it as a <FeaturedImage> component (an <img>, or the URL with format="url"); the Section block’s editor preview uses it for the parallax layer when the featured image is the background.


Image Resolution

  • UI: CustomSelectControl showing available size names with dimensions as hints (e.g., “Large — 1024×576”).
  • Settings key: responsiveSettings.{breakpoint}.bgImgSize
  • Visibility: Shown when bgImg has been selected and the current breakpoint is enabled.

Available sizes are dynamically computed from the bgImg attribute cross‑referenced with the editor’s registered imageSizes.


Image Alignment

  • UI: AlignmentMatrixControl (3×3 grid) + text label showing the current value.
  • Settings key: responsiveSettings.{breakpoint}.bgImgAlign
  • Default: "center center"
  • Visibility: Base breakpoint only; hidden when parallax or video is active; hidden in isImg mode.

Position Offset

  • UI: Two UnitControl fields for X and Y offset.
  • Settings keys: responsiveSettings.{breakpoint}.bgOffsetX, responsiveSettings.{breakpoint}.bgOffsetY
  • Visibility: Same conditions as Image Alignment.

Display Size

  • UI: SelectControl dropdown.
  • Settings key: responsiveSettings.{breakpoint}.bgDisplaySize

In standard background mode (isImg=false):

OptionValue
Cover"" (empty — the default; .method-section-bgimg / .method-container-bgimg are background-size: cover in the stylesheet)
Containcontain
Image Sizesize (natural dimensions; emitted as background-size: unset)
Customcustom

In image‑fitting mode (isImg=true):

OptionValue
Cover"" (empty)
Contain"-contain"

When “Custom” is selected, additional Width and Height UnitControl fields appear.


Repeat

  • UI: SelectControl dropdown.
  • Settings key: responsiveSettings.{breakpoint}.bgRepeat
  • Visibility: Hidden in isImg mode and when parallax/video is active.
OptionValue
No Repeat"" (empty)
Repeatrepeat
Repeat Xrepeat-x
Repeat Yrepeat-y
Spacespace

Parallax Toggle

  • UI: CheckboxControl.
  • Attribute: useParallax (top‑level attribute, not in responsiveSettings)
  • Visibility: Hidden in isImg mode.

The checkbox label includes a help note: “If enabled, Jarallax will be used to add parallax scrolling. Automatically enabled for background video.” When bgVideo has a value, the checkbox is forced to checked.


Background Video URL

  • UI: TextControl.
  • Attribute: bgVideo (top‑level attribute)
  • Visibility: Only when includeVideo=true, not in isImg mode, and breakpoint is enabled.

Accepts URLs from YouTube, Vimeo, or direct video sources. Processed by Jarallax’s video extension.


Responsive Override

For non‑base breakpoints, a “Custom Background” checkbox (responsiveSettings.{breakpoint}.customBg) gates all controls. When unchecked, the breakpoint inherits from base.


Usage by Blocks

BlockisImgincludeVideoincludeFeaturedImagelimitedBreakpoints
Sectionfalsetrue (base)true (base)falsebase, mobile, tablet, wide
Containerfalsetrue (base)falsefalsebase, mobile, tablet, wide
Fitted Imagetruefalsefalse (its own Use Featured Image checkbox)falsebase only
Fluid Videotruefalsefalsetruebase only (the poster)
Swiper Gallery————(uses its own MediaUpload)

Changelog

VersionDescription
2.0.0-alpha4Introduced.
2.0.0-beta6Featured image as background: the opt-in includeFeaturedImage prop, a per-breakpoint featuredImageSize (previously the top-level useFeaturedImageSize), and the useFeaturedImageSizes() hook for the editor (09cc16b).
2.0.0-beta14limited prop for the Fluid Video poster (ba36676).
2.0.0-beta21Background Size options reworked: Cover is the default (and the stylesheet default), with a new Image Size option (size) for natural dimensions (75910d2).