How can I add a field to an existing biblatex type?

The answer to Add field “tome” to biblatex entries was written back in the good old days when datamodel commands were still allowed in the document preamble, starting from version 2.9 those commands cannot be used in the preamble in order to avoid complications and unwanted behaviour. The answer has now been amended to reflect this change.

So if you want to use datamodel commands now you will have to use a datamodel file (either a .dbx or biblatex-dm.cfg). You could call this file werner.dbx, its content would be

\DeclareDatamodelFields[type=field,datatype=verbatim,nullok=true]{breakurl}
\DeclareDatamodelEntryfields{breakurl}

You would then have to load biblatex with the option datamodel=werner.

Please note that nullok=true does not ensure that the field appears in the .bbl even if it is empty, it just doesn't generate a warning. So breakurl = {}, does not make the field breakurl appear in the .bbl.


You seem to want to use the breakurl field as a boolean value. This can be done slightly easier with \DeclareEntryOption.

\newtoggle{blx@breakurl}
\DeclareEntryOption{breakurl}[true]{%
  \settoggle{blx@breakurl}{#1}%
  % or whatever you need to do here
}

Defines a new option breakurl that sets a toggle.

In your .bib entry you then have

options  = {breakurl},

to toggle breakurl on.

You can have a look at biblatex - citing dead author, How to remove comma from authoryear citation, Functionality of apacites \nocitemeta with biblatex-apa: adding asterisks to author lastnames (meta-analysis) and Change 'Chapter' in @inbook to 'Appendix' for one BibLaTex entry for more examples and uses of \DeclareEntryOption.

MWE

\documentclass{article}
\usepackage{filecontents}
\usepackage{biblatex}

\begin{filecontents*}{\jobname.bib}
@online{abc,
  author   = {A Author},
  title    = {Some lengthy title that's awesome},
  url      = {http://tex.stackexchange.com},
  options  = {breakurl},
}
\end{filecontents*}

\addbibresource{\jobname.bib}

\newtoggle{blx@breakurl}
\togglefalse{blx@breakurl}
\DeclareEntryOption{breakurl}[true]{%
  \settoggle{blx@breakurl}{#1}%
  % or whatever you need to do here
}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

According to the biblatex manual (texdoc biblatex)

It is not possible to add to a loaded data model by using the macros below in your preamble as the preamble is read after Biblatex has defined critical internal macros based on the data model. If any data model macro is used in a document, it will be ignored and a warning will be generated.

The command to declare data model (and thus new field) should be in configuration files.

To insert them in a document one can use filecontents environment to generate the configuration file.

\begin{filecontents}{biblatex-dm.cfg}
\DeclareDatamodelFields[type=field,datatype=verbatim,nullok=true]{breakurl}
\DeclareDatamodelEntryfields{breakurl}
\DeclareFieldFormat[online]{breakurl}{}% Used as a boolean variable
\end{filecontents}

Tags:

Biblatex