Skip to content

Instantly share code, notes, and snippets.

@elliott-w
elliott-w / payload.config.ts
Created May 6, 2025 09:45
Payload CMS assume relationships are resolved json schema
import { resolveRelationships } from './resolveRelationships'
export default buildConfig({
typescript: {
schema: [resolveRelationships],
},
})
@elliott-w
elliott-w / imageAspectRatios.ts
Last active April 24, 2025 21:47
Payload CMS Image Aspect Ratios Pugin
import type {
CollectionBeforeOperationHook,
FileData,
Plugin,
UploadCollectionSlug,
} from 'payload'
type AspectRatios = Record<string, number>
type Collections = Partial<Record<UploadCollectionSlug, AspectRatios>>
@elliott-w
elliott-w / collapse-acf-repeaters.php
Created September 12, 2024 03:43
Collapse acf repeater rows by default
<?php
// Add the "Collapse by default" checkbox to the repeater field settings
add_action('acf/render_field_settings', 'add_collapse_setting_to_repeater_field', 10, 1);
function add_collapse_setting_to_repeater_field($field) {
if ($field['type'] == 'repeater') {
acf_render_field_setting($field, array(
'label' => __('Collapse by default', 'text-domain'),
'instructions' => __('Collapse all rows by default when editing.', 'text-domain'),
'type' => 'true_false',
@elliott-w
elliott-w / CustomAdminView.tsx
Last active August 9, 2024 12:11
Payload v3 Custom Form in Admin
import { FC } from 'react'
import { Form, FormSubmit, Gutter, RenderFields } from '@payloadcms/ui'
import { mapFields } from '@payloadcms/ui/utilities/buildComponentMap'
import { AdminViewProps, Field, WithServerSidePropsComponentProps } from 'payload'
import { WithServerSideProps as WithServerSidePropsGeneric } from '@payloadcms/ui/shared'
import { DefaultTemplate } from '@payloadcms/next/templates'
import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'
type WithServerSidePropsPrePopulated = React.FC<
Omit<WithServerSidePropsComponentProps, 'serverOnlyProps'>
@elliott-w
elliott-w / CustomAdminView.tsx
Last active August 2, 2024 10:18
Payload CMS Custom Admin View Form
import { FC, Fragment } from 'react'
import {
Form,
FormSubmit,
Gutter,
HydrateClientUser,
RenderFields,
SetStepNav,
SetViewActions,
} from '@payloadcms/ui'
@elliott-w
elliott-w / html-snippets.json
Created July 8, 2024 00:45
HTML Snippets in PHP
{
// Place your snippets for html here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@elliott-w
elliott-w / migrate.js
Created June 4, 2024 02:09
Bulk Import/Migrate Github Repos
const { spawn } = require('child_process')
const fs = require('fs')
const path = require('path')
const os = require('os')
// Replace with your GitHub usernames and personal access tokens
const sourceOrg = 'sourceOrg'
const sourceUser = 'sourceUser'
const sourceToken = 'sourceUserToken'
const targetOrg = 'targetOrg'