craft-linkfield
craft-linkfield copied to clipboard
Announcement: Version 2
Hi everyone! Over the last weeks we've been working on a bigger update for the link field. The new update comes with several requested features but the biggest change will be the fact that we will be storing links to a dedicated table instead of a chunk of json like before. This unlocks a whole lot of new possibilities for querying and updating links with simple db commands.
As this requires us to update all your stored links we would like to make sure the update process is as smooth as possible for everyone. Therefore we kindly invite everyone eager enough to try out the v2 beta version to provide feedback.
Updating
In order to use the beta version of the link field in your project, first make sure you have a backup of your database, then make the following changes to your composer.json before running composer update:
"minimum-stability": "beta",
"require": {
"sebastianlenz/linkfield": "^2.0-beta",
},
New stuff
Eager loading of linked elements
Starting with v2 you can now eager load linked elements. This can save a lot of time e.g. when displaying content that must access the linked elements. You may activate the eager loading by specifying the name of the link field in the with argument of element queries:
{% set pages = craft.entries.section('footer').with('linkField').all() %}
Caching linked element urls and titles
If you don't need to access the linked elements the field might still need to load the element as we need to know the url or title of the linked element. With v2 this lookup can be avoided by caching the linked elements url and title. Open the settings of your link field and tick the checkbox Enable element url and title cache on the common settings page.
The link field stores urls and titles of linked elements within the link record. The plugin watches for element changes and updates these values accordingly. You'll find a new cache option in Tools > Clear caches named Link field element cache allowing you to rebuild all cached element links. This might be handy when moving your site between hosts or when the base url / slug format of your entries change.
New link type and link models
In previous versions links where able to simply store one value, which turned out to be very limiting. The new version therefore adds distinctive link models for the different link types allowing us to store more data with each link type. This makes authoring link types much more flexible and allows us to integrate more features in the future.
Out of the box v2 comes with the ability to link to elements across different sites within your Craft installation, just ticke the new option Allow links to reference a different site on element link types on the field settings. When selecting elements users now can change the target site in the element popup.
New namespace
The plugin namespace has moved to lenz\linkfield. This is just some houskeeping in preparation of the release of another plugin.
Feedback
We would like you to try out these new features and especially provide feedback for the upgrade experience, both positive and negative. Please leave a comment or emote right here to let us know how things played out for you.
Just tried a fresh install of this on a testing environment and ran into this error when trying to save a new Link Field:
Error: Call to a member function getLinkTypes() on null in /app/vendor/sebastianlenz/linkfield/src/fields/LinkField.php:158
Stack trace:
#0 /app/vendor/sebastianlenz/linkfield/src/fields/LinkField.php(332): lenz\linkfield\fields\LinkField->getAvailableLinkTypes()
#1 /app/vendor/yiisoft/yii2/base/Component.php(180): lenz\linkfield\fields\LinkField->setTypeSettings(Array)
#2 /app/vendor/yiisoft/yii2/BaseYii.php(546): yii\base\Component->__set('typeSettings', Array)
#3 /app/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure(Object(lenz\linkfield\fields\LinkField), Array)
#4 /app/vendor/craftcms/cms/src/helpers/Component.php(112): yii\base\BaseObject->__construct(Array)
#5 /app/vendor/craftcms/cms/src/services/Fields.php(548): craft\helpers\Component::createComponent(Array, 'craft\\base\\Fiel...')
#6 /app/vendor/craftcms/cms/src/services/Fields.php(573): craft\services\Fields->createField(Array)
#7 /app/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1606): craft\services\Fields->getAllFields()
#8 /app/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1133): craft\elements\db\ElementQuery->customFields()
#9 /app/vendor/yiisoft/yii2/db/QueryBuilder.php(227): craft\elements\db\ElementQuery->prepare(Object(craft\db\mysql\QueryBuilder))
#10 /app/vendor/yiisoft/yii2/db/Query.php(146): yii\db\QueryBuilder->build(Object(craft\elements\db\UserQuery))
#11 /app/vendor/yiisoft/yii2/db/Query.php(274): yii\db\Query->createCommand(Object(craft\db\Connection))
#12 /app/vendor/craftcms/cms/src/db/Query.php(177): yii\db\Query->one(NULL)
#13 /app/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1277): craft\db\Query->one(NULL)
#14 /app/vendor/craftcms/cms/src/elements/User.php(374): craft\elements\db\ElementQuery->one()
#15 /app/vendor/yiisoft/yii2/web/User.php(690): craft\elements\User::findIdentity('1')
#16 /app/vendor/craftcms/cms/src/web/User.php(491): yii\web\User->renewAuthStatus()
#17 /app/vendor/yiisoft/yii2/web/User.php(192): craft\web\User->renewAuthStatus()
#18 /app/vendor/craftcms/cms/src/web/User.php(231): yii\web\User->getIdentity()
#19 /app/vendor/mmikkel/cp-field-inspect/src/CpFieldInspect.php(76): craft\web\User->getIsAdmin()
#20 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): mmikkel\cpfieldinspect\CpFieldInspect->init()
#21 /app/vendor/yiisoft/yii2/base/Module.php(158): yii\base\BaseObject->__construct(Array)
#22 /app/vendor/craftcms/cms/src/base/Plugin.php(127): yii\base\Module->__construct('cp-field-inspec...', Object(craft\web\Application), Array)
#23 [internal function]: craft\base\Plugin->__construct('cp-field-inspec...', Object(craft\web\Application), Array)
#24 /app/vendor/yiisoft/yii2/di/Container.php(384): ReflectionClass->newInstanceArgs(Array)
#25 /app/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('mmikkel\\cpfield...', Array, Array)
#26 /app/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->get('mmikkel\\cpfield...', Array, Array)
#27 /app/vendor/craftcms/cms/src/services/Plugins.php(897): yii\BaseYii::createObject(Array, Array)
#28 /app/vendor/craftcms/cms/src/services/Plugins.php(230): craft\services\Plugins->createPlugin('cp-field-inspec...', Array)
#29 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(1225): craft\services\Plugins->loadPlugins()
#30 /app/vendor/craftcms/cms/src/web/Application.php(112): craft\web\Application->_postInit()
#31 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\web\Application->init()
#32 /app/vendor/yiisoft/yii2/base/Application.php(206): yii\base\BaseObject->__construct(Array)
#33 /app/vendor/craftcms/cms/src/web/Application.php(100): yii\base\Application->__construct(Array)
#34 [internal function]: craft\web\Application->__construct(Array)
#35 /app/vendor/yiisoft/yii2/di/Container.php(384): ReflectionClass->newInstanceArgs(Array)
#36 /app/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('craft\\web\\Appli...', Array, Array)
#37 /app/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->get('craft\\web\\Appli...', Array, Array)
#38 /app/vendor/craftcms/cms/bootstrap/bootstrap.php(255): yii\BaseYii::createObject(Array)
#39 /app/vendor/craftcms/cms/bootstrap/web.php(42): require('/app/vendor/cra...')
#40 /app/web/index.php(20): require('/app/vendor/cra...')
#41 {main}
It looks like this entirely breaks the CP.
Note This is on Craft 3.2 alpha 4
Thank you for the report! This error is caused by another plugin accessing the user element upon plugin loading and before the link field plugin has been loaded. You have attached a link field to the user and therefore you get that error. As Craft has no way of specifying the load order of plugins we cannot do anything about this, the problem must be fixed in the plugin cp-field-inspect. To make sure we don't run into the same problem, I've updated our plugin init code to respect that, we'll issue a warning know.
@sebastian-lenz this is great! Will kick the tires this week. We rely on linkfield in nearly every build. I think the biggest issue we have with it (haven't testing 2.x yet) is the UI could be better. Will post feedback here!
@timkelty What would you like to improve on the UI part?
@sebastian-lenz made separate issues: https://github.com/sebastian-lenz/craft-linkfield/issues/64 https://github.com/sebastian-lenz/craft-linkfield/issues/63
Looking forward to this! It'd be incredible if you were able to introduce functionality as described here: https://github.com/sebastian-lenz/craft-linkfield/issues/47
It's an ongoing struggle trying to keep link field settings in check as new sections get created throughout the life of a project.
What about providing the ability to link to a Single by selection?
@sebastian-lenz Hey, just wondering if this is back on your radar now that 3.2 is out?
I think we should wait for Craft 3.3 and ditch support for the GraphQL plugin before releasing v2.
Hows the movement on this?
@OwenMelbz Version 2 is available on the Dev-Branch. I use this version in all of my projects, we have not released it due to issues when upgrading the plugin. If you start a new project I'd recommend version 2.
Is there a possibility that the following issue will be addressed? https://github.com/sebastian-lenz/craft-linkfield/issues/60
@LeoWie93 No, please see my answer in the linked issue.
Will upgrading from version 1 be possible?
Any update on version 2? Is it safe to use in production, or still in beta? We are working on a project where we need GraphQL support, so we want to update from v1 to v2.
@thijskaspers Version 2 is safe to use and recommended. What actually is in beta right now is the upgrade / database migration.
@sebastian-lenz any updates here when v2 is official?
@davidhellmann I've just made the v2 branch the master branch of this repository. We are moving 😉
If i want to move across from v1 to v2, should I uninstall v1 before installing v2?
Hi @alexr8! No, you should be able to upgrade the field by raising the version number in your composer.json. If you remove the field first, you'll loose the data associated with it.
Please create a backup of your site before upgrading the field. If you run into problems with the upgrade, please report them here.
Hi @sebastian-lenz thats great! should i just bump to "sebastianlenz/linkfield": "^2.0" or should i specify a version specifically like "sebastianlenz/linkfield": "2.0.0-beta.12"?
Hm, ^2.0 won't work as I did not release a version not tagged as beta, to ensure you receive future updates I would go with ^2.0.0-beta.12.
I've just released a new version and I've bean eager enough to name it a release candidate.
Is there an ETA on the v2 release?
😄 It took me two years to reach the RC state, so...
Still very keen on exposing this to GraphQL unless you know of any alternatives that support GQL? Love this plugin and now I'm lost without it on this new NextJS project.
Would love to know if this is nearing production-status - going through a perf audit now and this would help a lot.