Skip to content

eric-schmidt/contentful-auto-field-value

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project was bootstrapped with Create Contentful App.

Overview

The main goal of this app is to allow content modelers the ability automatically generate the value of a field based on the values of other fields. An example use case is concatenating a first and last name field into the entry title for an author.

Deployment

This app uses https://github.com/contentful/actions-app-deploy to automatically deploy to Contentful when changes are pushed up to GitHub. Configuration for this process can be found in the .github/workflows/actions-app-deploy.yml file.

App/Content Type Configuration

  1. Install the app to your space, either via Contentful hosting or by cloning this repo and running npm install and npm start (hosted at http://localhost:3000).
  2. Enable for Short Text entry fields (the only field type currently supported).
  3. Add an instance parameter called Replacement Pattern (replacementPattern) of type Short Text, which will be used to allow content modelers to specify which fields to use as tokens for this fields value. Here is some example help text to add for this instance parameter: A tokenized pattern of field IDs on this content type that will be used for replacement. Please wrap all tokens in square brackets (e.g. [fieldId]).
  4. Create a Short Text field on a content type and edit its appearance to use the Auto Field Value widget.
  5. Update the Replacement Pattern field the above field's appearance configuration dialog to contain references to other Short Text field IDs tokenized with square brackets (e.g. [fieldId]). Note that at this time you can only reference other Short Text fields here.

Available Scripts

In the project directory, you can run:

npm start

Creates or updates your app definition in Contentful, and runs the app in development mode. Open your app to view it in the browser.

The page will reload if you make edits. You will also see any lint errors in the console.

npm run build

Builds the app for production to the build folder. It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes. Your app is ready to be deployed!

npm run upload

Uploads the build folder to contentful and creates a bundle that is automatically activated. The command guides you through the deployment process and asks for all required arguments. Read here for more information about the deployment process.

npm run upload-ci

Similar to npm run upload it will upload your app to contentful and activate it. The only difference is
that with this command all required arguments are read from the environment variables, for example when you add the upload command to your CI pipeline.

For this command to work, the following environment variables must be set:

  • CONTENTFUL_ORG_ID - The ID of your organization
  • CONTENTFUL_APP_DEF_ID - The ID of the app to which to add the bundle
  • CONTENTFUL_ACCESS_TOKEN - A personal access token

Libraries to use

To make your app look and feel like Contentful use the following libraries:

Using the contentful-management SDK

In the default create contentful app output, a contentful management client is passed into each location. This can be used to interact with Contentful's management API. For example

// Use the client
cma.locale.getMany({}).then((locales) => console.log(locales));

Visit the contentful-management documentation to find out more.

Learn More

Read more and check out the video on how to use the CLI.

Create Contentful App uses Create React App. You can learn more in the Create React App documentation and how to further customize your app.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published