Get image fields.

@param string $field			Field
@param int	 $attachment_id	The image id.
@param bool   $sub_field		Sub field (only if it's a repeater)
@return array
777106
public static function get_image_fields( $field, $attachment_id, $sub_field = false ) {
		$size = apply_filters( Filter::IMAGE, false, $field, $sub_field );

		if ( ! $size ) {
			return $attachment_id;
		}

		$src = wp_get_attachment_image_src( $attachment_id, $size );

		if ( ! $src ) {
			return $attachment_id;
		}

		return [
			'src' 		=> $src[0],
			'width'		=> $src[1],
			'height'	=> $src[2],
			'alt'		=> get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
		];
	}
814440
public function addField($field)
    {
        if (! is_array($field) && ! $field instanceof AttachmentField) {
            throw FieldCannotBeAdded::invalidType();
        }

        if (is_array($field)) {
            $title = array_keys($field)[0];
            $value = $field[$title];

            $field = AttachmentField::create($title, $value);
        }

        $this->fields->push($field);

        return $this;
    }
119018
public function getCMSFields()
    {
        // Obtain Field Objects (from parent):
        
        $fields = parent::getCMSFields();
        
        // Create Main Fields:
        
        $fields->addFieldsToTab(
            'Root.Main',
            [
                $image = UploadField::create(
                    'Image',
                    $this->fieldLabel('Image')
                ),
                HTMLEditorField::create(
                    'Caption',
                    $this->fieldLabel('Caption')
                )->setRows(10),
                TextField::create(
                    'ImageTitle',
                    $this->fieldLabel('ImageTitle')
                ),
                TextField::create(
                    'ImageAlt',
                    $this->fieldLabel('ImageAlt')
                )
            ]
        );
        
        // Define Image Field:
        
        $image->setAllowedExtensions(['gif', 'jpg', 'jpeg', 'png', 'svg']);
        $image->setFolderName($this->getAssetFolder());
        
        // Create Options Fields:
        
        $fields->addFieldToTab(
            'Root.Options',
            FieldSection::create(
                'ImageOptions',
                $this->fieldLabel('ImageOptions'),
                [
                    CheckboxField::create(
                        'LinkImage',
                        $this->fieldLabel('LinkImage')
                    ),
                    CheckboxField::create(
                        'HideCaption',
                        $this->fieldLabel('HideCaption')
                    ),
                    CheckboxField::create(
                        'InlineVector',
                        $this->fieldLabel('InlineVector')
                    )
                ]
            )
        );
        
        // Answer Field Objects:
        
        return $fields;
    }
102138
function create_new_field_keys( &$field )
	{
		// update key
		$field['key'] = 'field_' . uniqid();
		
		
		if( isset($field['sub_fields']) && is_array($field['sub_fields']) )
		{
			foreach( $field['sub_fields'] as $f )
			{
				$this->create_new_field_keys( $f );
			}
		}
		elseif( isset($field['layouts']) && is_array($field['layouts']) )
		{
			foreach( $field['layouts'] as $layout )
			{
				if( isset($layout['sub_fields']) && is_array($layout['sub_fields']) )
				{
					foreach( $layout['sub_fields'] as $f )
					{
						$this->create_new_field_keys( $f );
					}
				}
				
			}
		}
	}
1175887
private function fetchFields($subClass)
    {
        $fields = [];
        foreach ($this->fields as $name => $field) {
            if ($field instanceof $subClass) {
                $fields[$name] = $field;
            }
        }

        return $fields;
    }
819619
public function getDefinedUploadFields()
    {
        $fields = isset(static::$imageFields)
            ? static::$imageFields
            : $this->imagesFields;

        return array_merge($this->getDefinedFileFields(), $fields);
    }
1145153
function attachment_fields_to_edit( $form_fields, $post ) 
	{
		// vars
		$screen = get_current_screen();
		$post_id = $post->ID;
		

		if( $screen && $screen->base == 'post' ) {
			
			return $form_fields;
			
		}
		
		
		// get field groups
		$filter = array( 'post_type' => 'attachment' );
		$metabox_ids = array();
		$metabox_ids = apply_filters( 'acf/location/match_field_groups', $metabox_ids, $filter );
		
		
		// validate
		if( empty($metabox_ids) )
		{
			return $form_fields;	
		}
		
		
		$acfs = apply_filters('acf/get_field_groups', array());
	
	
		if( is_array($acfs) ){ foreach( $acfs as $acf ){
			
			// only add the chosen field groups
			if( !in_array( $acf['id'], $metabox_ids ) )
			{
				continue;
			}
			
			
			// load fields
			$fields = apply_filters('acf/field_group/get_fields', array(), $acf['id']);
			
			
			if( is_array($fields) ){ foreach( $fields as $i => $field ){
				
				// if they didn't select a type, skip this field
				if( !$field || !$field['type'] || $field['type'] == 'null' )
				{
					continue;
				}
					
			
				// set value
				if( !isset($field['value']) )
				{
					$field['value'] = apply_filters('acf/load_value', false, $post_id, $field);
					$field['value'] = apply_filters('acf/format_value', $field['value'], $post_id, $field);
				}
				
				
				// create field
				$field['name'] = 'fields[' . $field['key'] . ']';
				
				ob_start();
					
					do_action('acf/create_field', $field);
					
					$html = ob_get_contents();
				
				ob_end_clean();
 
				
				$form_fields[ $field['name'] ] = array(
		       		'label' => $field['label'],
		   			'input' => 'html',
		   			'html' => $html
				);
				
			}};
 
			
		}}
		
		
		// return
		return $form_fields;
	}
857071
public function parse(array $item, bool $subField = false): array
    {
        $groupId = false;
        if ($subField === false) {
            // Attempt to find and set group id.
            if (isset($item['group'])) {
                $groupId = $this->getGroupIdByName($item['group']);
                if ($groupId) {
                    unset($item['group']);
                }
            } else {
                $errors = [
                    'type' => [
                        Architect::t('Field group is missing.')
                    ]
                ];
                return [null, $errors];
            }
        }

        // Attempt to find matching field type.
        $matchingFieldTypes = $this->getMatchingFieldTypes($item['type']);
        if (\count($matchingFieldTypes) === 1) {
            $item = array_merge($item, [
                'type' => array_pop($matchingFieldTypes)
            ]);
        } else if (\count($matchingFieldTypes) <= 0) {
            $errors = [
                'type' => [
                    Architect::t('No field type matching "{fieldType}".', ['fieldType' => $item['type']])
                ]
            ];
            return [null, $errors];
        } else {
            $errors = [
                'type' => [
                    Architect::t('Too many field types matching "{fieldType}"', ['fieldType' => $item['type']]) . '<br>' . Architect::t('Possible values:') . '<br>' . implode('<br>', $matchingFieldTypes)
                ]
            ];
            return [null, $errors];
        }
        if ($subField === false) {
            $this->convertOld($item);
        }
        try {
            $this->mapSources($item);
        } catch (\Exception $e) {
            $errors = [
                'source' => [
                    Architect::t('There was an error mapping the source handles to existing sources.')
                ]
            ];
            return [null, $errors];
        }
        if ($item['type'] === Matrix::class || $item['type'] === SuperTableField::class || $item['type'] === Neo::class) {
            $this->mapTypeSettings($item);
            if ($subField) {
                $blockTypes = &$item['typesettings']['blockTypes'];
            } else {
                $blockTypes = &$item['blockTypes'];
            }
        }
        if ($item['type'] === Matrix::class) {
            if (isset($blockTypes[0])) {
                $this->convertBlockTypesToNew($blockTypes);
            }
            foreach ($blockTypes as $blockKey => &$blockType) {
                foreach ($blockType['fields'] as $fieldKey => $field) {
                    list ($field, $errors) = $this->parse($field, true);
                    if ($field === null) {
                        return [$field, $errors];
                    }
                    $blockType['fields'][$fieldKey] = $field;
                }
            }
            unset($blockType);
        } else if ($item['type'] === Neo::class) {
            if (isset($blockTypes[0])) {
                $this->convertBlockTypesToNew($blockTypes);
            }
            foreach ($blockTypes as &$blockType) {
                if (!array_key_exists('childBlocks', $blockType)) {
                    $blockType['childBlocks'] = null;
                }
                foreach ($blockType['fieldLayout'] as &$fields) {
                    if (is_array($fields)) {
                        $fields = $this->handlesToIds($fields);
                    }
                }
                unset($fields);
                if (\is_array($blockType['requiredFields'])) {
                    $blockType['requiredFields'] = $this->handlesToIds($blockType['requiredFields']);
                }
                unset($requiredFields);
            }
            unset($blockType);
        } else if ($item['type'] === SuperTableField::class) {
            if (!isset(array_values($blockTypes)[0]['fields'])) {
                $newBlockTypes = [
                    [
                        'fields' => $blockTypes
                    ]
                ];
                $blockTypes = $newBlockTypes;
                $this->convertBlockTypesToNew($blockTypes);
            }
            foreach ($blockTypes as $blockKey => &$blockType) {
                foreach ($blockType['fields'] as $fieldKey => &$field) {
                    $this->mapSources($field);
                    if ($field['type'] === Matrix::class) {
                        $this->convertBlockTypesToNew($field['typesettings']['blockTypes']);
                    }
                }
                unset($field);
            }
            unset($blockType);
        }

        if ($groupId && Craft::$app->fields->getGroupById((int) $groupId)) {
            $fieldObject = array_merge($item, [
                'groupId' => $groupId
            ]);

            if ($item['type'] === Neo::class) {
                $fieldObject['settings'] = [
                    'blockTypes' => $fieldObject['blockTypes']
                ];
                unset($fieldObject['blockTypes']);
            }

            $field = Craft::$app->fields->createField($fieldObject);

            return [$field, $field->getErrors()];
        }
        if ($subField) {
            return [$item, null];
        }
        $errors = [
            'group' => [
                Architect::t('No field group matching "{groupName}".', ['groupName' => $item['group']])
            ]
        ];
        return [null, $errors];
    }
416461
private function maybe_do_featured( $field, $post ){
		if ( 'post_featured' == $field ) {

			$id = get_post_thumbnail_id( $post->ID );
			if ( 0 < absint( $id ) ) {

				return wp_get_attachment_image( $id, 'large' );
			}

			return '';

		}



	}
269222
function getSectionSubsectionsFromFieldset($, $fieldset) {
    // Create a subsections object to return.
    var subsections = {};

    // Iterate through each Table ("Subsection").
    $fieldset.children('table').each(function(i) {
      var $table            = $(this),
          subsectionName    = getSubsectionNameFromTable($, $table),
          subsectionFields  = {};

      // If we couldn't extract a name from the subsection, generate one and mark the title as hidden.
      if(!subsectionName) {
        subsectionName = 'Untitled Subsection #' + (i + 1);
        subsectionFields.notitle = true;
      }

      // Add any extracted fields to the fields hash.
      addSubsectionFieldsFromTable($, subsectionFields, $table);

      subsections[subsectionName] = subsectionFields;
    });

    return subsections;
  }
1292853
public function getData(CK\MARCspec\FieldInterface $fieldspec, CK\MARCspec\SubfieldInterface $subfieldspec = null)
    {
        if (!$this->data) {
            return [];
        }

        $fieldBase = $fieldspec->getBaseSpec();
        if (!is_null($subfieldspec)) {
            $key = $fieldBase.$subfieldspec->getBaseSpec();
            if (array_key_exists($key, $this->data)) {
                return $this->data[$key];
            }
            $key = $fieldBase.'$'.$subfieldspec->getTag();
            if (array_key_exists($key, $this->data)) {
                return array_values($this->sliceData($key, $subfieldspec));
            }

            return [];
        }

        // subfieldspec is null
        if (array_key_exists($fieldBase, $this->data)) {
            return $this->data[$fieldBase];
        }
        $key = $fieldspec->getTag();
        if (array_key_exists($key, $this->data)) {
            return array_values($this->sliceData($key, $fieldspec));
        }

        return [];
    }
1006640
public function getFieldData(Field $field)
    {
        if ($field->value->data === null) {
            return;
        }

        $doc = new DOMDocument();
        if (!$doc->loadXML($field->value->data)) {
            return;
        }

        $linkTags = $doc->getElementsByTagName('link');

        if ($linkTags->length > 0) {
            $links = [];

            foreach ($linkTags as $link) {
                $urlId = $link->getAttribute('url_id');
                if (!empty($urlId)) {
                    if (!isset($links[$urlId])) {
                        $links[$urlId] = [];
                    }
                    $links[$urlId][] = $link;
                }
            }

            if (!empty($links)) {
                $linkIdUrlMap = $this->getIdUrlMap(array_keys($links));

                foreach ($linkIdUrlMap as $urlId => $url) {
                    foreach ($links[$urlId] as $link) {
                        $link->setAttribute('url', $url);
                        $link->removeAttribute('url_id');
                    }
                }

                // Store xml changes back to field
                $field->value->data = $doc->saveXML();
            }
        }
    }
889164
public function getAttachedFile($file, $attachment_id) {
	    $shouldOverride = apply_filters('ilab_should_override_attached_file', true, $attachment_id);

		if(!file_exists($file) && $shouldOverride) {
			$meta = wp_get_attachment_metadata($attachment_id);

			$new_url = null;
			if($meta) {
				$new_url = $this->getAttachmentURLFromMeta($meta);
			}

			if(!$new_url) {
				$meta = get_post_meta($attachment_id, 'ilab_s3_info', true);
				if($meta) {
					$new_url = $this->getAttachmentURLFromMeta($meta);
				} else if(!$meta && StorageSettings::docCdn()) {
					$post = \WP_Post::get_instance($attachment_id);
					if($post && (strpos($post->guid, StorageSettings::docCdn()) === 0)) {
						$new_url = $post->guid;
					}
				}
			}

			if($new_url) {
				return $new_url;
			}
		}

		return $file;
	}
1201671
public function generate_srcset_and_sizes( $image, $attachment_id ) {
		// Ensure the image meta exists.
		$image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';

		list( $image_src ) = explode( '?', $image_src );

		// Return early if we couldn't get the image source.
		if ( ! $image_src ) {
			return $image;
		}

		// Select image size from classname starting with 'size-'.
		$img_size = preg_match( '/ size-([^\s"]+)/', $image, $match_size ) ? $match_size[1] : false;

		// Bailout if image size couldn’t be read.
		if ( ! $img_size ) {
			return $image;
		}

		// Maybe select replacement size.
		if ( ! empty( $this->args['map_sizes'] ) ) {
			if ( is_array( $this->args['map_sizes'] )
				&& in_array( $img_size, array_keys( $this->args['map_sizes'] ), true )
			) {
				$img_size = $this->args['map_sizes'][ $img_size ];
			} else {
				$img_size = $this->args['map_sizes'];
			}
		}

		// Get responsive image markup for srcset and sizes.
		$attributes = get_timber_image_attributes_responsive(
			$attachment_id,
			$img_size
		);

		// Bailout if markup couldn’t be generated.
		if ( ! $attributes ) {
			return $image;
		}

		// Remove existing src
		$image = preg_replace( '/ src="([^"]+)"/', '', $image );

		/**
		 * Remove width, height and alt attributes, because they are handled by
		 * get_timber_image_responsive_src().
		 *
		 * @see get_timber_image_responsive_src()
		 */
		$image = preg_replace( '/ height="([^"]+)"/', '', $image );
		$image = preg_replace( '/ width="([^"]+)"/', '', $image );
		$image = preg_replace( '/ alt="([^"]+)"/', '', $image );
		$image = preg_replace( '/ title="([^"]+)"/', '', $image );

		// Remove class attribute and save class attribute content in attributes array.
		if ( preg_match( '/ class="([^"]+)"/', $image, $class_matches ) ) {
			$attributes['class'] = $class_matches[1];
			$image               = preg_replace( '/ class="([^"]+)"/', '', $image );
		}

		/**
		 * Filters image attributes used for a responsive content image.
		 *
		 * @param array  $attributes    A key-value array of HTML attributes.
		 * @param int    $attachment_id The attachment ID of the image.
		 * @param string $img_size      The image size key.
		 */
		$attributes = apply_filters(
			'timmy/responsive_content_image/attributes',
			$attributes,
			$attachment_id,
			$img_size
		);

		// Replace image markup
		$image = preg_replace(
			'/<img ([^>]+?)[\/ ]*>/',
			'<img $1 ' . Helper::get_attribute_html( $attributes ) . ' />',
			$image
		);

		/**
		 * Filters the image HTML markup.
		 *
		 * This filter can be used to append content to an image.
		 *
		 * @param string $image         The image HTML markup.
		 * @param int    $attachment_id The attachment ID of the image.
		 * @param string $img_size      The image size key.
		 */
		$image = apply_filters(
			'timmy/responsive_content_image',
			$image,
			$attachment_id,
			$img_size
		);

		return $image;
	}
74002
public Deque<Subfield> getSubfield(String subfieldId) {
        return subfields.stream()
                .filter(subfield -> subfield.getId().equals(subfieldId))
                .collect(Collectors.toCollection(LinkedList::new));
    }
169004
public function getSubFields(): array
    {
        $fields = [];

        foreach ($this->config->get('sub_fields') as $field) {
            $field->setParentKey($this->getKey());

            $fields[] = $field->toArray();
        }

        return $fields;
    }
333385
private function createSubSpec($_subTerms, $Subfield = null)
    {
        $fieldContext = $this->field->getBaseSpec();
        $context = $fieldContext;
        if (!is_null($Subfield)) {
            $context = $fieldContext.$Subfield->getBaseSpec();
            $subfieldContext = $Subfield->getBaseSpec();
        }

        $handleSubTerm = function ($subTerm) use ($fieldContext, $context) {
            if ('\\' == $subTerm[0]) { // is a comparisonString
                return new ComparisonString(substr($subTerm, 1));
            } else {
                if (strpos('[/_$', $subTerm[0]) && is_null($context)) {
                    throw new InvalidMARCspecException(
                        InvalidMARCspecException::SS.
                        InvalidMARCspecException::MISSINGFIELD,
                        $subTerm
                    );
                }

                switch ($subTerm[0]) {
                    case '_':
                        if ($refPos = strpos($context, $subTerm[0])) {
                            if ('$' !== substr($context, $refPos - 1, 1)) {
                                return new MARCspec(substr($context, 0, $refPos).$subTerm);
                            }
                        }

                        return new MARCspec($fieldContext.$subTerm);

                    case '$':
                        return new MARCspec($fieldContext.$subTerm);

                    case '/':
                        $refPos = strrpos($context, $subTerm[0]);
                        if ($refPos) {
                            if ('$' !== substr($context, $refPos - 1, 1)) {
                                return new MARCspec(substr($context, 0, $refPos).$subTerm);
                            }
                        }

                        return new MARCspec($context.$subTerm);

                    case '[':
                        $refPos = strrpos($context, $subTerm[0]);
                        if ($refPos) {
                            if ('$' !== substr($context, $refPos - 1, 1)) {
                                return new MARCspec(substr($context, 0, $refPos).$subTerm);
                            } else {
                                return new MARCspec($context.$subTerm);
                            }
                        } else {
                            return new MARCspec(substr($context, 0, 3).$subTerm);
                        }

                    default:
                        return new MARCspec($subTerm);
                }
            }
        };

        $_subTermSet = [];

        if (array_key_exists('leftsubterm', $_subTerms)) {
            $_subTermSet['leftsubterm'] = $handleSubTerm($_subTerms['leftsubterm']);
        } else {
            $_subTermSet['leftsubterm'] = new self($context);
        }

        $_subTermSet['rightsubterm'] = $handleSubTerm($_subTerms['rightsubterm']);

        return new SubSpec($_subTermSet['leftsubterm'], $_subTerms['operator'], $_subTermSet['rightsubterm']);
    }