foldershare-8.x-1.2/src/Entity/FolderShareTraits/GetSetSystemDisabledTrait.php
src/Entity/FolderShareTraits/GetSetSystemDisabledTrait.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | <?php namespace Drupal\foldershare\Entity\FolderShareTraits; use Drupal\Core\Database\Database; use Drupal\foldershare\Utilities\FormatUtilities; /** * Get/set FolderShare entity system disabled field. * * This trait includes get and set methods for FolderShare entity * system disabled field. * * <B>Internal trait</B> * This trait is internal to the FolderShare module and used to define * features of the FolderShare entity class. It is a mechanism to group * functionality to improve code management. * * @ingroup foldershare */ trait GetSetSystemDisabledTrait { /*--------------------------------------------------------------------- * * SystemDisabled field. * *---------------------------------------------------------------------*/ /** * {@inheritdoc} */ public function isSystemDisabled() { $value = $this ->get( 'systemdisabled' )->value; // An empty field is also FALSE. if ( empty ( $value ) === TRUE || $value === FALSE) { return FALSE; } return TRUE; } /** * Sets the system disabled flag. * * <B>This method is internal and strictly for use by the FolderShare * module itself.</B> * * The caller must call save() for the change to take effect. * * <B>Process locks</B> * This method does not lock access. The caller should lock around changes * to the entity. * * @param bool $state * The new flag state. * * @see ::isSystemDisabled() */ public function setSystemDisabled(bool $state ) { $this ->systemdisabled->setValue( $state ); } /** * Clears the system disabled flag on all hidden items. * * <B>This method is internal and strictly for use by the FolderShare * module itself.</B> * * This method is intended for use in system debugging and file system * fixes in order to quickly reset all disabled items. Since disabled * items are usually in the process of being changed (copied, moved, * ownership changed, etc.), reset all disabled items can cause confusion. * * The caller should clear the entity cache and the render cache to insure * that changed items are visible to the user. * * @return int * Returns the number of items changed. * * @see ::setSystemDisabled() */ public static function clearAllSystemDisabled() { $connection = Database::getConnection(); // Clear the disabled flag on all disabled items. $query = $connection ->update(self::BASE_TABLE); $query ->condition( 'systemdisabled' , TRUE, '=' ); $query ->fields([ 'systemdisabled' => (int) FALSE, ]); return $query ->execute(); } /*--------------------------------------------------------------------- * * Standard error messages. * *---------------------------------------------------------------------*/ /** * Returns a standard disabled message. * * This method provides a generic message that may be used by * operations that need to report that an item is disabled. * * @param mixed $operationName * The past tense name of the operation being performed, such as * 'deleted', 'moved', or 'copied'. The value may be a string or * translated markup (perferred). * @param string $itemName * (optional, default = NULL = multiple items) The name of a single item * involved in an operation that cannot be done. If NULL, a multi-item * message is returned instead. * * @return \Drupal\Core\Render\Markup * Returns a markup object containing a formatted standard * exception message. */ public static function getStandardDisabledMessage( $operationName , string $itemName = NULL) { if ( empty ( $operationName ) === TRUE) { $operationName = t( 'updated' ); } if ( empty ( $itemName ) === TRUE) { return FormatUtilities::createFormattedMessage( t( 'This item is in use by another user or by the system and cannot be @operation at this time.' , [ '@operation' => $operationName , ]), t( 'Please try again in a moment.' )); } return FormatUtilities::createFormattedMessage( t( 'The item "@name" is in use by another user or by the system and cannot be @operation at this time.' , [ '@name' => $itemName , '@operation' => $operationName , ]), t( 'Please try again in a moment.' )); } } |