Skip to content

AcfConfig ​

Configuration class for ACF (Advanced Custom Fields) integration.

Signature ​

php
<?php

namespace Studiometa\Foehn\Config;

final readonly class AcfConfig
{
    /**
     * @param bool $transformFields Transform ACF block fields via Timber's ACF integration.
     */
    public function __construct(
        public bool $transformFields = true,
    );
}

Properties ​

PropertyTypeDefaultDescription
transformFieldsbooltrueAuto-convert ACF values to Timber objects

Usage ​

Create a config file in your app directory:

php
<?php
// app/acf.config.php

use Studiometa\Foehn\Config\AcfConfig;

return new AcfConfig(
    transformFields: true,
);

Field Transformation ​

When transformFields is enabled (default), Timber's ACF transforms replace ACF's formatting for some field types while Føhn reads a block's fields. The stored value becomes a Timber object:

ACF Field TypeStored ValueTimber Object
ImageAttachment IDTimber\Image
Post ObjectPost IDTimber\Post
RelationshipArray of IDsTimber\PostArrayObject of posts
TaxonomyTerm IDTimber\Term
Date PickerYmd stringDateTimeImmutable

See the ACF blocks guide for every type.

Disabling Transformation ​

For performance, or when you want ACF's own formatting:

php
return new AcfConfig(
    transformFields: false,
);

With transformation disabled, block fields have ACF's formatting, as get_fields() returns them: an image is what its return_format gives (an array, a URL or an ID), and you must resolve Timber objects manually.

Released under the MIT License.